Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KroneckerArrays"
uuid = "05d0b138-81bc-4ff7-84be-08becefb1ccc"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.8"
version = "0.2.9"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
23 changes: 19 additions & 4 deletions src/kroneckerarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,26 @@ function Base.:(==)(a::AbstractKroneckerArray, b::AbstractKroneckerArray)
return arg1(a) == arg1(b) && arg2(a) == arg2(b)
end

# TODO: this definition doesn't fully retain the original meaning:
# ‖a - b‖ < atol could be true even if the following check isn't
function Base.isapprox(a::AbstractKroneckerArray, b::AbstractKroneckerArray; kwargs...)
return isapprox(arg1(a), arg1(b); kwargs...) && isapprox(arg2(a), arg2(b); kwargs...)
using LinearAlgebra: promote_leaf_eltypes
function Base.isapprox(
a::KroneckerArray, b::KroneckerArray;
atol::Real = 0,
rtol::Real = Base.rtoldefault(promote_leaf_eltypes(a), promote_leaf_eltypes(b), atol),
norm::Function = norm
)
a1, a2 = arg1(a), arg2(a)
b1, b2 = arg1(b), arg2(b)
# Approximation of:
# norm(a - b) = norm(a1 ⊗ a2 - b1 ⊗ b2)
# = norm((a1 - b1) ⊗ a2 + b1 ⊗ (a2 - b2) + (a1 - b1) ⊗ (a2 - b2))
diff1 = norm(a1 - b1)
diff2 = norm(a2 - b2)
d = diff1 * norm(a2) + norm(b1) * diff2 + diff1 * diff2
return iszero(rtol) ? d <= atol : d <= max(atol, rtol * max(norm(a), norm(b)))
end

function Base.iszero(a::KroneckerArray)

function Base.iszero(a::AbstractKroneckerArray)
return iszero(arg1(a)) || iszero(arg2(a))
end
Expand Down
Loading