Skip to content

Commit c25f399

Browse files
authored
Merge pull request #544 from diliphridya/Modify_dot
Modify dot
2 parents 972a67f + 29b881b commit c25f399

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/TensorValues/Operations.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ end
193193
end
194194

195195
# a_ilm = b_ij*c_jlm
196-
@generated function dot(a::A,b::B) where {A<:MultiValue{Tuple{D,D}},B<:ThirdOrderTensorValue{D}} where D
196+
@generated function dot(a::A,b::B) where {A<:MultiValue{Tuple{D,D}},B<:ThirdOrderTensorValue{D,D,L}} where {D,L}
197197
ss = String[]
198-
for m in 1:D
198+
for m in 1:L
199199
for l in 1:D
200200
for i in 1:D
201201
s = join([ "a[$i,$j]*b[$j,$l,$m]+" for j in 1:D])
@@ -204,8 +204,8 @@ end
204204
end
205205
end
206206
str = join(ss)
207-
Meta.parse("ThirdOrderTensorValue{$D}($str)")
208-
end
207+
Meta.parse("ThirdOrderTensorValue{$D,$D,$L}($str)")
208+
end
209209

210210
const ¹ = dot
211211

test/TensorValuesTests/OperationsTests.jl

+27
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,33 @@ c = a ⋅ st
224224
r = VectorValue(14,30,42)
225225
@test c == r
226226

227+
a1 = VectorValue(1,0)
228+
b1 = VectorValue(1,2)
229+
230+
t1 = ThirdOrderTensorValue{2,2,1}(1,2,3,4)
231+
t2 = TensorValue(1,0,0,1)
232+
t3 = TensorValue(1,2,0,0)
233+
234+
c = a1 t1
235+
@test isa(c,TensorValue{2,1,Int})
236+
r = TensorValue{2,1}(1,3)
237+
@test c == r
238+
239+
c = b1 t1
240+
@test isa(c,TensorValue{2,1,Int})
241+
r = TensorValue{2,1}(5,11)
242+
@test c == r
243+
244+
c = t2 t1
245+
@test isa(c,ThirdOrderTensorValue{2,2,1,Int,4})
246+
r = ThirdOrderTensorValue{2,2,1}(1,2,3,4)
247+
@test c == r
248+
249+
c = t3 t1
250+
@test isa(c,ThirdOrderTensorValue{2,2,1,Int,4})
251+
r = ThirdOrderTensorValue{2,2,1}(1,2,3,6)
252+
@test c == r
253+
227254
# Inner product (full contraction)
228255

229256
c = 2 3

0 commit comments

Comments
 (0)