-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coot 17: Refactor MakeAlias to make it compatible with bandicoot #3693
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0415de3
Just a prototype for the new function signature
shrit ffb9c5f
Initial refactoring for a set of MakeAlias, not finished yet
shrit e303c5a
Fix SetWeight, and variable name
shrit f9e3eba
Fix the SetWeights function globally
shrit 4af7f48
Fix const and SFINAE signature for all of these functions
shrit 226acf5
Remove memptr from tests
shrit de747c3
Regexp weights1.memptr() to wieghts1
shrit 04a3ed4
Fix the missing parts inside method
shrit 09b3322
Adding some forgetten refactoring around
shrit 7a363cb
Fix the slices MakeAlias, this is compiling on my end, tests are not …
shrit d164b28
Update src/mlpack/core/math/make_alias.hpp
shrit b14a872
Update src/mlpack/core/math/make_alias.hpp
shrit 5e98e3f
Update src/mlpack/core/math/make_alias.hpp
shrit 30c88bc
Use the Output type with SFINAE
shrit 3164cf6
Add tests are passing with no problem
shrit f229e4b
Update src/mlpack/methods/ann/rnn_impl.hpp
shrit 64a3900
Fix the function call
shrit 5960f23
Merge branch 'coot_17' of github.com:shrit/mlpack into coot_17
shrit 0f2bc5c
Update Core with new MakeAlias signature
shrit eef5b68
Fix the comments as requested
shrit 58970a5
Update doc/user/core.md
shrit File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,55 +16,69 @@ | |
namespace mlpack { | ||
|
||
/** | ||
* Reconstruct `m` as an alias around the memory `newMem`, with size `numRows` x | ||
* Reconstruct `v` as an alias around the memory `newMem`, with size `numRows` x | ||
* `numCols`. | ||
*/ | ||
template<typename MatType> | ||
void MakeAlias(MatType& m, | ||
typename MatType::elem_type* newMem, | ||
const size_t numRows, | ||
const size_t numCols, | ||
template<typename InVecType, typename OutVecType> | ||
void MakeAlias(OutVecType& v, | ||
const InVecType& oldVec, | ||
const size_t numElems, | ||
const size_t offset = 0, | ||
const bool strict = true, | ||
const typename std::enable_if_t<!IsCube<MatType>::value>* = 0) | ||
const typename std::enable_if_t<IsVector<OutVecType>::value>* = 0) | ||
{ | ||
// We use placement new to reinitialize the object, since the copy and move | ||
// assignment operators in Armadillo will end up copying memory instead of | ||
// making an alias. | ||
m.~MatType(); | ||
new (&m) MatType(newMem, numRows, numCols, false, strict); | ||
typename InVecType::elem_type* newMem = | ||
const_cast<typename InVecType::elem_type*>(oldVec.memptr()) + offset; | ||
v.~OutVecType(); | ||
new (&v) OutVecType(newMem, numElems, false, strict); | ||
} | ||
|
||
/** | ||
* Reconstruct `c` as an alias around the memory` newMem`, with size `numRows` x | ||
* `numCols` x `numSlices`. | ||
* Reconstruct `m` as an alias around the memory `newMem`, with size `numRows` x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch :) |
||
* `numCols`. | ||
*/ | ||
template<typename CubeType> | ||
void MakeAlias(CubeType& c, | ||
typename CubeType::elem_type* newMem, | ||
template<typename InMatType, typename OutMatType> | ||
void MakeAlias(OutMatType& m, | ||
const InMatType& oldMat, | ||
const size_t numRows, | ||
const size_t numCols, | ||
const size_t numSlices, | ||
const size_t offset = 0, | ||
const bool strict = true, | ||
const typename std::enable_if_t<IsCube<CubeType>::value>* = 0) | ||
const typename std::enable_if_t<IsMatrix<OutMatType>::value>* = 0) | ||
{ | ||
// We use placement new to reinitialize the object, since the copy and move | ||
// assignment operators in Armadillo will end up copying memory instead of | ||
// making an alias. | ||
c.~CubeType(); | ||
new (&c) CubeType(newMem, numRows, numCols, numSlices, false, strict); | ||
typename InMatType::elem_type* newMem = | ||
const_cast<typename InMatType::elem_type*>(oldMat.memptr()) + offset; | ||
m.~OutMatType(); | ||
new (&m) OutMatType(newMem, numRows, numCols, false, strict); | ||
} | ||
|
||
/** | ||
* Make `m` an alias of `in`, using the given size. | ||
* Reconstruct `c` as an alias around the memory` newMem`, with size `numRows` x | ||
* `numCols` x `numSlices`. | ||
*/ | ||
template<typename eT> | ||
void MakeAlias(arma::Mat<eT>& m, | ||
const arma::Mat<eT>& in, | ||
template<typename InCubeType, typename OutCubeType> | ||
void MakeAlias(OutCubeType& c, | ||
const InCubeType& oldCube, | ||
const size_t numRows, | ||
const size_t numCols, | ||
const bool strict = true) | ||
const size_t numSlices, | ||
const size_t offset = 0, | ||
const bool strict = true, | ||
const typename std::enable_if_t<IsCube<OutCubeType>::value>* = 0) | ||
{ | ||
MakeAlias(m, (eT*) in.memptr(), numRows, numCols, strict); | ||
// We use placement new to reinitialize the object, since the copy and move | ||
// assignment operators in Armadillo will end up copying memory instead of | ||
// making an alias. | ||
typename InCubeType::elem_type* newMem = | ||
const_cast<typename InCubeType::elem_type*>(oldCube.memptr()) + offset; | ||
c.~OutCubeType(); | ||
new (&c) OutCubeType(newMem, numRows, numCols, numSlices, false, strict); | ||
} | ||
|
||
/** | ||
|
@@ -75,6 +89,7 @@ void MakeAlias(arma::SpMat<eT>& m, | |
const arma::SpMat<eT>& in, | ||
const size_t /* numRows */, | ||
const size_t /* numCols */, | ||
const size_t /* offset */, | ||
const bool /* strict */) | ||
{ | ||
// We can't make aliases of sparse objects, so just copy it. | ||
|
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document the version for vectors too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done