35 XERUS_force_inline void transpose(
double*
const __restrict _out,
const double*
const __restrict _in,
const size_t _leftDim,
const size_t _rightDim) {
36 for(
size_t i = 0; i < _leftDim; ++i) {
37 for(
size_t j = 0; j < _rightDim; ++j) {
38 _out[j*_leftDim+i] = _in[i*_rightDim+j];
44 std::unique_ptr<double[]> AT(
new double[_leftDim*_rightDim]);
45 transpose(AT.get(), _A, _leftDim, _rightDim);
50 XERUS_force_inline void transpose(std::map<size_t, double>& __restrict _out,
const std::map<size_t, double>& __restrict _in,
const size_t _leftDim,
const size_t _rightDim) {
51 for(
const auto& entry : _in) {
52 const size_t i = entry.first/_rightDim;
53 const size_t j = entry.first%_rightDim;
54 _out.emplace(j*_leftDim + i, entry.second);
59 std::map<size_t, double> AT;
67 const size_t _leftDim,
68 const size_t _rightDim,
70 const std::map<size_t, double>& _A,
71 const bool _transposeA,
73 const double*
const _B) {
81 for(
const auto& entry : _A) {
82 const size_t i = entry.first/_midDim;
83 const size_t j = entry.first%_midDim;
84 misc::add_scaled(_C+i*_rightDim, _alpha*entry.second, _B+j*_rightDim, _rightDim);
87 for(
const auto& entry : _A) {
88 const size_t i = entry.first%_leftDim;
89 const size_t j = entry.first/_leftDim;
90 misc::add_scaled(_C+i*_rightDim, _alpha*entry.second, _B+j*_rightDim, _rightDim);
98 const size_t _leftDim,
99 const size_t _rightDim,
101 const std::map<size_t, double>& _A,
102 const bool _transposeA,
103 const size_t _midDim,
104 const double*
const _B,
105 const bool _transposeB) {
107 const std::unique_ptr<double[]> BT =
transpose(_B, _rightDim, _midDim);
115 const size_t _leftDim,
116 const size_t _rightDim,
118 const double*
const _A,
119 const bool _transposeA,
120 const size_t _midDim,
121 const std::map<size_t, double>& _B,
122 const bool _transposeB) {
124 const std::unique_ptr<double[]> CT(
new double[_leftDim*_rightDim]);
125 matrix_matrix_product(CT.get(), _rightDim, _leftDim, _alpha, _B, !_transposeB, _midDim, _A, !_transposeA);
126 transpose(_C, CT.get(), _rightDim, _leftDim);
134 const size_t _rightDim,
136 const std::map<size_t, double>& _A,
137 const size_t _midDim,
138 const double*
const _B) {
141 size_t currentRow = 0;
142 std::unique_ptr<double[]> row(
new double[_rightDim]);
145 for(
const auto& entry : _A) {
146 const size_t i = entry.first/_midDim;
147 const size_t j = entry.first%_midDim;
149 if(i == currentRow) {
150 misc::add_scaled(row.get(), _alpha*entry.second, _B+j*_rightDim, _rightDim);
155 for(
size_t k = 0; k < _rightDim; ++k) {
156 #pragma GCC diagnostic push 157 #pragma GCC diagnostic ignored "-Wfloat-equal" 158 if(row.get()[k] != 0) {
159 _C.emplace(currentRow*_rightDim + k, row.get()[k]);
161 #pragma GCC diagnostic pop 171 for(
size_t k = 0; k < _rightDim; ++k) {
172 #pragma GCC diagnostic push 173 #pragma GCC diagnostic ignored "-Wfloat-equal" 174 if(row.get()[k] != 0) {
175 _C.emplace(currentRow*_rightDim + k, row.get()[k]);
177 #pragma GCC diagnostic pop 184 const size_t _leftDim,
185 const size_t _rightDim,
187 const std::map<size_t, double>& _A,
188 const bool _transposeA,
189 const size_t _midDim,
190 const double*
const _B,
191 const bool _transposeB) {
193 const std::map<size_t, double> AT =
transpose(_A, _midDim, _leftDim);
195 std::unique_ptr<double[]> BT =
transpose(_B, _rightDim, _midDim);
202 std::unique_ptr<double[]> BT =
transpose(_B, _rightDim, _midDim);
211 const size_t _leftDim,
212 const size_t _rightDim,
214 const double*
const _A,
215 const bool _transposeA,
216 const size_t _midDim,
217 const std::map<size_t, double>& _B,
218 const bool _transposeB) {
220 std::map<size_t, double> CT;
Header file for CHECK and REQUIRE macros.
The main namespace of xerus.
void copy_scaled(T *const __restrict _x, const T _alpha, const T *const _y, const size_t _n) noexcept
Copys _n entries from _y to _x, simulationously scaling each entry by the factor _alpha. I.e x = alpha*y.
Header file for the low level array support function.
Header file for comfort functions and macros that should not be exported in the library.
Header file for sparse matrix times dense matrix wrapper functions.
Header file for some elementary string manipulation routines.
static XERUS_force_inline std::string to_string(const bool obj)
void set_zero(T *const __restrict _x, const size_t _n) noexcept
Sets all entries equal to zero.
void add_scaled(T *const __restrict _x, const T _alpha, const T *const __restrict _y, const size_t _n) noexcept
Adds _n entries of _y, scaled by _alpha to the ones of _x. I.e. x += alpha*y.
XERUS_force_inline void transpose(double *const __restrict _out, const double *const __restrict _in, const size_t _leftDim, const size_t _rightDim)
#define XERUS_force_inline
Collection of attributes to force gcc to inline a specific function.
void matrix_matrix_product(double *const _C, const size_t _leftDim, const size_t _rightDim, const double _alpha, const std::map< size_t, double > &_A, const bool _transposeA, const size_t _midDim, const double *const _B, const bool _transposeB)