7#ifndef LIMBO_SOLVERS_NUMERICAL_H
8#define LIMBO_SOLVERS_NUMERICAL_H
30inline void mklaxpy(
unsigned int n, T a, T
const* x, T* y);
37inline void mklaxpy<float>(
unsigned int n,
float a,
float const* x,
float* y)
39 cblas_saxpy(n, a, x, 1, y, 1);
47inline void mklaxpy<double>(
unsigned int n,
double a,
double const* x,
double* y)
49 cblas_daxpy(n, a, x, 1, y, 1);
60template <
typename T,
typename MatrixType>
61inline void mklAxPlusy(T a, MatrixType
const& A, T
const* x, T b, T* y);
69inline void mklAxPlusy<float, MatrixCSR<float, int, 1> >(
float a,
MatrixCSR<float, int, 1> const& A,
float const* x,
float b,
float* y)
71 mkl_scsrmv(
"N", &A.numRows, &A.numColumns, &a,
"G", A.vElement, A.vColumn, A.vRowBeginIndex, A.vRowBeginIndex+1, x, &b, y);
80inline void mklAxPlusy<double, MatrixCSR<double, int, 1> >(
double a,
MatrixCSR<double, int, 1> const& A,
double const* x,
double b,
double* y)
82 mkl_dcsrmv(
"N", &A.numRows, &A.numColumns, &a,
"G", A.vElement, A.vColumn, A.vRowBeginIndex, A.vRowBeginIndex+1, x, &b, y);
93template <
typename T,
typename MatrixType>
94inline void mklATxPlusy(T a, MatrixType
const& A, T
const* x, T b, T* y);
101inline void mklATxPlusy<float, MatrixCSR<float, int, 1> >(
float a,
MatrixCSR<float, int, 1> const& A,
float const* x,
float b,
float* y)
103 mkl_scsrmv(
"T", &A.numRows, &A.numColumns, &a,
"G", A.vElement, A.vColumn, A.vRowBeginIndex, A.vRowBeginIndex+1, x, &b, y);
111inline void mklATxPlusy<double, MatrixCSR<double, int, 1> >(
double a,
MatrixCSR<double, int, 1> const& A,
double const* x,
double b,
double* y)
113 mkl_dcsrmv(
"T", &A.numRows, &A.numColumns, &a,
"G", A.vElement, A.vColumn, A.vRowBeginIndex, A.vRowBeginIndex+1, x, &b, y);
122inline T mkldot(
unsigned int n, T
const* x, T
const* y);
129inline float mkldot(
unsigned int n,
float const* x,
float const* y)
131 return cblas_sdot(n, x, 1, y, 1);
139inline double mkldot(
unsigned int n,
double const* x,
double const* y)
141 return cblas_ddot(n, x, 1, y, 1);
150inline void mklcopy(
unsigned int n, T
const* x, T* y);
156inline void mklcopy(
unsigned int n,
float const* x,
float* y)
158 cblas_scopy(n, x, 1, y, 1);
165inline void mklcopy(
unsigned int n,
double const* x,
double* y)
167 cblas_dcopy(n, x, 1, y, 1);
178template <
typename T,
typename V>
179inline void axpy(
unsigned int n, T a, V
const* x, T* y)
184 for (
unsigned int i = 0; i < n; ++i)
197template <
typename T,
typename V,
typename MatrixType>
198inline void AxPlusy(T a, MatrixType
const& A, V
const* x, T* y)
202 mklAxPlusy(a, A, x, (T)1, y);
204 for (
typename MatrixType::index_type i = 0; i < A.numRows; ++i)
206 for (
typename MatrixType::index_type k = A.vRowBeginIndex[i]; k < A.vRowBeginIndex[i+1]; ++k)
208 typename MatrixType::index_type kk = k-MatrixType::s_startingIndex;
209#ifdef DEBUG_NUMERICAL
210 limboAssert(A.vColumn[kk]-MatrixType::s_startingIndex < A.numColumns && kk < A.numElements);
212 y[i] += a*A.vElement[kk]*x[A.vColumn[kk]-MatrixType::s_startingIndex];
225template <
typename T,
typename V,
typename MatrixType>
226inline void ATxPlusy(T a, MatrixType
const& A, V
const* x, T* y)
230 mklATxPlusy(a, A, x, (T)1, y);
232 for (
typename MatrixType::index_type i = 0; i < A.numRows; ++i)
234 for (
typename MatrixType::index_type k = A.vRowBeginIndex[i]; k < A.vRowBeginIndex[i+1]; ++k)
236 typename MatrixType::index_type kk = k-MatrixType::s_startingIndex;
237#ifdef DEBUG_NUMERICAL
238 limboAssert(A.vColumn[kk]-MatrixType::s_startingIndex < A.numColumns && kk < A.numElements);
240 y[A.vColumn[kk]-MatrixType::s_startingIndex] += a*A.vElement[kk]*x[i];
252inline T
dot(
unsigned int n, T
const* x, T
const* y)
256 result = mkldot(n, x, y);
258 for (
unsigned int i = 0; i < n; ++i)
269inline void vcopy(
unsigned int n, T
const* x, T* y)
275 std::copy(x, x+n, y);
#define limboAssert(condition)
custom assertion without message
Basic utilities such as variables and linear expressions in solvers.
namespace for Limbo.Solvers
void vcopy(unsigned int n, T const *x, T *y)
copy vector
void axpy(unsigned int n, T a, V const *x, T *y)
void AxPlusy(T a, MatrixType const &A, V const *x, T *y)
T dot(unsigned int n, T const *x, T const *y)
compute dot product
void ATxPlusy(T a, MatrixType const &A, V const *x, T *y)
Compressed sparse row (CSR) matrix.