Skip to content

Commit 1e854f3

Browse files
authored
Add missing similar definition (#4)
1 parent 986e780 commit 1e854f3

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
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.1"
4+
version = "0.1.2"
55

66
[deps]
77
DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"

src/KroneckerArrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ function Base.similar(
112112
) where {A,B}
113113
return similar(A, map(ax -> ax.product.a, axs)) similar(B, map(ax -> ax.product.b, axs))
114114
end
115+
function Base.similar(
116+
::Type{<:KroneckerArray{<:Any,<:Any,A,B}}, sz::Tuple{Int,Vararg{Int}}
117+
) where {A,B}
118+
return similar(promote_type(A, B), sz)
119+
end
115120

116121
Base.collect(a::KroneckerArray) = kron(a.a, a.b)
117122

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1111
Aqua = "0.8"
1212
KroneckerArrays = "0.1"
1313
LinearAlgebra = "1.10"
14+
MatrixAlgebraKit = "0.2"
1415
SafeTestsets = "0.1"
1516
Suppressor = "0.2"
1617
Test = "1.10"

test/test_basics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const elts = (Float32, Float64, ComplexF32, ComplexF64)
1111
a = randn(elt, 2, 2) randn(elt, 3, 3)
1212
b = randn(elt, 2, 2) randn(elt, 3, 3)
1313
c = a.a b.b
14+
@test similar(typeof(a), (2, 3)) isa Matrix{elt}
15+
@test size(similar(typeof(a), (2, 3))) == (2, 3)
1416
@test a[1 × 1, 1 × 1] == a.a[1, 1] * a.b[1, 1]
1517
@test a[1 × 3, 2 × 1] == a.a[1, 2] * a.b[3, 1]
1618
@test a[1 × (2:3), 2 × 1] == a.a[1, 2] * a.b[2:3, 1]

0 commit comments

Comments
 (0)