Skip to content

Commit 77f2331

Browse files
authored
Simplify and generalize Eye factorizations (#18)
1 parent aa15737 commit 77f2331

File tree

8 files changed

+272
-282
lines changed

8 files changed

+272
-282
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "KroneckerArrays"
22
uuid = "05d0b138-81bc-4ff7-84be-08becefb1ccc"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.1.12"
4+
version = "0.1.13"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/KroneckerArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ include("matrixalgebrakit.jl")
99
include("fillarrays/kroneckerarray.jl")
1010
include("fillarrays/linearalgebra.jl")
1111
include("fillarrays/matrixalgebrakit.jl")
12+
include("fillarrays/matrixalgebrakit_truncate.jl")
1213

1314
end

src/fillarrays/kroneckerarray.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ const SquareEyeSquareEye{T,A<:SquareEye{T},B<:SquareEye{T}} = KroneckerMatrix{T,
1111
# Like `adapt` but preserves `Eye`.
1212
_adapt(to, a::Eye) = a
1313

14+
# Like `similar` but preserves `Eye`.
15+
function _similar(a::AbstractArray, elt::Type, ax::Tuple)
16+
return similar(a, elt, ax)
17+
end
18+
function _similar(A::Type{<:AbstractArray}, ax::Tuple)
19+
return similar(A, ax)
20+
end
21+
function _similar(a::AbstractArray, ax::Tuple)
22+
return _similar(a, eltype(a), ax)
23+
end
24+
function _similar(a::AbstractArray, elt::Type)
25+
return _similar(a, elt, axes(a))
26+
end
27+
function _similar(a::AbstractArray)
28+
return _similar(a, eltype(a), axes(a))
29+
end
30+
1431
# Like `similar` but preserves `Eye`.
1532
function _similar(a::Eye, elt::Type, axs::NTuple{2,AbstractUnitRange})
1633
return Eye{elt}(axs)

src/fillarrays/linearalgebra.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ end
77

88
function _mul(a::Eye, b::Eye)
99
check_mul_axes(a, b)
10+
(size(a, 1) > size(a, 2)) &&
11+
(size(b, 1) < size(b, 2)) &&
12+
error("This multiplication leads to a projector.")
1013
T = promote_type(eltype(a), eltype(b))
1114
return Eye{T}((axes(a, 1), axes(b, 2)))
1215
end

0 commit comments

Comments
 (0)