Skip to content

Commit 9096171

Browse files
authored
Merge pull request #62 from MultiSimOLab/cofactor
2 parents bf81795 + 122b58e commit 9096171

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ function _δδ_λ_2D(λ::Float64)
4242
λ)
4343
end
4444

45+
A = TensorValue(1.:9...)
46+
A = A + A' + I3
47+
4548
SUITE["Tensor algebra"]["δδ_μ_2d"] = @benchmarkable δᵢₖδⱼₗ2D + δᵢₗδⱼₖ2D
4649
SUITE["Tensor algebra"]["δδ_λ_2d"] = @benchmarkable 1.0 * δᵢⱼδₖₗ2D
50+
SUITE["Tensor algebra"]["Cofactor"] = cof(A)
51+
SUITE["Tensor algebra"]["Det(A)Inv(A')"] = det(A)*inv(A')

src/TensorAlgebra/Functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
Calculate the cofactor of a matrix.
1818
"""
1919
function cof(A::TensorValue)
20-
return det(A)*inv(A')
20+
0.5A×A
2121
end
2222

2323

test/TestTensorAlgebra/TensorAlgebra.jl renamed to test/TestTensorAlgebra/TensorAlgebraTests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,13 @@ end
104104
@testset "sqrt" begin
105105
A = TensorValue(1.:9...)
106106
A = A'*A + I3
107-
@test isapprox(sqrt(A), TensorValue(sqrt(get_array(A))), rtol=1e-14)
107+
sqrtA = TensorValue(sqrt(get_array(A)))
108+
@test isapprox(sqrt(A), sqrtA, rtol=1e-14)
109+
end
110+
111+
112+
@testset "cofactor" begin
113+
A = TensorValue(1.:9...) + I3
114+
cofA = det(A) * inv(A')
115+
@test isapprox(cof(A), cofA)
108116
end

test/TestTensorAlgebra/runtests.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
using HyperFEM
2+
using Gridap
3+
using Test
4+
15
@testset "TensorAlgebra" begin
26

3-
@time begin
4-
include("TensorAlgebra.jl")
5-
end
7+
@time begin
8+
include("TensorAlgebraTests.jl")
9+
end
610

7-
end
11+
end

0 commit comments

Comments
 (0)