Implement Circle header, rename all files to use .hpp extension.
This commit is contained in:
66
include/J3ML/LinearAlgebra/Matrix.hpp
Normal file
66
include/J3ML/LinearAlgebra/Matrix.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include "Vector.hpp"
|
||||
|
||||
namespace J3ML::LinearAlgebra
|
||||
{
|
||||
|
||||
|
||||
template <uint ROWS, uint COLS, typename T>
|
||||
class Matrix
|
||||
{
|
||||
static constexpr uint Diag = std::min(ROWS, COLS);
|
||||
|
||||
using RowVector = Vector<ROWS, T>;
|
||||
using ColVector = Vector<COLS, T>;
|
||||
using DiagVector = Vector<Diag, T>;
|
||||
|
||||
enum { Rows = ROWS };
|
||||
enum { Cols = COLS };
|
||||
|
||||
void AssertRowSize(uint rows)
|
||||
{
|
||||
assert(rows < Rows && "");
|
||||
}
|
||||
void AssertColumnSize(uint cols)
|
||||
{
|
||||
assert(cols < Cols && "");
|
||||
}
|
||||
|
||||
RowVector GetRow(uint index) const;
|
||||
ColVector GetColumn(uint index) const;
|
||||
void SetRow(uint index, RowVector);
|
||||
void SetColumn(uint index, ColVector);
|
||||
|
||||
RowVector &Row(uint index) const;
|
||||
ColVector &Column(uint index) const;
|
||||
|
||||
const T At(uint row, uint col) const
|
||||
{
|
||||
AssertRowSize(row);
|
||||
AssertColumnSize(col);
|
||||
|
||||
return elems[row][col];
|
||||
}
|
||||
|
||||
T &At(uint row, uint col)
|
||||
{
|
||||
AssertRowSize(row);
|
||||
AssertColumnSize(col);
|
||||
|
||||
return elems[row][col];
|
||||
}
|
||||
|
||||
float* ptr();
|
||||
const float* ptr() const;
|
||||
|
||||
float operator[](uint index) const;
|
||||
float& operator[](uint index);
|
||||
|
||||
private:
|
||||
T elems[ROWS][COLS];
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user