Skip to content

Commit add9b06

Browse files
committed
Include cross terms
1 parent db344d5 commit add9b06

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/kroneckerarray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function Base.:(==)(a::AbstractKroneckerArray, b::AbstractKroneckerArray)
357357
return arg1(a) == arg1(b) && arg2(a) == arg2(b)
358358
end
359359

360-
using LinearAlgebra: promote_leaf_eltypes
360+
using LinearAlgebra: dot, promote_leaf_eltypes
361361
function Base.isapprox(
362362
a::KroneckerArray, b::KroneckerArray;
363363
atol::Real = 0,
@@ -369,9 +369,9 @@ function Base.isapprox(
369369
# Approximation of:
370370
# norm(a - b) = norm(a1 ⊗ a2 - b1 ⊗ b2)
371371
# = norm((a1 - b1) ⊗ a2 + b1 ⊗ (a2 - b2) + (a1 - b1) ⊗ (a2 - b2))
372-
diff1 = norm(a1 - b1)
373-
diff2 = norm(a2 - b2)
374-
d = diff1 * norm(a2) + norm(b1) * diff2 + diff1 * diff2
372+
diff1 = a1 - b1
373+
diff2 = a2 - b2
374+
d = sqrt(norm(diff1)^2 * norm(a2)^2 + norm(b1)^2 * norm(diff2)^2 + 2 * real(dot(diff1, b1) * dot(b2, diff2)))
375375
return iszero(rtol) ? d <= atol : d <= max(atol, rtol * max(norm(a), norm(b)))
376376
end
377377

0 commit comments

Comments
 (0)