Table 1
Summary of implemented tensor operations. u, v denotes vectors, A, B denotes second-order symmetric or non-symmetric tensors, and C, D denotes fourth-order symmetric or non-symmetric tensors. We note that instead of using : for infix double contraction we use ⊡ (written as \boxdot). This is because : does not have the same operator precedence as multiplication in Julia.
| Operation | Julia code | infix |
|---|---|---|
| Single contraction | ||
| u · v (uivi) | dot(u, v) | u · v |
| A · v (Aijvj) | dot(A, v) | A · v |
| A · B (AijBjk) | dot(A, B) | A · B |
| Double contraction | ||
| A : B (AijBij) | dcontract(A, B) | A ⊡ B |
| C : B (CijklBkl) | dcontract(C, B) | C ⊡ B |
| C : D (CijklDklmn) | dcontract(A, D) | C ⊡ D |
| Outer product | ||
| u ⊗ v (uivj) | otimes(u, v) | u ⊗ v |
| A ⊗ B (AijBkl) | otimes(A, B) | A ⊗ B |
| Other operations | ||
| det(A) | det(A) | |
| inv(A) | inv(A) | |
| norm(A) | norm(A) | |
| AT | transpose(A) | |
| symmetric(A) | ||
| skew(A) | ||
Table 2
Comparison of performance for some tensor operations using Tensors.jl and Voigt format using Julia Arrays.
| Operation | Tensor | Array | Speed-up |
|---|---|---|---|
| Single contraction | |||
| u · u | 1.241 ns | 9.795 ns | ×7.9 |
| A · u | 2.161 ns | 58.769 ns | ×27.2 |
| A · A | 3.117 ns | 44.395 ns | ×14.2 |
| Asym · Asym | 5.125 ns | 44.498 ns | ×8.7 |
| Double contraction | |||
| A : A | 1.927 ns | 12.189 ns | ×6.3 |
| Asym : Asym | 1.927 ns | 12.187 ns | ×6.3 |
| C : A | 6.087 ns | 78.554 ns | ×12.9 |
| C : C | 60.820 ns | 280.502 ns | ×4.6 |
| Csym : Csym | 22.104 ns | 281.003 ns | ×12.7 |
| Asym : Csym : Asym | 9.466 ns | 89.747 ns | ×9.5 |
| Outer product | |||
| u ⊗ u | 2.167 ns | 32.447 ns | ×15.0 |
| A ⊗ A | 9.801 ns | 6.568 ns | ×8.8 |
| Other operations | |||
| det(A) | 1.924 ns | 177.134 ns | ×92.1 |
| inv(Asym) | 4.587 ns | 635.858 ns | ×138.6 |
| norm(A) | 1.990 ns | 16.752 ns | ×8.4 |
