26template<
typename AFloat>
34 std::vector<AFloat> temp(nElements/nSteps + 1);
36 auto f = [&data, &temp, nElements, nSteps](
UInt_t workerID)
38 size_t iMax = std::min(workerID+nSteps, nElements);
39 size_t iWorker = workerID/nSteps;
40 for (
size_t i = workerID; i < iMax; ++i) {
41 temp[iWorker] +=
fabs(data[i]);
45 auto reduction = [](
const std::vector<AFloat> &
v )
47 return std::accumulate(
v.begin(),
v.end(),AFloat{});
59template<
typename AFloat>
65 AFloat *dataB =
B.GetRawDataPointer();
66 const AFloat *dataA =
A.GetRawDataPointer();
68 size_t nElements =
B.GetNoElements();
76 size_t iMax = std::min(workerID+nSteps, nElements);
77 for (
size_t i = workerID; i < iMax; ++i) {
78 AFloat sign = (dataA[i] < 0.0) ? -1.0 : 1.0;
84 if (nSteps < nElements) {
86 B.GetThreadExecutor().Foreach(
f,
ROOT::TSeqI(0,nElements, nSteps));
88 for (
size_t i = 0; i < nElements; i+=nSteps)
97template<
typename AFloat>
105 std::vector<AFloat> temp(nElements/nSteps + 1);
107 auto f = [&data, &temp, nElements, nSteps](
UInt_t workerID)
109 size_t iMax = std::min(workerID+nSteps, nElements);
110 size_t iWorker = workerID/nSteps;
112 for (
size_t i = workerID; i < iMax; ++i) {
113 temp[iWorker] += data[i] * data[i];
117 auto reduction = [](
const std::vector<AFloat> &
v )
119 return std::accumulate(
v.begin(),
v.end(),AFloat{});
131template<
typename AFloat>
137 AFloat *dataB =
B.GetRawDataPointer();
138 const AFloat *dataA =
A.GetRawDataPointer();
140 size_t nElements =
B.GetNoElements();
146 size_t iMax = std::min(workerID+nSteps, nElements);
147 for (
size_t i = workerID; i < iMax; ++i) {
153 if (nSteps < nElements) {
155 B.GetThreadExecutor().Foreach(
f,
ROOT::TSeqI(0,nElements, nSteps));
157 for (
size_t i = 0; i < nElements; i+=nSteps)
A pseudo container class which is a generator of indices.
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
static size_t GetNWorkItems(size_t nelements)
static Executor & GetThreadExecutor()
size_t GetNoElements() const
static Scalar_t L1Regularization(const Matrix_t &W)
static void AddL1RegularizationGradients(Matrix_t &A, const Matrix_t &W, Scalar_t weightDecay)
static Scalar_t L2Regularization(const Matrix_t &W)
static void AddL2RegularizationGradients(Matrix_t &A, const Matrix_t &W, Scalar_t weightDecay)
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
auto Reduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
Wrap Reduce function.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
create variable transformations