Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptazhou committed Oct 26, 2024
1 parent 74f9c40 commit 395dd57
Show file tree
Hide file tree
Showing 22 changed files with 418 additions and 20 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ jobs:
- uses: codecov/[email protected]
with:
file: lcov.info
docs:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
statuses: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: julia-actions/setup-julia@v2
with:
show-versioninfo: true
version: "1"
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/docs/build/
lcov.info
Manifest.toml
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "Exts"
uuid = "0b12d779-4123-4875-9d6c-e33c2e29e2c9"
authors = ["Heptazhou <zhou at 0h7z dot com>"]
version = "0.1.7"
version = "0.1.8"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[weakdeps]
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Exts.jl
[![CI status](https://github.com/0h7z/Exts.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/0h7z/Exts.jl/actions/workflows/CI.yml)
[![codecov.io](https://codecov.io/gh/0h7z/Exts.jl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/0h7z/Exts.jl)

*****
## Usage
```julia
pkg> registry add https://github.com/0h7z/0hjl.git
pkg> add Exts

julia> using Exts
```

12 changes: 12 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656"
FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
69 changes: 69 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (C) 2022-2024 Heptazhou <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

using Documenter: Documenter, DocMeta
using DocumenterInterLinks: InterLinks
using Exts
using OrderedCollections: OrderedDict

DocMeta.setdocmeta!(Exts, :DocTestSetup, quote
#! format: noindent
using Exts
end)

using DataFrames
using FITSIO
using StatsBase

const entry = OrderedDict{String, String}()
const extra = Vector{Module}()
const links = InterLinks(
"Julia" => "https://docs.julialang.org/en/v1/",
)

cd(@__DIR__) do
#! format: noindent
for (k, v) Exts.ext(:)
md = readstr("src/api.md")
md = replace(md, "[Exts]" => "[$k]")
md = replace(md, r"^#+\K\s+"m => " ")
entry["$k"] = "$k.md"
write("src/" * entry["$k"], md)
push!(extra, v)
@eval $(Symbol(k)) = $v
end
end

@info s"Documenter.doctest"
@noinfo Documenter.doctest(Exts, fix = true, manual = false)

@info s"Documenter.makedocs"
@noinfo Documenter.makedocs(
format = Documenter.HTML(),
modules = [Exts, extra...],
pages = ["Manual" => "index.md", entry...],
pagesonly = true,
plugins = [links],
sitename = "Exts.jl",
)

@info s"Documenter.deploydocs"
@noinfo Documenter.deploydocs(
branch = "gh-pages",
devbranch = "master",
devurl = "latest",
forcepush = true,
repo = "github.com/0h7z/Exts.jl.git",
)

18 changes: 18 additions & 0 deletions docs/src/BaseExt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## API reference
```@autodocs
Modules = [BaseExt]
Order = [:module]
```

## Types
```@autodocs
Modules = [BaseExt]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [BaseExt]
Order = [:function, :macro]
```

18 changes: 18 additions & 0 deletions docs/src/DataFramesExt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## API reference
```@autodocs
Modules = [DataFramesExt]
Order = [:module]
```

## Types
```@autodocs
Modules = [DataFramesExt]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [DataFramesExt]
Order = [:function, :macro]
```

18 changes: 18 additions & 0 deletions docs/src/FITSIOExt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## API reference
```@autodocs
Modules = [FITSIOExt]
Order = [:module]
```

## Types
```@autodocs
Modules = [FITSIOExt]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [FITSIOExt]
Order = [:function, :macro]
```

18 changes: 18 additions & 0 deletions docs/src/StatisticsExt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## API reference
```@autodocs
Modules = [StatisticsExt]
Order = [:module]
```

## Types
```@autodocs
Modules = [StatisticsExt]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [StatisticsExt]
Order = [:function, :macro]
```

18 changes: 18 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## API reference
```@autodocs
Modules = [Exts]
Order = [:module]
```

## Types
```@autodocs
Modules = [Exts]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [Exts]
Order = [:function, :macro]
```

32 changes: 32 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Exts.jl
[![CI status](https://github.com/0h7z/Exts.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/0h7z/Exts.jl/actions/workflows/CI.yml)
[![codecov.io](https://codecov.io/gh/0h7z/Exts.jl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/0h7z/Exts.jl)

*****
## Usage
```julia
pkg> registry add https://github.com/0h7z/0hjl.git
pkg> add Exts

julia> using Exts
```

*****
## API reference
```@autodocs
Modules = [Exts]
Order = [:module]
```

## Types
```@autodocs
Modules = [Exts]
Order = [:constant, :type]
```

## Functions
```@autodocs
Modules = [Exts]
Order = [:function, :macro]
```

3 changes: 3 additions & 0 deletions ext/DataFramesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""
DataFramesExt
"""
module DataFramesExt

using DataFrames: DataFrame
Expand Down
7 changes: 6 additions & 1 deletion ext/FITSIOExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""
FITSIOExt
"""
module FITSIOExt

using Base.Threads: @spawn
Expand All @@ -22,6 +25,8 @@ using FITSIO: FITSIO, FITS, EitherTableHDU
const ensure_vector(a::AbstractArray) = eachslice(a, dims = ndims(a))
const ensure_vector(v::AbstractVector) = v

@doc " FITSIO.EitherTableHDU = Union{TableHDU, ASCIITableHDU}" EitherTableHDU

"""
read(t::ASCIITableHDU, DataFrame,
colnames = Tables.columnnames(t)) -> DataFrame
Expand All @@ -39,7 +44,7 @@ function Base.read(t::EitherTableHDU, ::Type{DataFrame},
@spawn ensure_vector(FITS(f -> read(f[n], colname), f))
end
DataFrame(map(fetch, cols), colnames)
end
end # @doc read(::TableHDU, ::Type{DataFrame}, ::AbstractVector{Symbol})

end # module

9 changes: 7 additions & 2 deletions ext/StatisticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""
StatisticsExt
"""
module StatisticsExt

using Exts: Exts
Expand All @@ -25,12 +28,14 @@ Compute the weighted mean of array `A` with weight vector `w`, and fallback
to the unweighted mean if `w` is all zero(s) (instead of returning `NaN`). If
`dims` (of type `Int`) is provided, compute the mean along dimension `dims`.
See also [`mean(::AbstractArray, ::AbstractWeights)`](@ref).
See also [`mean(::AbstractArray)`](@extref `Statistics.mean`),
[`mean(::AbstractArray,
::AbstractWeights)`](https://juliastats.org/StatsBase.jl/stable/scalarstats/#Statistics.mean).
"""
function Exts.nanmean(A::AbstractArray, w::AbstractWeights; dims::Union{Colon, Int} = :)
r = mean(A, (w); dims)
!isnan(r) ? (r) : (@assert all(iszero, w); mean(A; dims))
end
end # @doc nanmean

end # module

9 changes: 6 additions & 3 deletions src/BaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""
BaseExt
"""
module BaseExt

function Base.adjoint(m::T) where T <: AbstractVecOrMat{Any}
Expand All @@ -35,14 +38,14 @@ function Base.convert(::Type{S}, v::AbstractVector) where S <: AbstractSet{T} wh
end

"""
log10(x::T, σ::T) where T <: Real -> NTuple{2, AbstractFloat}
log10(x::T, σ::T) -> NTuple{2, AbstractFloat} where T <: Real
Compute the logarithm of `x ± σ` to base 10.
"""
function Base.log10(x::T, σ::T) where T <: Real
# https://physics.stackexchange.com/q/95254
log10(x), σ / log(10)x
end
log10(x), (σ / log(10)x)
end # @doc log10(::T, ::T) where T <: Real

end # module

Loading

0 comments on commit 395dd57

Please sign in to comment.