Skip to content

Commit 06c6d59

Browse files
committed
Get atsign-test_approx_eq working for non-1 indices
1 parent 9114ae6 commit 06c6d59

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

base/test.jl

+8-7
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,11 @@ approx_full(x) = full(x)
827827
function test_approx_eq(va, vb, Eps, astr, bstr)
828828
va = approx_full(va)
829829
vb = approx_full(vb)
830-
if length(va) != length(vb)
830+
la, lb = length(linearindices(va)), length(linearindices(vb))
831+
if la != lb
831832
error("lengths of ", astr, " and ", bstr, " do not match: ",
832-
"\n ", astr, " (length $(length(va))) = ", va,
833-
"\n ", bstr, " (length $(length(vb))) = ", vb)
833+
"\n ", astr, " (length $la) = ", va,
834+
"\n ", bstr, " (length $lb) = ", vb)
834835
end
835836
diff = real(zero(eltype(va)))
836837
for (xa, xb) = zip(va, vb)
@@ -856,7 +857,7 @@ array_eps{T}(a::AbstractArray{Complex{T}}) = eps(float(maximum(x->(isfinite(x) ?
856857
array_eps(a) = eps(float(maximum(x->(isfinite(x) ? abs(x) : oftype(x,NaN)), a)))
857858

858859
test_approx_eq(va, vb, astr, bstr) =
859-
test_approx_eq(va, vb, 1E4*length(va)*max(array_eps(va), array_eps(vb)), astr, bstr)
860+
test_approx_eq(va, vb, 1E4*length(linearindices(va))*max(array_eps(va), array_eps(vb)), astr, bstr)
860861

861862
"""
862863
@test_approx_eq_eps(a, b, tol)
@@ -966,10 +967,10 @@ end
966967
# nothing.
967968
function test_approx_eq_modphase{S<:Real,T<:Real}(
968969
a::StridedVecOrMat{S}, b::StridedVecOrMat{T}, err=nothing)
969-
m, n = size(a)
970-
@test n==size(b, 2) && m==size(b, 1)
970+
@test indices(a,1) == indices(b,1) && indices(a,2) == indices(b,2)
971+
m = length(indices(a,1))
971972
err === nothing && (err=m^3*(eps(S)+eps(T)))
972-
for i=1:n
973+
for i in indices(a,2)
973974
v1, v2 = a[:, i], b[:, i]
974975
@test_approx_eq_eps min(abs(norm(v1-v2)), abs(norm(v1+v2))) 0.0 err
975976
end

test/offsetarray.jl

+2
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,11 @@ am = map(identity, a)
339339

340340
# other functions
341341
v = OffsetArray(v0, (-3,))
342+
@test_approx_eq v v
342343
@test parent(v') == v0'
343344
@test indices(v') === (1:1,-2:1)
344345
A = OffsetArray(rand(4,4), (-3,5))
346+
@test_approx_eq A A
345347
@test maximum(A) == maximum(parent(A))
346348
@test minimum(A) == minimum(parent(A))
347349
@test extrema(A) == extrema(parent(A))

0 commit comments

Comments
 (0)