Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TMVA] Add operations needed for performing optimizer updates:
* Implement ConstAdd, ConstMult, ReciprocalElementWise, SquareElementWise, SqrtElementWise in CPU and Reference architectures. * Add Unit Tests for them in CPU architecture. * Add ROOT Style docs and clang format the code.
- Loading branch information
1 parent
15ed1fb
commit dc6f823
Showing
8 changed files
with
472 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tmva/tmva/src/DNN/Architectures/Reference/Arithmetic.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// @(#)root/tmva/tmva/dnn:$Id$ | ||
// Author: Ravi Kiran S | ||
|
||
/************************************************************************* | ||
* Copyright (C) 2018, Ravi Kiran S * | ||
* All rights reserved. * | ||
* * | ||
* For the licensing terms see $ROOTSYS/LICENSE. * | ||
* For the list of contributors see $ROOTSYS/README/CREDITS. * | ||
*************************************************************************/ | ||
|
||
////////////////////////////////////////////////////////////////// | ||
// Implementation of the Helper arithmetic functions for the // | ||
// reference implementation. // | ||
////////////////////////////////////////////////////////////////// | ||
|
||
#include "TMVA/DNN/Architectures/Reference.h" | ||
#include <math.h> | ||
|
||
namespace TMVA { | ||
namespace DNN { | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::SumColumns(TMatrixT<AReal> &B, const TMatrixT<AReal> &A) | ||
{ | ||
B = 0.0; | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
B(0, j) += A(i, j); | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::Hadamard(TMatrixT<AReal> &A, const TMatrixT<AReal> &B) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) *= B(i, j); | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::ConstAdd(TMatrixT<AReal> &A, AReal beta) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) += beta; | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::ConstMult(TMatrixT<AReal> &A, AReal beta) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) *= beta; | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::ReciprocalElementWise(TMatrixT<AReal> &A) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) = 1.0 / A(i, j); | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::SquareElementWise(TMatrixT<AReal> &A) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) *= A(i, j); | ||
} | ||
} | ||
} | ||
|
||
//______________________________________________________________________________ | ||
template <typename AReal> | ||
void TReference<AReal>::SqrtElementWise(TMatrixT<AReal> &A) | ||
{ | ||
for (Int_t i = 0; i < A.GetNrows(); i++) { | ||
for (Int_t j = 0; j < A.GetNcols(); j++) { | ||
A(i, j) = sqrt(A(i, j)); | ||
} | ||
} | ||
} | ||
|
||
} // namespace DNN | ||
} // namespace TMVA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.