diff --git a/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl b/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl index d7974b2..9334a52 100644 --- a/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl +++ b/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl @@ -49,8 +49,8 @@ H = TensorValue(1.:81...) SUITE["Tensor algebra"]["δδ_μ_2d"] = @benchmarkable δᵢₖδⱼₗ2D + δᵢₗδⱼₖ2D SUITE["Tensor algebra"]["δδ_λ_2d"] = @benchmarkable 1.0 * δᵢⱼδₖₗ2D -SUITE["Tensor algebra"]["Cofactor"] = @benchmarkable cof(A) -SUITE["Tensor algebra"]["Det(A)Inv(A')"] = @benchmarkable det(A)*inv(A') -SUITE["Tensor algebra"]["×ᵢ⁴"] = @benchmarkable ×ᵢ⁴(A) -SUITE["Tensor algebra"]["IIsym"] = @benchmarkable IIsym(A) -SUITE["Tensor algebra"]["push_forward_C_to_F"] = @benchmarkable push_forward_C_to_F(F,H) +SUITE["Tensor algebra"]["Cofactor"] = @benchmarkable cof($A) +SUITE["Tensor algebra"]["Det(A)Inv(A')"] = @benchmarkable det($A)*inv($A') +SUITE["Tensor algebra"]["×ᵢ⁴"] = @benchmarkable ×ᵢ⁴($A) +SUITE["Tensor algebra"]["IIsym"] = @benchmarkable IIsym($A) +SUITE["Tensor algebra"]["push_forward_C_to_F"] = @benchmarkable push_forward_C_to_F($F,$H) diff --git a/src/TensorAlgebra/Operations.jl b/src/TensorAlgebra/Operations.jl index 24a974b..985f3f6 100644 --- a/src/TensorAlgebra/Operations.jl +++ b/src/TensorAlgebra/Operations.jl @@ -10,12 +10,30 @@ function (*)(Ten1::TensorValue, Ten2::TensorValue) end -@inline @generated function (+)(A::TensorValue{D,D}, B::TensorValue{D,D}) where {D} +@inline @generated function (+)(A::TensorValue{D1,D2}, B::TensorValue{D1,D2}) where {D1,D2} str = "" - for i in 1:D*D + for i in 1:D1*D2 str *= "A.data[$i] + B.data[$i], " end - Meta.parse("TensorValue{D,D}($str)") + Meta.parse("TensorValue{D1,D2}($str)") +end + + +@inline @generated function (-)(A::TensorValue{D1,D2}, B::TensorValue{D1,D2}) where {D1,D2} + str = "" + for i in 1:D1*D2 + str *= "A.data[$i] - B.data[$i], " + end + Meta.parse("TensorValue{D1,D2}($str)") +end + + +@inline @generated function (-)(A::TensorValue{D1,D2}) where {D1,D2} + str = "" + for i in 1:D1*D2 + str *= "-A.data[$i], " + end + Meta.parse("TensorValue{D1,D2}($str)") end diff --git a/src/TensorAlgebra/TensorAlgebra.jl b/src/TensorAlgebra/TensorAlgebra.jl index dfc7839..76abf9a 100644 --- a/src/TensorAlgebra/TensorAlgebra.jl +++ b/src/TensorAlgebra/TensorAlgebra.jl @@ -6,9 +6,11 @@ using StaticArrays using LinearAlgebra import Base: * import Base: + +import Base: - export (*) export (+) +export (-) export (⊗₁₂³) export (⊗₁₃²) export (⊗₁²³)