Linear algebra library usage notes - isaar/MSolve GitHub Wiki
(as of 23/1/2019)
-
For general matrix and vector operations use LinearAlgebra.Matrices.Matrix and LinearAlgebra.Vectors.Vector. These are similar to the arrays used in Matlab.
-
You can read usage examples in LinearAlgebra.Tests project.
-
Most classes have descriptive static factory methods instead of public constructors. E.g. Vector.CreateFromArray(double[]) and Vector.CreateZero(int length).
-
Do not explicitly transpose the matrix if you only want to multiply it with a vector. Most matrix-vector multiplication methods have flags (e.g. bool transposeThis), that control whether A*x or AT*x will be performed. These are much more efficient than explicitly transposing. Same for matrix-matrix multiplications.
-
Many methods have an ~IntoThis() version:
- e.g. Vector.Add(Vector other) and Vector.AddIntoThis(Vector other).
- The ~IntoThis() version overwrites the object where the method is called from with the result. The simple version returns the result in a new object.
- The ~IntoThis() version is more efficient, since it avoids continuous allocations and deallocations of objects. Prefer it for temporary results.
-
About the vector-vector and matrix-matrix operation Axpy(): y = a*x+y.
- It is used very often if you think about it and linear algebra libraries often provide axpy() instead of add(), subtract().
- It is much more efficient than doing e.g. y = y.Add(x.Scale(a));
-
Current convention: for element sized operations or smaller (e.g. elementK * elementU) use a double[] array for vectors. Many operations provided for LinearAlgebra.Vectors.Vector are also provided for double[] as extension methods. To enable them, write using ISAAR.MSolve.LinearAlgebra; at the start of your file.
-
Except for pure C# code, it is possible to use the high performance libararies Intel MKL (dense operations for matrices and vectors) and SuiteSparse (sparse system solution, reorderings).
- They are disabled by default.
- Classes that use SuiteSparse usually say so in their name. E.g. ISAAR.MSolve.Solvers.Direct.SuiteSparseSolver
- You can choose whether to use C# code or MKL in your analysis by writing: using ISAAR.MSolve.LinearAlgebra; LibrarySettings.LinearAlgebraProviders = LinearAlgebraProviderChoice.MKL;
- Restrictions:
- You must download and install Intel MKL yourselves. See https://github.com/isaar/MSolve/wiki/How-to-install-Intel-MKL-on-windows for instructions. SuiteSparse depends on MKL by the way.
- MKL and SuiteSparse are native dlls written in C or Fortran. For now, we can only use them on windows x64 operating systems.
- Do NOT write tests that depend on native dlls. If you have an example analysis that is computationally heavy, you can add it to SamplesConsole and use MKl and SuiteSparse freely.