Skip to content

Commit 7a1f4d7

Browse files
Merge branch 'master' into jdf/alt_findminmax
2 parents b3f3f12 + 1fde86f commit 7a1f4d7

File tree

8 files changed

+156
-15
lines changed

8 files changed

+156
-15
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "weekly"

.github/workflows/CompatHelper.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CompatHelper
2+
on:
3+
schedule:
4+
- cron: 0 0 * * *
5+
workflow_dispatch:
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
jobs:
10+
CompatHelper:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check if Julia is already available in the PATH
14+
id: julia_in_path
15+
run: which julia
16+
continue-on-error: true
17+
- name: Install Julia, but only if it is not already available in the PATH
18+
uses: julia-actions/setup-julia@v2
19+
with:
20+
version: '1'
21+
arch: ${{ runner.arch }}
22+
if: steps.julia_in_path.outcome != 'success'
23+
- name: "Add the General registry via Git"
24+
run: |
25+
import Pkg
26+
ENV["JULIA_PKG_SERVER"] = ""
27+
Pkg.Registry.add("General")
28+
shell: julia --color=yes {0}
29+
- name: "Install CompatHelper"
30+
run: |
31+
import Pkg
32+
name = "CompatHelper"
33+
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
34+
version = "3"
35+
Pkg.add(; name, uuid, version)
36+
shell: julia --color=yes {0}
37+
- name: "Run CompatHelper"
38+
run: |
39+
import CompatHelper
40+
CompatHelper.main()
41+
shell: julia --color=yes {0}
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
45+
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}

.github/workflows/Invalidations.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Invalidations
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: always.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
evaluate:
14+
# Only run on PRs to the default branch.
15+
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
16+
if: github.base_ref == github.event.repository.default_branch
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: julia-actions/setup-julia@v1
20+
with:
21+
version: '1'
22+
- uses: actions/checkout@v3
23+
- uses: julia-actions/julia-buildpkg@v1
24+
- uses: julia-actions/julia-invalidations@v1
25+
id: invs_pr
26+
27+
- uses: actions/checkout@v3
28+
with:
29+
ref: ${{ github.event.repository.default_branch }}
30+
- uses: julia-actions/julia-buildpkg@v1
31+
- uses: julia-actions/julia-invalidations@v1
32+
id: invs_default
33+
34+
- name: Report invalidation counts
35+
run: |
36+
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
37+
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
38+
- name: Check if the PR does increase number of invalidations
39+
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
40+
run: exit 1

.github/workflows/ci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
version: ['1.6', '1', 'nightly'] # Test against LTS, current minor release, and nightly
14+
version: ['1.10', '1', 'pre'] # Test against LTS, current minor release, and pre-releases
1515
os:
1616
- ubuntu-latest
1717
- macOS-latest
@@ -23,12 +23,12 @@ jobs:
2323
- os: macOS-latest
2424
arch: x86
2525
steps:
26-
- uses: actions/checkout@v2
27-
- uses: julia-actions/setup-julia@v1
26+
- uses: actions/checkout@v4
27+
- uses: julia-actions/setup-julia@v2
2828
with:
2929
version: ${{ matrix.version }}
3030
arch: ${{ matrix.arch }}
31-
- uses: actions/cache@v1
31+
- uses: actions/cache@v4
3232
env:
3333
cache-name: cache-artifacts
3434
with:
@@ -41,6 +41,7 @@ jobs:
4141
- uses: julia-actions/julia-buildpkg@v1
4242
- uses: julia-actions/julia-runtest@v1
4343
- uses: julia-actions/julia-processcoverage@v1
44-
- uses: codecov/codecov-action@v1
44+
- uses: codecov/codecov-action@v5
4545
with:
46-
file: lcov.info
46+
files: lcov.info
47+
token: ${{ secrets.CODECOV_TOKEN }}

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name = "NaNMath"
22
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
3-
repo = "https://github.com/mlubin/NaNMath.jl.git"
3+
repo = "https://github.com/JuliaMath/NaNMath.jl.git"
44
authors = ["Miles Lubin"]
5-
version = "1.0.1"
5+
version = "1.1.0"
66

77
[deps]
88
OpenLibm_jll = "05823500-19ac-5b8b-9628-191a04bc5112"
99

1010
[compat]
11-
julia = "1.6"
11+
julia = "1.10"
1212

1313
[extras]
1414
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# NaNMath
22

3-
[![deps](https://juliahub.com/docs/NaNMath/deps.svg)](https://juliahub.com/ui/Packages/NaNMath/k9Y1O?t=2)
3+
[![CI](https://github.com/JuliaMath/NaNMath.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaMath/NaNMath.jl/actions/workflows/ci.yml)
4+
[![codecov](https://codecov.io/gh/JuliaMath/NaNMath.jl/graph/badge.svg?token=uoFvfoAd4T)](https://codecov.io/gh/JuliaMath/NaNMath.jl)
5+
[![deps](https://juliahub.com/docs/General/NaNMath/stable/deps.svg)](https://juliahub.com/ui/Packages/General/NaNMath?t=2)
46

57
Implementations of basic math functions which return ``NaN`` instead of throwing a ``DomainError``.
68

src/NaNMath.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,38 @@ for f in (:sin, :cos, :tan, :asin, :acos, :acosh, :atanh, :log, :log2, :log10,
99
($f)(x::Float64) = ccall(($(string(f)),libm), Float64, (Float64,), x)
1010
($f)(x::Float32) = ccall(($(string(f,"f")),libm), Float32, (Float32,), x)
1111
($f)(x::Real) = ($f)(float(x))
12+
if $f !== :lgamma
13+
($f)(x) = (Base.$f)(x)
14+
end
1215
end
1316
end
1417

18+
for f in (:sqrt,)
19+
@eval ($f)(x) = (Base.$f)(x)
20+
end
21+
22+
for f in (:max, :min)
23+
@eval ($f)(x, y) = (Base.$f)(x, y)
24+
end
25+
1526
# Would be more efficient to remove the domain check in Base.sqrt(),
1627
# but this doesn't seem easy to do.
17-
sqrt(x::Real) = x < 0.0 ? NaN : Base.sqrt(x)
28+
sqrt(x::T) where {T<:AbstractFloat} = x < 0.0 ? T(NaN) : Base.sqrt(x)
29+
sqrt(x::Real) = sqrt(float(x))
1830

1931
# Don't override built-in ^ operator
2032
pow(x::Float64, y::Float64) = ccall((:pow,libm), Float64, (Float64,Float64), x, y)
2133
pow(x::Float32, y::Float32) = ccall((:powf,libm), Float32, (Float32,Float32), x, y)
2234
# We `promote` first before converting to floating pointing numbers to ensure that
2335
# e.g. `pow(::Float32, ::Int)` ends up calling `pow(::Float32, ::Float32)`
24-
pow(x::Number, y::Number) = pow(promote(x, y)...)
25-
pow(x::T, y::T) where {T<:Number} = pow(float(x), float(y))
36+
pow(x::Real, y::Real) = pow(promote(x, y)...)
37+
pow(x::T, y::T) where {T<:Real} = pow(float(x), float(y))
38+
pow(x, y) = ^(x, y)
39+
40+
# The following combinations are safe, so we can fall back to ^
41+
pow(x::Number, y::Integer) = x^y
42+
pow(x::Real, y::Integer) = x^y
43+
pow(x::Complex, y::Complex) = x^y
2644

2745
"""
2846
NaNMath.sum(A)

test/runtests.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using Test
77
@test isnan(NaNMath.pow(-1.5f0,2.3f0))
88
@test isnan(NaNMath.pow(-1.5,2.3f0))
99
@test isnan(NaNMath.pow(-1.5f0,2.3))
10-
@test NaNMath.pow(-1,2) isa Float64
1110
@test NaNMath.pow(-1.5f0,2) isa Float32
1211
@test NaNMath.pow(-1.5f0,2//1) isa Float32
1312
@test NaNMath.pow(-1.5f0,2.3f0) isa Float32
@@ -16,8 +15,22 @@ using Test
1615
@test NaNMath.pow(-1.5,2//1) isa Float64
1716
@test NaNMath.pow(-1.5,2.3f0) isa Float64
1817
@test NaNMath.pow(-1.5,2.3) isa Float64
18+
@test NaNMath.pow(-1,2) === 1
19+
@test NaNMath.pow(2,2) === 4
20+
@test NaNMath.pow(1.0, 1.0+im) === 1.0 + 0.0im
21+
@test NaNMath.pow(1.0+im, 1) === 1.0 + 1.0im
22+
@test NaNMath.pow(1.0+im, 1.0) === 1.0 + 1.0im
1923
@test isnan(NaNMath.sqrt(-5))
2024
@test NaNMath.sqrt(5) == Base.sqrt(5)
25+
@test isnan(NaNMath.sqrt(-3.2f0)) && NaNMath.sqrt(-3.2f0) isa Float32
26+
@test isnan(NaNMath.sqrt(-BigFloat(7.0))) && NaNMath.sqrt(-BigFloat(7.0)) isa BigFloat
27+
@test isnan(NaNMath.sqrt(-7)) && NaNMath.sqrt(-7) isa Float64
28+
@inferred NaNMath.sqrt(5)
29+
@inferred NaNMath.sqrt(5.0)
30+
@inferred NaNMath.sqrt(5.0f0)
31+
@inferred NaNMath.sqrt(-5)
32+
@inferred NaNMath.sqrt(-5.0)
33+
@inferred NaNMath.sqrt(-5.0f0)
2134
@test NaNMath.sum([1., 2., NaN]) == 3.0
2235
@test NaNMath.sum([1. 2.; NaN 1.]) == 4.0
2336
@test isnan(NaNMath.sum([NaN, NaN]))
@@ -202,4 +215,19 @@ end
202215
@test NaNMath.argmax(x) === CartesianIndex(1, 2)
203216
@test NaNMath.argmin(exp,x) === -1.0
204217
@test NaNMath.argmax(exp,x) === 3.0
205-
end
218+
end
219+
220+
# Test forwarding
221+
x = 1 + 2im
222+
for f in (:sin, :cos, :tan, :asin, :acos, :acosh, :atanh, :log, :log2, :log10,
223+
:log1p, :sqrt)
224+
@test @eval (NaNMath.$f)(x) == $f(x)
225+
end
226+
227+
struct A end
228+
Base.isless(::A, ::A) = false
229+
y = A()
230+
for f in (:max, :min)
231+
@test @eval (NaNMath.$f)(y, y) == $f(y, y)
232+
end
233+
@test NaNMath.pow(x, x) == ^(x, x)

0 commit comments

Comments
 (0)