66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdlib>
|
|
#include <algorithm>
|
|
#include "Vector.h"
|
|
|
|
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];
|
|
};
|
|
} |