Tensors.jl
Tensors.jl copied to clipboard
Cofactor Matrix
This is commonly used to compute the push-forward of surface areas from reference to current configuration in continuum mechanics (Nansons formula).
using Tensors, BenchmarkTools
F = Tensor{2,3,Float64}((1.1,-0.1,0.1, -0.1,0.9,0.0 ,0.25,0.0,1.2))
# Master version
cof2(F) = det(F)*transpose(inv(F))
@btime cof2($F); # 16.583 ns
@btime gradient(cof2, $F); # 233.892 ns
@btime gradient(cof2, $F, :all); # 236.603 ns
# This PR
@btime cof($F); # 5.890 ns
@btime gradient(cof, $F); # 78.131 ns
@btime gradient(cof, $F, :all); # 92.096 ns