Skip to content

Commit 782c36c

Browse files
authored
Generalize arguments of Summed (#18)
1 parent d932692 commit 782c36c

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MapBroadcast"
22
uuid = "ebd9b9da-f48d-417c-9660-449667d60261"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.1.10"
4+
version = "0.1.11"
55

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

src/linearcombination.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function (f::LinearCombination)(args...)
77
return mapreduce(*,+,coefficients(f),args)
88
end
99

10-
struct Summed{Style,N,C<:NTuple{N},A<:NTuple{N}}
10+
struct Summed{Style,N,C<:NTuple{N,Any},A<:NTuple{N,Any}}
1111
style::Style
1212
coefficients::C
1313
arguments::A

test/test_basics.jl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,71 @@ end
7777

7878
@testset "Summed" begin
7979
elt = Float64
80+
8081
a1 = randn(elt, 2, 2)
8182
a2 = randn(elt, 2, 2)
82-
8383
s = Summed(a1)
8484
@test arguments(s) (a1,)
8585
@test coefficients(s) (one(elt),)
8686

87+
a1 = randn(elt, 2, 2)
88+
a2 = randn(elt, 2, 2)
8789
s = -Summed(a1)
8890
@test arguments(s) (a1,)
8991
@test coefficients(s) (-one(elt),)
9092

93+
a1 = randn(elt, 2, 2)
94+
a2 = randn(elt, 2, 2)
9195
s = 2 * Summed(a1)
9296
@test arguments(s) (a1,)
9397
@test coefficients(s) (2 * one(elt),)
9498

99+
a1 = randn(elt, 2, 2)
100+
a2 = randn(elt, 2, 2)
95101
s = Summed(a1) * 2
96102
@test arguments(s) (a1,)
97103
@test coefficients(s) (2 * one(elt),)
98104

105+
a1 = randn(elt, 2, 2)
106+
a2 = randn(elt, 2, 2)
99107
s = Summed(a1) / 2
100108
@test arguments(s) (a1,)
101109
@test coefficients(s) (one(elt) / 2,)
102110

111+
a1 = randn(elt, 2, 2)
112+
a2 = randn(elt, 2, 2)
103113
s = 2 * Summed(a1) + 3 * Summed(a2)
104114
@test arguments(s) (a1, a2)
105115
@test coefficients(s) (2 * one(elt), 3 * one(elt))
106116

117+
a1 = randn(elt, 2, 2)
118+
a2 = randn(elt, 2, 2)
107119
s = 2 * Summed(a1) - 3 * Summed(a2)
108120
@test arguments(s) (a1, a2)
109121
@test coefficients(s) (2 * one(elt), -3 * one(elt))
110122

123+
a1 = randn(elt, 2, 2)
124+
a2 = randn(elt, 2, 2)
111125
s = 4 * (2 * Summed(a1) + 3 * Summed(a2))
112126
@test arguments(s) (a1, a2)
113127
@test coefficients(s) (8 * one(elt), 12 * one(elt))
114128

129+
a1 = randn(elt, 2, 2)
130+
a2 = randn(elt, 2, 2)
115131
@test Summed(a1) + a2 Summed(a1) + Summed(a2)
116132
@test Summed(a1) - a2 Summed(a1) - Summed(a2)
117133
@test a1 + Summed(a2) Summed(a1) + Summed(a2)
118134
@test a1 - Summed(a2) Summed(a1) - Summed(a2)
119135

136+
# Regression test mixed types
137+
a1 = [1, 2]
138+
a2 = [1.0, 2.0]
139+
s = Summed(a1) + Summed(a2)
140+
@test arguments(s) (a1, a2)
141+
@test coefficients(s) (1, 1.0)
142+
143+
a1 = randn(elt, 2, 2)
144+
a2 = randn(elt, 2, 2)
120145
s = 2 * Summed(a1) + 3 * Summed(a2)
121146
@test arguments(s) (a1, a2)
122147
@test coefficients(s) (2 * one(elt), 3 * one(elt))
@@ -137,6 +162,9 @@ end
137162
@test copyto!(similar(s), s) 2 * a1 + 3 * a2
138163
@test s[1, 2] 2 * a1[1, 2] + 3 * a2[1, 2]
139164

165+
a1 = randn(elt, 2, 2)
166+
a2 = randn(elt, 2, 2)
167+
s = 2 * Summed(a1) + 3 * Summed(a2)
140168
@test Broadcasted(s) isa Broadcasted
141169
@test Broadcasted(s).style BroadcastStyle(typeof(a1))
142170
@test Broadcasted(s).f LinearCombination(s)

0 commit comments

Comments
 (0)