-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
Reminder for me to factor out the cofactor matrix computation
Lines 80 to 132 in 258540f
| """ | |
| inv(::SecondOrderTensor) | |
| Computes the inverse of a second order tensor. | |
| # Examples | |
| ```jldoctest | |
| julia> A = rand(Tensor{2,3}) | |
| 3×3 Tensor{2, 3, Float64, 9}: | |
| 0.590845 0.460085 0.200586 | |
| 0.766797 0.794026 0.298614 | |
| 0.566237 0.854147 0.246837 | |
| julia> inv(A) | |
| 3×3 Tensor{2, 3, Float64, 9}: | |
| 19.7146 -19.2802 7.30384 | |
| 6.73809 -10.7687 7.55198 | |
| -68.541 81.4917 -38.8361 | |
| ``` | |
| """ | |
| @generated function Base.inv(t::Tensor{2, dim}) where {dim} | |
| Tt = get_base(t) | |
| idx(i,j) = compute_index(Tt, i, j) | |
| if dim == 1 | |
| ex = :($Tt((dinv, ))) | |
| elseif dim == 2 | |
| ex = quote | |
| v = get_data(t) | |
| $Tt((v[$(idx(2,2))] * dinv, -v[$(idx(2,1))] * dinv, | |
| -v[$(idx(1,2))] * dinv, v[$(idx(1,1))] * dinv)) | |
| end | |
| else # dim == 3 | |
| ex = quote | |
| v = get_data(t) | |
| $Tt(((v[$(idx(2,2))]*v[$(idx(3,3))] - v[$(idx(2,3))]*v[$(idx(3,2))]) * dinv, | |
| -(v[$(idx(2,1))]*v[$(idx(3,3))] - v[$(idx(2,3))]*v[$(idx(3,1))]) * dinv, | |
| (v[$(idx(2,1))]*v[$(idx(3,2))] - v[$(idx(2,2))]*v[$(idx(3,1))]) * dinv, | |
| -(v[$(idx(1,2))]*v[$(idx(3,3))] - v[$(idx(1,3))]*v[$(idx(3,2))]) * dinv, | |
| (v[$(idx(1,1))]*v[$(idx(3,3))] - v[$(idx(1,3))]*v[$(idx(3,1))]) * dinv, | |
| -(v[$(idx(1,1))]*v[$(idx(3,2))] - v[$(idx(1,2))]*v[$(idx(3,1))]) * dinv, | |
| (v[$(idx(1,2))]*v[$(idx(2,3))] - v[$(idx(1,3))]*v[$(idx(2,2))]) * dinv, | |
| -(v[$(idx(1,1))]*v[$(idx(2,3))] - v[$(idx(1,3))]*v[$(idx(2,1))]) * dinv, | |
| (v[$(idx(1,1))]*v[$(idx(2,2))] - v[$(idx(1,2))]*v[$(idx(2,1))]) * dinv)) | |
| end | |
| end | |
| return quote | |
| $(Expr(:meta, :inline)) | |
| dinv = 1 / det(t) | |
| @inbounds return $ex | |
| end | |
| end |
Users will for now probably use the identity
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels