Skip to content

Commit 01aa0a3

Browse files
authored
specialize tensor_product for OneToOne (#6)
1 parent 8f82bc3 commit 01aa0a3

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-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 = "TensorProducts"
22
uuid = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[weakdeps]
77
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"

src/tensor_product.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ function tensor_product(a1::AbstractUnitRange, a2::AbstractUnitRange)
2828
return Base.OneTo(length(a1) * length(a2))
2929
end
3030

31+
# OneToOne acts as neutral element for tensor_product
3132
tensor_product(::OneToOne, ::OneToOne) = OneToOne()
33+
tensor_product(::OneToOne, a::AbstractUnitRange) = tensor_product(a)
34+
tensor_product(a::AbstractUnitRange, ::OneToOne) = tensor_product(a)

test/test_tensor_product.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ b1 = blockedrange([1, 2])
1515

1616
@test (r0, r0) isa OneToOne
1717
@test blockisequal((b1, b1), blockedrange([1, 2, 2, 4]))
18+
@test blockisequal((b1, r0), b1)
19+
@test blockisequal((r0, b1), b1)
1820
end
1921

2022
@testset "tensor_product" begin

0 commit comments

Comments
 (0)