xref: /libCEED/julia/LibCEED.jl/docs/src/Misc.md (revision 06988bf74cc6ac18eacafe7930f080803395ba29)
1*6f5dc8baSWill Pazner# Linear Algebra
2*6f5dc8baSWill Pazner
3*6f5dc8baSWill PaznerUser Q-functions often perform small (1x1, 2x2, or 3x3) linear algebra
4*6f5dc8baSWill Pazneroperations (determinant, matrix-vector product, etc.) at every Q-point. For good
5*6f5dc8baSWill Paznerperformance, it is important to use specialized versions of these operations for
6*6f5dc8baSWill Paznerthe given size.
7*6f5dc8baSWill Pazner
8*6f5dc8baSWill PaznerIf the matrix or vector is given in a statically sized container (e.g. using
9*6f5dc8baSWill Pazner[StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl/)) then this
10*6f5dc8baSWill Paznerhappens automatically. However, if the matrix is not statically sized, and
11*6f5dc8baSWill Paznerinstead is given as, for example, a view into a larger array, then LibCEED.jl
12*6f5dc8baSWill Paznerprovides some convenient specialized functions.
13*6f5dc8baSWill Pazner
14*6f5dc8baSWill PaznerIn order to allow for generic code, the [`CeedDim`](@ref) struct is used for
15*6f5dc8baSWill Paznerdispatch. An object `D = CeedDim(dim)` can be created, and passed as a second
16*6f5dc8baSWill Paznerargument to functions like `det` to choose the specialized implementations. In
17*6f5dc8baSWill Paznerthis case, `dim` should be known as a compile-time constant, otherwise it will
18*6f5dc8baSWill Paznerresult in a type instability, and give poor performance.
19*6f5dc8baSWill Pazner
20*6f5dc8baSWill PaznerFor example:
21*6f5dc8baSWill Pazner```@repl
22*6f5dc8baSWill Paznerusing LibCEED, LinearAlgebra
23*6f5dc8baSWill Pazner
24*6f5dc8baSWill Paznerdim = 3;
25*6f5dc8baSWill PaznerJ = rand(dim, dim);
26*6f5dc8baSWill Pazner
27*6f5dc8baSWill Paznerdet(J) # Slow!
28*6f5dc8baSWill Paznerdet(J, CeedDim(dim)) # Fast!
29*6f5dc8baSWill Pazner```
30*6f5dc8baSWill Pazner
31*6f5dc8baSWill Pazner```@docs
32*6f5dc8baSWill PaznerCeedDim
33*6f5dc8baSWill Paznerdet(J, ::CeedDim{1})
34*6f5dc8baSWill Paznersetvoigt
35*6f5dc8baSWill Paznergetvoigt
36*6f5dc8baSWill Pazner```
37