Tensors.jl icon indicating copy to clipboard operation
Tensors.jl copied to clipboard

tensor_product macro

Open KnutAM opened this issue 2 years ago • 3 comments
trafficstars

Make it easy to define new unrolled tensor expressions based on an index expression, xref: https://github.com/Ferrite-FEM/Tensors.jl/pull/205#discussion_r1359951108

Examples

Tensors.@tensor_product(@inline @inbounds function dcontract(A::Tensor{4,3}, B::Tensor{4,3})
    C[i,j,k,l] = A[i,j,m,n]*B[m,n,k,l]
end, muladd)

Tensors.@tensor_product(@inline @inbounds function otimes(A::Tensor{2,3}, B::Tensor{2,3})
    C[i,j,k,l] = A[i,j]*B[k,l]
end)

TODO

  • [x] Support SymmetricTensor output (need to automatically figure out when based on the input and expression)
  • [x] Replace current functions with the generated functions where that makes sense (e.g. otimes already use index expression, and that approach seems faster than manually unrolling)
  • [x] Document the macro such that users can create their special functions (not public API yet)

KnutAM avatar Oct 25 '23 06:10 KnutAM

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (ce37b01) 96.91% compared to head (62d0fc7) 93.69%. Report is 3 commits behind head on master.

Files Patch % Lines
src/utilities.jl 92.48% 16 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #211      +/-   ##
==========================================
- Coverage   96.91%   93.69%   -3.23%     
==========================================
  Files          17       17              
  Lines        1490     1522      +32     
==========================================
- Hits         1444     1426      -18     
- Misses         46       96      +50     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 25 '23 07:10 codecov-commenter

I think this can also really help users getting https://github.com/Ferrite-FEM/Tensors.jl/pull/188 functional for their corner cases

termi-official avatar Dec 07 '23 12:12 termi-official

@fredrikekre or @KristofferC - would any of you have time to review?

Feels like there is too much code for "parsing" the user input, but didn't find a way to reduce it...

KnutAM avatar Jan 01 '24 18:01 KnutAM