Skip to content

Commit 485ee6d

Browse files
authored
Add tests for x_of_nans (#165)
1 parent 950a12c commit 485ee6d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DifferentiationInterface = "0.6.43, 0.7"
1616
FiniteDiff = "2.0"
1717
ForwardDiff = "0.10, 1.0"
1818
LinearAlgebra = "<0.0.1, 1"
19+
StaticArrays = "1.9"
1920
julia = "1.10"
2021

2122
[extras]
@@ -25,7 +26,8 @@ OptimTestProblems = "cec144fc-5a64-5bc6-99fb-dde8f63e154c"
2526
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2627
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2728
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
29+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2830
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2931

3032
[targets]
31-
test = ["ADTypes", "ComponentArrays", "OptimTestProblems", "Random", "RecursiveArrayTools", "SparseArrays", "Test"]
33+
test = ["ADTypes", "ComponentArrays", "OptimTestProblems", "Random", "RecursiveArrayTools", "SparseArrays", "StaticArrays", "Test"]

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using NLSolversBase, Test
22
using Random
33
using LinearAlgebra: Diagonal, I, mul!
44
using ComponentArrays
5+
using StaticArrays
56
using SparseArrays
67
using OptimTestProblems
78
using RecursiveArrayTools
@@ -87,4 +88,5 @@ end
8788
include("autodiff.jl")
8889
include("sparse.jl")
8990
include("kwargs.jl")
91+
include("utils.jl")
9092
end

test/utils.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@testset "utililties" begin
2+
@testset "x_of_nans" begin
3+
for T in (Int, Float32, Float64)
4+
for x in (zeros(T), zeros(T, 2), zeros(T, 3, 2))
5+
x_nans = @inferred(NLSolversBase.x_of_nans(x))
6+
@test x_nans isa Array{float(T),ndims(x)}
7+
@test size(x_nans) == size(x)
8+
@test all(isnan, x_nans)
9+
end
10+
11+
for x in (SArray{Tuple{}}(zeros(T)), SArray{Tuple{2}}(zeros(T, 2)), SArray{Tuple{3,2}}(zeros(T, 3, 2)))
12+
x_nans = @inferred(NLSolversBase.x_of_nans(x))
13+
@test x_nans isa MArray{Tuple{size(x)...},float(T)}
14+
@test size(x_nans) == size(x)
15+
@test all(isnan, x_nans)
16+
end
17+
18+
for x in (MArray{Tuple{}}(zeros(T)), MArray{Tuple{2}}(zeros(T, 2)), MArray{Tuple{3,2}}(zeros(T, 3, 2)))
19+
x_nans = @inferred(NLSolversBase.x_of_nans(x))
20+
@test x_nans isa MArray{Tuple{size(x)...},float(T)}
21+
@test size(x_nans) == size(x)
22+
@test all(isnan, x_nans)
23+
end
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)