Skip to content

Commit 8cbf82d

Browse files
authored
Merge pull request #230 from dfdx/dfdx/fix-test-broadcasted
Fix test_approx() when one of the arguments is a broadcasted multidimensional array
2 parents e30fcb4 + 5e5acf8 commit 8cbf82d

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ docs/site/
2727

2828
# JetBrains meta files
2929
.idea/*
30+
31+
# VS Code meta files
32+
.vscode/

src/check_result.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ function test_approx(actual::A, expected::E, msg=""; kwargs...) where {A,E}
142142
if _can_pass_early(actual, expected)
143143
@test true
144144
else
145-
c_actual = collect(actual)
146-
c_expected = collect(expected)
145+
# Works around https://github.com/JuliaLang/julia/issues/43847 on pre-Julia v1.9
146+
c_actual = collect(Broadcast.materialize(actual))
147+
c_expected = collect(Broadcast.materialize(expected))
147148
if (c_actual isa A) && (c_expected isa E) # prevent stack-overflow
148149
throw(MethodError, test_approx, (actual, expected))
149150
end

test/check_result.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ end
3636

3737
test_approx([1.0, 2.0], [1.0, 2.0])
3838
test_approx([[1.0], [2.0]], [[1.0], [2.0]])
39+
test_approx(Broadcast.broadcasted(identity, [1.0 2.0; 3.0 4.0]), [1.0 2.0; 3.0 4.0])
3940

4041
test_approx(@thunk(10 * 0.1 * [[1.0], [2.0]]), [[1.0], [2.0]])
4142

0 commit comments

Comments
 (0)