OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
Matrix.hpp
Go to the documentation of this file.
1#pragma once
2#include "Matrix.h"
3#include <exception>
4
5template<class T>
6inline Matrix<T>::Matrix(int64_t rows, int64_t columns, accessOptimizationDirection direction) : _rows(rows), _columns(columns)
7{
8 if (_rows == 0 || _columns == 0)
9 {
10 throw std::runtime_error("A matrix creation requires the number of rows and columns to be larger than zero.");
11 }
12 _numberOfEntries = _rows * _columns;
13 _matrix = static_cast<T*>(_aligned_malloc(_numberOfEntries * sizeof(T),_defaultAlignment));
15 {
16 _rowStepWidth = _columns;
17 _columnStepWidth = 1;
18 }
19 else
20 {
21 _rowStepWidth = 1;
22 _columnStepWidth = _rows;
23 }
24}
25
26template<class T>
28{
29 _aligned_free(_matrix);
30 _matrix = nullptr;
31}
32
33template<class T>
34inline T Matrix<T>::GetValue(int64_t row, int64_t column) const
35{
36 int64_t index = row * _rowStepWidth + column * _columnStepWidth;
37 return _matrix[index];
38}
39
40template<class T>
41inline void Matrix<T>::SetValue(int64_t row, int64_t column, T& value)
42{
43 int64_t index = row * _rowStepWidth + column * _columnStepWidth;
44 _matrix[index] = value;
45}
46
47template<class T>
49{
50 return _rows;
51}
52
53template<class T>
55{
56 return _columns;
57}
bsoncxx::types::value value
Definition DocumentManager.h:16
Access optimized dense matrix handle.
void SetValue(int64_t row, int64_t column, T &value)
Definition Matrix.hpp:41
T GetValue(int64_t row, int64_t column) const
Definition Matrix.hpp:34
int64_t GetNumberOfRows()
Definition Matrix.hpp:48
Matrix(int64_t rows, int64_t columns, accessOptimizationDirection direction=accessOptimizationDirection::columnWiseAccess)
Definition Matrix.hpp:6
accessOptimizationDirection
Definition Matrix.h:15
@ columnWiseAccess
Definition Matrix.h:15
int64_t GetNumberOfColumns()
Definition Matrix.hpp:54
~Matrix()
Definition Matrix.hpp:27