27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wshadow"
32#pragma GCC diagnostic pop
41template<
typename AReal>
46 int m = (
int)
A.GetNrows();
47 int k = (
int)
A.GetNcols();
48 int n = (
int)
B.GetNcols();
62 const AReal * APointer =
A.GetRawDataPointer();
63 const AReal * BPointer =
B.GetRawDataPointer();
64 AReal * CPointer =
C.GetRawDataPointer();
67 APointer, &
m, BPointer, &k, &
beta, CPointer, &
m);
76template<
typename AReal>
80 AReal alpha, AReal
beta)
83 int m = (
int)
A.GetNcols();
84 int k = (
int)
A.GetNrows();
85 int n = (
int)
B.GetNcols();
97 const AReal *APointer =
A.GetRawDataPointer();
98 const AReal *BPointer =
B.GetRawDataPointer();
99 AReal *CPointer =
C.GetRawDataPointer();
102 APointer, &k, BPointer, &k, &
beta, CPointer, &
m);
109 tmp = tmp +
beta * tmp0;
116template<
typename AReal>
120 const AReal *dataA =
A.GetRawDataPointer();
121 AReal *dataB =
B.GetRawDataPointer();
123 size_t nElements =
A.GetNoElements();
129 for (
size_t j = 0; j < nSteps; ++j) {
130 size_t idx = workerID+j;
131 if (idx >= nElements)
break;
132 dataB[idx] *= dataA[idx];
137 if (nSteps < nElements) {
139 B.GetThreadExecutor().Foreach(
f,
ROOT::TSeqI(0,nElements,nSteps));
141 for (
size_t i = 0; i < nElements ; i+= nSteps)
151template<
typename AReal>
155 const AReal *dataA =
A.GetRawDataPointer();
156 AReal *dataB =
B.GetRawDataPointer();
158 size_t nElements =
A.GetNoElements();
164 for (
size_t j = 0; j < nSteps; ++j) {
165 size_t idx = workerID+j;
166 if (idx >= nElements)
break;
167 dataB[idx] *= dataA[idx];
172 if (nSteps < nElements) {
176 for (
size_t i = 0; i < nElements ; i+= nSteps)
193template<
typename AReal>
196 if (
A.GetNrows() !=
B.GetNrows() ||
A.GetNcols() !=
B.GetNcols()) {
197 Fatal(
"AlmostEquals",
"The passed matrices have unequal shapes.");
200 const AReal *dataA =
A.GetRawDataPointer();
201 const AReal *dataB =
B.GetRawDataPointer();
202 size_t nElements =
A.GetNoElements();
204 for(
size_t i = 0; i < nElements; i++) {
205 if(
fabs(dataA[i] - dataB[i]) >
epsilon)
return false;
211template<
typename AReal>
214 AReal alpha, AReal
beta)
217 int m = (
int)
A.GetNrows();
218 int n = (
int)
A.GetNcols();
220 assert((
int)
B.GetNoElements() >=
n);
226 const AReal * APointer =
A.GetRawDataPointer();
227 AReal * BPointer =
B.GetRawDataPointer();
233 &
beta, BPointer, &inc);
239 assert(
B.GetNrows() == 1 ||
B.GetNcols() == 1);
240 tmp = alpha * tA * ones +
beta * tmp;
247template<
typename AReal>
253 int n = (
int) (
A.GetNcols() *
A.GetNrows());
256 const AReal *
x =
A.GetRawDataPointer();
257 AReal *
y =
B.GetRawDataPointer();
268template<
typename AReal>
272 auto f = [](AReal
x) {
return x;};
278template<
typename AReal>
284 for (
size_t i = 0; i <
B.GetFirstSize(); ++i) {
286 ScaleAdd(B_m,
A.At(i).GetMatrix(), alpha);
291template<
typename AReal>
296 auto f = [](AReal
x) {
return x;};
301template <
typename AReal>
309template <
typename AReal>
317template <
typename AReal>
320 auto f = [](AReal
x) {
return 1.0 /
x; };
325template <
typename AReal>
328 auto f = [](AReal
x) {
return x *
x; };
333template <
typename AReal>
336 auto f = [](AReal
x) {
return sqrt(
x); };
342template<
typename AReal>
347 AReal *
a =
A.GetRawDataPointer();
350 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
351 a[index] =
a[index] - alpha *
m[index]/(
sqrt(
v[index]) + eps);
356template<
typename AReal>
361 AReal *
a =
A.GetRawDataPointer();
362 const AReal *
b =
B.GetRawDataPointer();
363 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
368template<
typename AReal>
373 AReal *
a =
A.GetRawDataPointer();
374 const AReal *
b =
B.GetRawDataPointer();
375 for (
size_t index = 0; index <
A.GetNoElements() ; ++index) {
376 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.
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
TMatrixT< Element > & T()
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.
Element * GetMatrixArray()
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