25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wshadow"
30#pragma GCC diagnostic pop
38template<
typename AReal>
43 int m = (int)
A.GetNrows();
44 int k = (int)
A.GetNcols();
45 int n = (int)
B.GetNcols();
59 const AReal * APointer =
A.GetRawDataPointer();
60 const AReal * BPointer =
B.GetRawDataPointer();
61 AReal * CPointer =
C.GetRawDataPointer();
64 APointer, &
m, BPointer, &k, &
beta, CPointer, &
m);
73template<
typename AReal>
77 AReal alpha, AReal
beta)
80 int m = (int)
A.GetNcols();
81 int k = (int)
A.GetNrows();
82 int n = (int)
B.GetNcols();
94 const AReal *APointer =
A.GetRawDataPointer();
95 const AReal *BPointer =
B.GetRawDataPointer();
96 AReal *CPointer =
C.GetRawDataPointer();
99 APointer, &k, BPointer, &k, &
beta, CPointer, &
m);
103 tmp = alpha*tmp +
beta;
109template<
typename AReal>
113 const AReal *dataA =
A.GetRawDataPointer();
114 AReal *dataB =
B.GetRawDataPointer();
116 size_t nElements =
A.GetNoElements();
122 for (
size_t j = 0; j < nSteps; ++j) {
123 size_t idx = workerID+j;
124 if (idx >= nElements)
break;
125 dataB[idx] *= dataA[idx];
130 if (nSteps < nElements) {
132 B.GetThreadExecutor().Foreach(
f,
ROOT::TSeqI(0,nElements,nSteps));
134 for (
size_t i = 0; i < nElements ; i+= nSteps)
144template<
typename AReal>
148 const AReal *dataA =
A.GetRawDataPointer();
149 AReal *dataB =
B.GetRawDataPointer();
151 size_t nElements =
A.GetNoElements();
157 for (
size_t j = 0; j < nSteps; ++j) {
158 size_t idx = workerID+j;
159 if (idx >= nElements)
break;
160 dataB[idx] *= dataA[idx];
165 if (nSteps < nElements) {
169 for (
size_t i = 0; i < nElements ; i+= nSteps)
186template<
typename AReal>
189 if (
A.GetNrows() !=
B.GetNrows() ||
A.GetNcols() !=
B.GetNcols()) {
190 Fatal(
"AlmostEquals",
"The passed matrices have unequal shapes.");
193 const AReal *dataA =
A.GetRawDataPointer();
194 const AReal *dataB =
B.GetRawDataPointer();
195 size_t nElements =
A.GetNoElements();
197 for(
size_t i = 0; i < nElements; i++) {
198 if(
fabs(dataA[i] - dataB[i]) >
epsilon)
return false;
204template<
typename AReal>
207 AReal alpha, AReal
beta)
210 int m = (int)
A.GetNrows();
211 int n = (int)
A.GetNcols();
218 const AReal * APointer =
A.GetRawDataPointer();
219 AReal * BPointer =
B.GetRawDataPointer();
223 &
beta, BPointer, &inc);
227 tmp = alpha*tmp +
beta;
233template<
typename AReal>
239 int n = (int) (
A.GetNcols() *
A.GetNrows());
242 const AReal *
x =
A.GetRawDataPointer();
243 AReal *
y =
B.GetRawDataPointer();
254template<
typename AReal>
258 auto f = [](AReal
x) {
return x;};
264template<
typename AReal>
270 for (
size_t i = 0; i <
B.GetFirstSize(); ++i) {
272 ScaleAdd(B_m,
A.At(i).GetMatrix(), alpha);
277template<
typename AReal>
282 auto f = [](AReal
x) {
return x;};
287template <
typename AReal>
295template <
typename AReal>
303template <
typename AReal>
306 auto f = [](AReal
x) {
return 1.0 /
x; };
311template <
typename AReal>
314 auto f = [](AReal
x) {
return x *
x; };
319template <
typename AReal>
322 auto f = [](AReal
x) {
return sqrt(
x); };
328template<
typename AReal>
333 AReal *
a =
A.GetRawDataPointer();
336 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
337 a[index] =
a[index] - alpha *
m[index]/(
sqrt(
v[index]) + eps);
342template<
typename AReal>
347 AReal *
a =
A.GetRawDataPointer();
348 const AReal *
b =
B.GetRawDataPointer();
349 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
354template<
typename AReal>
359 AReal *
a =
A.GetRawDataPointer();
360 const AReal *
b =
B.GetRawDataPointer();
361 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
362 a[index] =
beta *
a[index] + (1.-
beta) *
b[index] *
b[index];
void Fatal(const char *location, const char *msgfmt,...)
A pseudo container class which is a generator of indices.
Executor & GetThreadExecutor()
Get executor class for multi-thread usage In case when MT is not enabled will return a serial executo...
static Config & Instance()
static function: returns TMVA instance
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
static size_t GetNWorkItems(size_t nelements)
static void TransposeMultiply(Matrix_t &output, const Matrix_t &input, const Matrix_t &Weights, Scalar_t alpha=1.0, Scalar_t beta=0.)
Matrix multiplication of two matrices A and B^T (transposed) with the result being written into C.
static void ScaleAdd(Matrix_t &A, const Matrix_t &B, Scalar_t beta=1.0)
Adds a the elements in matrix B scaled by c to the elements in the matrix A.
static void ConstAdd(Matrix_t &A, Scalar_t beta)
Add the constant beta to all the elements of matrix A and write the result into A.
static void SumColumns(Matrix_t &B, const Matrix_t &A, Scalar_t alpha=1.0, Scalar_t beta=0.)
Sum columns of (m x n) matrixx A and write the results into the first m elements in A.
static bool AlmostEquals(const Matrix_t &A, const Matrix_t &B, double epsilon=0.1)
Check two matrices for equality, taking floating point arithmetic errors into account.
static void Hadamard(Tensor_t &A, const Tensor_t &B)
In-place Hadamard (element-wise) product of matrices A and B with the result being written into A.
static void SqrtElementWise(Matrix_t &A)
Square root each element of the matrix A and write the result into A.
static void Multiply(Matrix_t &C, const Matrix_t &A, const Matrix_t &B)
Standard multiplication of two matrices A and B with the result being written into C.
static void AdamUpdateSecondMom(Matrix_t &A, const Matrix_t &B, Scalar_t beta)
static void Copy(Matrix_t &B, const Matrix_t &A)
static void SquareElementWise(Matrix_t &A)
Square each element of the matrix A and write the result into A.
static void AdamUpdateFirstMom(Matrix_t &A, const Matrix_t &B, Scalar_t beta)
static void ConstMult(Matrix_t &A, Scalar_t beta)
Multiply the constant beta to all the elements of matrix A and write the result into A.
static void ReciprocalElementWise(Matrix_t &A)
Reciprocal each element of the matrix A and write the result into A.
static void AdamUpdate(Matrix_t &A, const Matrix_t &M, const Matrix_t &V, Scalar_t alpha, Scalar_t eps)
Adam updates.
static void ScaleAdd(TMatrixT< Scalar_t > &A, const TMatrixT< Scalar_t > &B, Scalar_t beta=1.0)
Adds a the elements in matrix B scaled by c to the elements in the matrix A.
static void SumColumns(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
Sum columns of (m x n) matrixx A and write the results into the first m elements in A.
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
void TMult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
Create a matrix C such that C = A' * B.
void Mult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B.
double beta(double x, double y)
Calculates the beta function.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
void Axpy(const int *n, const AReal *alpha, const AReal *x, const int *incx, AReal *y, const int *incy)
Add the vector x scaled by alpha to y scaled by \beta.
void Gemm(const char *transa, const char *transb, const int *m, const int *n, const int *k, const AReal *alpha, const AReal *A, const int *lda, const AReal *B, const int *ldb, const AReal *beta, AReal *C, const int *ldc)
Multiply the matrix A with the matrix B and store the result in C.
void Gemv(const char *trans, const int *m, const int *n, const AReal *alpha, const AReal *A, const int *lda, const AReal *x, const int *incx, const AReal *beta, AReal *y, const int *incy)
Multiply the vector x with the matrix A and store the result in y.
create variable transformations