openGPMP
Open Source Mathematics Package
Static Public Member Functions | List of all members
gpmp::linalg::mtx< T > Struct Template Reference

Matrix struct. More...

#include <mtx_tmpl.hpp>

Static Public Member Functions

static Matrix< T > zeros (size_t rows, size_t cols)
 Matrix zeros method. More...
 
static Matrix< T > ones (size_t rows, size_t cols)
 
static Matrix< T > randn (size_t rows, size_t cols)
 
static Matrix< T > rand (size_t rows, size_t cols)
 

Detailed Description

template<typename T>
struct gpmp::linalg::mtx< T >

Matrix struct.

Definition at line 408 of file mtx_tmpl.hpp.

Member Function Documentation

◆ ones()

template<typename T >
static Matrix<T> gpmp::linalg::mtx< T >::ones ( size_t  rows,
size_t  cols 
)
inlinestatic

Definition at line 419 of file mtx_tmpl.hpp.

419  {
420  Matrix<T> MTX{rows, cols};
421  MTX.fill_index(T(1));
422  return MTX;
423  }

References test_linalg::cols, and test_linalg::rows.

◆ rand()

template<typename T >
static Matrix<T> gpmp::linalg::mtx< T >::rand ( size_t  rows,
size_t  cols 
)
inlinestatic

Definition at line 441 of file mtx_tmpl.hpp.

441  {
442  Matrix<T> MTX{rows, cols};
443 
444  std::random_device rd{};
445  std::mt19937 gen{rd()};
446  std::uniform_real_distribution<T> d{0, 1};
447 
448  for (size_t r = 0; r < rows; ++r) {
449  for (int64_t c = 0; c < cols; ++c) {
450  MTX(r, c) = d(gen);
451  }
452  }
453  return MTX;
454  }

References test_linalg::cols, and test_linalg::rows.

◆ randn()

template<typename T >
static Matrix<T> gpmp::linalg::mtx< T >::randn ( size_t  rows,
size_t  cols 
)
inlinestatic

Definition at line 425 of file mtx_tmpl.hpp.

425  {
426  Matrix<T> MTX{rows, cols};
427 
428  std::random_device rd{};
429  std::mt19937 gen{rd()};
430  T n(MTX.num_elements);
431  T stdev{1 / sqrt(n)};
432  std::normal_distribution<T> d{0, stdev};
433 
434  for (size_t r = 0; r < rows; ++r) {
435  for (uint64_t c = 0; c < cols; ++c) {
436  MTX(r, c) = d(gen);
437  }
438  }
439  return MTX;
440  }

References test_linalg::cols, and test_linalg::rows.

Referenced by gpmp::ml::SecondaryMLP< T >::SecondaryMLP().

◆ zeros()

template<typename T >
static Matrix<T> gpmp::linalg::mtx< T >::zeros ( size_t  rows,
size_t  cols 
)
inlinestatic

Matrix zeros method.

Definition at line 412 of file mtx_tmpl.hpp.

412  {
413  Matrix<T> MTX{rows, cols};
414  // fill by index
415  MTX.fill_index(T(0));
416  return MTX;
417  }

References test_linalg::cols, and test_linalg::rows.


The documentation for this struct was generated from the following file: