Skip to content

Conversation

@miguelmaso
Copy link
Collaborator

In PR #1 some operations were added in tensor algebra. In this PR, duplicated functions have been removed and optimized.

Additionally, some tests are stronger. For instance, the previous tests were unable to track some operations, given that norm(⊗₁₂³⁴) == norm(⊗₁₃²⁴) == norm(⊗₁₄²³) or norm(⊗₁²³) == norm(⊗₁₂³) == norm(⊗₁₃²). The current tests take advantage of the integer multiplications, which are easy to track component by component.

On the performance side, the substitution of component by component multiplications by generated functions, allow to speedup operations about x30. In the case of contractions in R² space:

BenchmarkTools.Trial: 10000 samples with 158 evaluations per sample.
 Range (min  max):  659.494 ns   29.168 μs  ┊ GC (min  max): 0.00%  95.51%
 Time  (median):     735.443 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   826.036 ns ± 713.565 ns  ┊ GC (mean ± σ):  8.20% ±  9.00%

  █▇▅▃                                                          ▁
  ██████▅▅▄▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▃▃▅ █
  659 ns        Histogram: log(frequency) by time       6.23 μs <

 Memory estimate: 736 bytes, allocs estimate: 7.

BenchmarkTools.Trial: 10000 samples with 998 evaluations per sample.
 Range (min  max):  15.932 ns   5.511 μs  ┊ GC (min  max):  0.00%  98.90%
 Time  (median):     19.238 ns              ┊ GC (median):     0.00%
 Time  (mean ± σ):   29.613 ns ± 98.910 ns  ┊ GC (mean ± σ):  14.40% ±  7.46%

  ▄██▇▆▄▂▁                 ▁▂▂▂▂▂▂▂▁▂▂▂▂▁                     ▂
  ███████████▇▆▅▄▄▄▁▅▁▁▁▃▄▆███████████████▇▇▆▆▆▆▅▆▇▆▇▅▆▅▄▅▅▅▄ █
  15.9 ns      Histogram: log(frequency) by time      90.5 ns <

 Memory estimate: 144 bytes, allocs estimate: 1.

The corresponding changes have been applied to the viscous model.

@miguelmaso miguelmaso changed the title TesnorAlgebra lcenaup and optimization TesnorAlgebra clenaup and optimization Sep 15, 2025
Copy link
Collaborator

@jmartfrut jmartfrut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice contribution!!

@miguelmaso
Copy link
Collaborator Author

It is passing the tests and I've run some simulations.

I'll wait to merge until you confirm the changes are not affecting your simulations.

@miguelmaso miguelmaso changed the title TesnorAlgebra clenaup and optimization TensorAlgebra cleanup and optimization Sep 15, 2025
@jmartfrut jmartfrut merged commit f4a62b1 into main Sep 15, 2025
3 checks passed
@miguelmaso miguelmaso deleted the mmaso/tensor-algebra branch September 17, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants