13#ifndef ML_MATRIX_TEMPLATE_H
14#define ML_MATRIX_TEMPLATE_H
30#include <ThirdPartyWarningsDisable.h>
35#include <ThirdPartyWarningsRestore.h>
55 T& ref(
size_t i)
const {
return (*v)[s.start()+
i*s.stride()]; }
92 && p.s.stride()==
q.s.stride()
93 && p.s.start()==
q.s.start();
106 && p.s.stride()==
q.s.stride()
107 && p.s.start()==
q.s.start();
128 const T& ref(
size_t i)
const {
return (*v)[s.start()+
i*s.stride()]; }
164 return p.curr==
q.curr
165 && p.s.stride()==
q.s.stride()
166 && p.s.start()==
q.s.start();
179 && p.s.stride()==
q.s.stride()
180 && p.s.start()==
q.s.start();
207 size_t size()
const {
return size_x*size_y; }
208 size_t sizeX()
const {
return size_x; }
209 size_t sizeY()
const {
return size_y; }
234 std::valarray<T>&
array() {
return *v; }
236 operator T * () {
return reinterpret_cast<T*
>(&v); }
248template <
class T,
size_t SIZE_X,
size_t SIZE_Y>
299 v =
new std::valarray<T>(size_x*size_y);
310 v =
new std::valarray<T>(size_x*size_y);
322 this->resizeMatrix(
mt.size_x,
mt.size_y);
344 v->resize(size_x*size_y, c);
356 v->resize(size_x*size_y, c);
387 for (
size_t i = 0;
i<v2.size();
i++)
res+= v1[
i]*v2[
i];
396 if (
m.sizeX()!=v.size()){
399 "Wrong number of elements in m*v\n, ignoring problem");
402 std::valarray<T>
res(
m.sizeY());
403 for (
size_t i = 0;
i<
m.sizeY();
i++)
res[
i] =
mul(
m.row(
i),v);
413 if (
m.sizeX()!=v.size()){
416 "Wrong number of elements in m*v\n, ignoring problem");
419 std::valarray<T>
res(
m.sizeY());
421 for (
size_t i = 0;
i<
m.sizeY();
i++) {
434 if (v.size()!=
m.sizeY()){
437 "Wrong number of elements in v*m\n, ignoring problem");
440 std::valarray<T>
res(
m.sizeX());
442 for (
size_t i = 0;
i<
m.sizeX();
i++) {
461 for(
int y=0; y<
m.sizeY(); y++)
463 for(
int x=0; x<
m.sizeX(); x++)
Templated support class for class MatrixTemplate to allow fast element access organisation by slicing...
friend bool operator==(const Cslice_iter< T > &p, const Cslice_iter< T > &q)
overload operator==(.,.) for Cslice_iter objects
const T & operator()(size_t i) const
Fortran-style subscript.
Cslice_iter< T > & operator++()
standard itterator incrementation
const T & operator*() const
current element
const T & operator[](size_t i) const
C style subscript.
friend bool operator!=(const Cslice_iter< T > &p, const Cslice_iter< T > &q)
overload operator!=(.,.) for Cslice_iter objects
Cslice_iter< T > end() const
returns itterator positioned on last-plus-one element
Cslice_iter(std::valarray< T > *vv, std::slice ss)
constructor: initialising slice-itterator for val-array
Cslice_iter< T > operator++(int)
standard itterator incrementation
general Matrix class based on MatrixTemplate<T> to allow fixed size setting with object declaration.
MatrixSizedTemplate()
ctor: initialise size at object creation with desired value
MatricTemplate implements general Matrix class based on valarray of objects with Template class type ...
Slice_iter< T > operator[](size_t i)
slice of column(i)
Cslice_iter< T > operator[](size_t i) const
const slice of column(i)
size_t sizeX() const
return number of columns
void overrideMatrix(size_t x, size_t y, const T &c=T())
resize matrix if necessary, set all elements on value c
Cslice_iter< T > row(size_t i) const
const itterator access to i-te row slice
Cslice_iter< T > operator()(size_t i) const
const slice of first argument (i.e column(i))
T & operator()(size_t x, size_t y)
reference of element x,y
void freeMatrix()
free allocated memory
size_t sizeY() const
return number of rows
void resizeMatrix(size_t x, size_t y, const T &c=T())
resize matrix, set new allocated elements to value c
MatrixTemplate(size_t x, size_t y)
constructor initialising memory block for requested matrix size
Cslice_iter< T > column(size_t i) const
const itterator access to i-te column slice
Slice_iter< T > column(size_t i)
itterator access to i-te column slice
MatrixTemplate< T > & operator=(const MatrixTemplate< T > &)
assignment operator ATTENTION: implies resizing of matrix
size_t size() const
return total number of matrix elements
~MatrixTemplate()
destructor: free allocated memory
T operator()(size_t x, size_t y) const
element x,y
Slice_iter< T > operator()(size_t i)
slice of first argument (i.e column(i))
Slice_iter< T > row(size_t i)
itterator access to i-te row slice
MatrixTemplate(const MatrixTemplate< T > &)
copy constructor
std::valarray< T > & array()
reference to internal valarray
MatrixTemplate< T > & operator*=(T)
multiplication of all matrix elements with element-type multiplicator
Templated support class for class MatrixTemplate to allow fast element access organisation by slicing...
Slice_iter< T > & operator++()
standard itterator incrementation
Slice_iter(std::valarray< T > *vv, std::slice ss)
constructor: initialising slice-itterator for val-array
T & operator[](size_t i)
C style subscript.
Slice_iter< T > end() const
returns itterator positioned on last-plus-one element
T & operator()(size_t i)
Fortran-style subscript.
Slice_iter< T > operator++(int)
standard itterator incrementation
T & operator*()
current element
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm;...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
void ML_UTILS_EXPORT printTemplateError(const char *location, MLErrorCode reason, const std::string_view &handling)
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
T mul(const Cslice_iter< T > &v1, const std::valarray< T > &v2)
implementation of (global) operator functions to assist MatrixTemplate class
std::valarray< T > mul_mv(const MatrixTemplate< T > &m, std::valarray< T > &v)
alternative definition of m*v