From f35540bc0b9b78b6afde2029ac2d0fc3e5ab44be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 11 Nov 2025 14:57:56 +0100 Subject: [PATCH 1/3] faster cofactor --- src/TensorAlgebra/Functions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 72c25d94c934200d5607fdcbe59bb3589cb355da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 11 Nov 2025 14:58:35 +0100 Subject: [PATCH 2/3] rename + test --- .../{TensorAlgebra.jl => TensorAlgebraTests.jl} | 10 +++++++++- test/TestTensorAlgebra/runtests.jl | 12 ++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) rename test/TestTensorAlgebra/{TensorAlgebra.jl => TensorAlgebraTests.jl} (95%) 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 From 122b58e48b202667d20eaa26b430b67a4dd39632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mas=C3=B3?= Date: Tue, 11 Nov 2025 14:58:50 +0100 Subject: [PATCH 3/3] added benchmark --- benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl | 5 +++++ 1 file changed, 5 insertions(+) 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')