Vectors and matrices
Vectors: Indexing starts with 0. Access to a single element via [].
- classic static
vector (static == at compile time)
- std:array<T,N> (see www)
- static
- some methods: [], at(), size(), constructors ()
- dynamic vector via pointer (dynamic ==
at run time)
- allocation (new T []) , deallocation (delete [])
- Example
skalar
(tar,
doc)
- std::vector<T> (see
www)
- some methods: [], at(), size(), constructors (), resize(),
push_back(), pop_back(), front(), back()
- method
data() returns a row pointer to the allocated memory.
- Example
skalar_stl
(tar,
doc)
- dynamic vector in example
intro_secretnumber
(tar,
doc)
- std::list<T> (see www)
- some
methods: constructors (), resize(), push_back(),
pop_back()
Dense matrices with N nows and M colums:
- not supported as data class in C++
- 2D storage:
- vector<vector<T>>
- non continuous memory for matrix
- fragile dynamic allocation
- access via mm[i][j]
- not compatible with most LinAlg libraries, e.g., BLAS, LAPACK,
which require POD (plain old data)
- 1D storage:
- vector<T>
- vector length N*M needed
- continuous memory for matrix
- access via mm[i*M+j]
- via mm.data(), N, M compatible with
LinAlg libraries.
- Example intro_vector_densematrix (tar,
doc)
Sparse matrices (www):
- not supported
- many different matrix formats (CRS,COO, ...)
- we will used CRS (also named CSR) as described in the FEM code (plain
version, oo
version)
- Example
intro_crsmatrix
(tar,
doc)
Jan 24, 2019