diff --git a/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl b/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl index 66342fc..7693540 100644 --- a/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl +++ b/benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl @@ -42,5 +42,10 @@ function _δδ_λ_2D(λ::Float64) λ) end +A = TensorValue(1.:9...) +A = A + A' + I3 + SUITE["Tensor algebra"]["δδ_μ_2d"] = @benchmarkable δᵢₖδⱼₗ2D + δᵢₗδⱼₖ2D SUITE["Tensor algebra"]["δδ_λ_2d"] = @benchmarkable 1.0 * δᵢⱼδₖₗ2D +SUITE["Tensor algebra"]["Cofactor"] = cof(A) +SUITE["Tensor algebra"]["Det(A)Inv(A')"] = det(A)*inv(A') diff --git a/src/TensorAlgebra/Functions.jl b/src/TensorAlgebra/Functions.jl index 782e8cd..3cdf3bf 100644 --- a/src/TensorAlgebra/Functions.jl +++ b/src/TensorAlgebra/Functions.jl @@ -17,7 +17,7 @@ end Calculate the cofactor of a matrix. """ function cof(A::TensorValue) - return det(A)*inv(A') + 0.5A×A end diff --git a/test/TestTensorAlgebra/TensorAlgebra.jl b/test/TestTensorAlgebra/TensorAlgebraTests.jl similarity index 95% rename from test/TestTensorAlgebra/TensorAlgebra.jl rename to test/TestTensorAlgebra/TensorAlgebraTests.jl index 126ecfc..c84ecff 100644 --- a/test/TestTensorAlgebra/TensorAlgebra.jl +++ b/test/TestTensorAlgebra/TensorAlgebraTests.jl @@ -104,5 +104,13 @@ end @testset "sqrt" begin A = TensorValue(1.:9...) A = A'*A + I3 - @test isapprox(sqrt(A), TensorValue(sqrt(get_array(A))), rtol=1e-14) + sqrtA = TensorValue(sqrt(get_array(A))) + @test isapprox(sqrt(A), sqrtA, rtol=1e-14) +end + + +@testset "cofactor" begin + A = TensorValue(1.:9...) + I3 + cofA = det(A) * inv(A') + @test isapprox(cof(A), cofA) end diff --git a/test/TestTensorAlgebra/runtests.jl b/test/TestTensorAlgebra/runtests.jl index 7b354b0..7f3e541 100644 --- a/test/TestTensorAlgebra/runtests.jl +++ b/test/TestTensorAlgebra/runtests.jl @@ -1,7 +1,11 @@ +using HyperFEM +using Gridap +using Test + @testset "TensorAlgebra" begin - @time begin - include("TensorAlgebra.jl") - end + @time begin + include("TensorAlgebraTests.jl") + end -end \ No newline at end of file +end