10template<dim_t R, dim_t C,
typename T>
11inline mat<C, R, T>
transpose(
const mat<R, C, T>& m);
13template<dim_t N,
typename T>
14inline mat<N, N, T>
inverse(
const mat<N, N, T>& m);
16template<dim_t R, dim_t C,
typename T>
46 explicit mat(U scalar) {
52 template<
typename ... Us,
typename std::enable_if<
sizeof...(Us) == R * C>::type* =
nullptr>
54 T tmp[
sizeof...(Us)] = {
static_cast<T
>(scalars)...};
57 value = tmp[ri *
columns() + ci];
74 template<
typename ... Us,
typename std::enable_if<
sizeof...(Us) == R>::type* =
nullptr>
78 template<
typename ... Us,
typename std::enable_if<
sizeof...(Us) == R>::type * =
nullptr>
83 template<
typename ... Us,
typename std::enable_if<
sizeof...(Us) == C>::type* =
nullptr>
85 mat<
sizeof...(vs), R, T> tmp{vs ...};
89 template<
typename U,
typename ...,
dim_t H = R,
dim_t W = C>
90 static typename std::enable_if<H == W, mat>::type
diagonal(U scalar) {
98 template<
typename U,
typename ...,
dim_t H = R,
dim_t W = C>
102 row[ri] = scalars[ri];
107 template<
typename ... Us,
dim_t H = R,
dim_t W = C>
108 static typename std::enable_if<(H == W) && (
sizeof...(Us) == H),
mat>::type
diagonal(Us... scalars) {
112 template<
typename ...,
dim_t H = R,
dim_t W = C>
113 static typename std::enable_if<H == W, mat>::type
identity() {
119 assert(index <
rows());
126 assert(index <
rows());
182 return operator+=<T>(rhs);
200 return operator-=<T>(rhs);
212 return (*
this = *
this * rhs);
216 return operator*=<T>(rhs);
232 return operator/=<T>(rhs);
235 template<
typename ...,
dim_t H = R,
dim_t W = C>
236 typename std::enable_if<H == W, mat&>::type
transpose() {
254 col[ri] =
row[index];
259 template<dim_t H, dim_t W>
260 typename std::enable_if<(H > 1 && W > 1 && H <= R && W <= C), mat<H, W, T> >::type
submat(
dim_t y,
dim_t x)
const {
261 assert(H + y <=
rows());
266 value =
values[y + ri][x + ci];
274template<dim_t R, dim_t C,
typename T>
278 lhs.
apply([&rhs, &retval](
const row_type& row,
dim_t ri) {
279 retval = retval && (row == rhs[ri]);
284template<dim_t R, dim_t C,
typename T>
286 return !(lhs == rhs);
289template<dim_t R, dim_t C,
typename T>
294template<dim_t R, dim_t C,
typename T>
301template<dim_t R, dim_t C,
typename T>
306template<dim_t R, dim_t C,
typename T>
311template<dim_t R, dim_t C,
typename T>
316template<dim_t R, dim_t C,
typename T>
321template<dim_t R, dim_t C,
typename T>
326template<dim_t R, dim_t C,
typename T>
331template<dim_t R, dim_t C,
typename T>
336template<dim_t R, dim_t C,
typename T>
341template<dim_t R, dim_t C,
typename T>
345 rhs.
apply([&ret, &lhs](
const row_type& row,
dim_t ri) {
346 ret += (row * row_type{lhs[ri]});
351template<dim_t R, dim_t C,
typename T>
354 using value_type =
typename column_type::value_type;
356 rhs.
apply([&ret, &lhs](value_type value,
dim_t ci) {
357 ret += (lhs.
column(ci) * column_type{value});
362template<dim_t R, dim_t S, dim_t C,
typename T>
366 ret.
apply([&lhs, &rhs](row_type& row,
dim_t ri) {
367 row = (lhs[ri] * rhs);
372template<dim_t R, dim_t C,
typename T>
377template<dim_t R, dim_t C,
typename T>
387template<dim_t R, dim_t C,
typename T>
392template<dim_t R, dim_t C,
typename T>
397template<dim_t R, dim_t C,
typename T>
Definition: Computations.h:19
std::size_t dim_t
Definition: Types.h:22
bool operator!=(const mat< R, C, T > &lhs, const mat< R, C, T > &rhs)
Definition: Mat.h:285
bool operator==(const mat< R, C, T > &lhs, const mat< R, C, T > &rhs)
Definition: Mat.h:275
mat< R, C, T > operator*(const mat< R, C, T > &lhs, T rhs)
Definition: Mat.h:332
mat< R, C, T > operator/(const mat< R, C, T > &lhs, T rhs)
Definition: Mat.h:373
mat< R, C, T > operator-(const mat< R, C, T > &m)
Definition: Mat.h:295
mat< C, R, T > transpose(const mat< R, C, T > &m)
Definition: Computations.h:57
mat< R, C, T > operator+(const mat< R, C, T > &m)
Definition: Mat.h:290
mat< N, N, T > inverse(const mat< N, N, T > &m)
Definition: Computations.h:134
std::enable_if< H==W, mat & >::type transpose()
Definition: Mat.h:236
static constexpr dim_t columns()
Definition: Mat.h:26
mat & operator/=(const mat< R, C, U > &rhs)
Definition: Mat.h:227
const mat & apply(F func) const
Definition: Mat.h:148
mat & operator/=(U rhs)
Definition: Mat.h:220
row_type values[R]
Definition: Mat.h:31
static std::enable_if< H==W, mat >::type identity()
Definition: Mat.h:113
mat & operator*=(const mat< R, C, U > &rhs)
Definition: Mat.h:211
row_type & operator[](dim_t index)
Definition: Mat.h:117
mat & operator-=(const mat &rhs)
Definition: Mat.h:199
mat & operator-=(U rhs)
Definition: Mat.h:186
mat & operator+=(const mat &rhs)
Definition: Mat.h:181
T & operator()(dim_t rowIndex, dim_t colIndex)
Definition: Mat.h:131
column_type column(dim_t index) const
Definition: Mat.h:251
mat(const mat< R, C, U > &rhs)
Definition: Mat.h:63
const T & operator()(dim_t rowIndex, dim_t colIndex) const
Definition: Mat.h:135
static std::enable_if< H==W, mat >::type diagonal(U scalar)
Definition: Mat.h:90
row_type row(dim_t index) const
Definition: Mat.h:247
mat & apply(F func)
Definition: Mat.h:140
mat & operator--()
Definition: Mat.h:161
mat & operator=(const mat &)=default
static std::enable_if<(H==W)&&(sizeof...(Us)==H), mat >::type diagonal(Us... scalars)
Definition: Mat.h:108
mat()
Definition: Mat.h:34
mat(const vec< C, Us > &... vs)
Definition: Mat.h:75
mat & operator+=(U rhs)
Definition: Mat.h:168
mat(Us... scalars)
Definition: Mat.h:53
mat & operator*=(const mat &rhs)
Definition: Mat.h:215
mat & operator=(const mat< R, C, U > &rhs)
Definition: Mat.h:70
static mat fromColumns(const vec< R, Us > &... vs)
Definition: Mat.h:84
mat & negate()
Definition: Mat.h:240
mat & operator=(mat &&)=default
const row_type & operator[](dim_t index) const
Definition: Mat.h:124
static std::enable_if< H==W, mat >::type diagonal(const vec< W, U > &scalars)
Definition: Mat.h:99
mat & operator+=(const mat< R, C, U > &rhs)
Definition: Mat.h:175
mat & operator/=(const mat &rhs)
Definition: Mat.h:231
static constexpr dim_t rows()
Definition: Mat.h:22
T value_type
Definition: Mat.h:18
mat(U scalar)
Definition: Mat.h:46
mat & operator-=(const mat< R, C, U > &rhs)
Definition: Mat.h:193
std::enable_if<(H >1 &&W >1 &&H<=R &&W<=C), mat< H, W, T > >::type submat(dim_t y, dim_t x) const
Definition: Mat.h:260
mat & operator++()
Definition: Mat.h:155
static mat fromRows(const vec< C, Us > &... vs)
Definition: Mat.h:79
mat & operator*=(U rhs)
Definition: Mat.h:204
static constexpr dim_t dimensions()
Definition: Vec.h:13
vec & apply(F func)
Definition: Vec.h:68
vec & negate()
Definition: Vec.h:178