Commit 84988350 authored by David Frank's avatar David Frank
Browse files

Prefer bass by const reference to avoid unnecessary copies

parent a849243a
...@@ -125,7 +125,7 @@ namespace elsa ...@@ -125,7 +125,7 @@ namespace elsa
} }
template <typename data_t> template <typename data_t>
data_t DataContainer<data_t>::at(IndexVector_t coordinate) const data_t DataContainer<data_t>::at(const IndexVector_t& coordinate) const
{ {
const auto arr = coordinate.array(); const auto arr = coordinate.array();
if ((arr < 0).any() if ((arr < 0).any()
...@@ -133,22 +133,22 @@ namespace elsa ...@@ -133,22 +133,22 @@ namespace elsa
return 0; return 0;
} }
return (*this)[_dataDescriptor->getIndexFromCoordinate(std::move(coordinate))]; return (*this)[_dataDescriptor->getIndexFromCoordinate(coordinate)];
} }
template <typename data_t> template <typename data_t>
data_t& DataContainer<data_t>::operator()(IndexVector_t coordinate) data_t& DataContainer<data_t>::operator()(const IndexVector_t& coordinate)
{ {
// const auto arr = coordinate.array(); // const auto arr = coordinate.array();
// const auto shape = _dataDescriptor->getNumberOfCoefficientsPerDimension().array(); // const auto shape = _dataDescriptor->getNumberOfCoefficientsPerDimension().array();
// ELSA_VERIFY((arr >= 0).all()); // ELSA_VERIFY((arr >= 0).all());
// ELSA_VERIFY((arr < shape).all()); // ELSA_VERIFY((arr < shape).all());
return (*this)[_dataDescriptor->getIndexFromCoordinate(std::move(coordinate))]; return (*this)[_dataDescriptor->getIndexFromCoordinate(coordinate)];
} }
template <typename data_t> template <typename data_t>
const data_t& DataContainer<data_t>::operator()(IndexVector_t coordinate) const const data_t& DataContainer<data_t>::operator()(const IndexVector_t& coordinate) const
{ {
// const auto arr = coordinate.array(); // const auto arr = coordinate.array();
// const auto shape = _dataDescriptor->getNumberOfCoefficientsPerDimension().array(); // const auto shape = _dataDescriptor->getNumberOfCoefficientsPerDimension().array();
......
...@@ -172,12 +172,12 @@ namespace elsa ...@@ -172,12 +172,12 @@ namespace elsa
const data_t& operator[](index_t index) const; const data_t& operator[](index_t index) const;
/// return an element by n-dimensional coordinate (not bounds-checked!) /// return an element by n-dimensional coordinate (not bounds-checked!)
data_t& operator()(IndexVector_t coordinate); data_t& operator()(const IndexVector_t& coordinate);
/// return an element by n-dimensional coordinate as read-only (not bounds-checked!) /// return an element by n-dimensional coordinate as read-only (not bounds-checked!)
const data_t& operator()(IndexVector_t coordinate) const; const data_t& operator()(const IndexVector_t& coordinate) const;
data_t at(IndexVector_t coordinate) const; data_t at(const IndexVector_t& coordinate) const;
/// return an element by its coordinates (not bounds-checked!) /// return an element by its coordinates (not bounds-checked!)
template <typename idx0_t, typename... idx_t, template <typename idx0_t, typename... idx_t,
......
...@@ -74,7 +74,7 @@ namespace elsa ...@@ -74,7 +74,7 @@ namespace elsa
RealVector_t DataDescriptor::getLocationOfOrigin() const { return _locationOfOrigin; } RealVector_t DataDescriptor::getLocationOfOrigin() const { return _locationOfOrigin; }
index_t DataDescriptor::getIndexFromCoordinate(elsa::IndexVector_t coordinate) const index_t DataDescriptor::getIndexFromCoordinate(const elsa::IndexVector_t& coordinate) const
{ {
// sanity check // sanity check
if (coordinate.size() != _productOfCoefficientsPerDimension.size()) if (coordinate.size() != _productOfCoefficientsPerDimension.size())
......
...@@ -79,7 +79,7 @@ namespace elsa ...@@ -79,7 +79,7 @@ namespace elsa
* _numberOfCoefficientsPerDimension[i]-1 for every dimension i = 0,...,_numberOfDimensions. * _numberOfCoefficientsPerDimension[i]-1 for every dimension i = 0,...,_numberOfDimensions.
* Linearization is assumed to be done in order of the dimensions. * Linearization is assumed to be done in order of the dimensions.
*/ */
index_t getIndexFromCoordinate(IndexVector_t coordinate) const; index_t getIndexFromCoordinate(const elsa::IndexVector_t& coordinate) const;
/** /**
* @brief computes the local coordinates from a linearized index * @brief computes the local coordinates from a linearized index
...@@ -88,8 +88,9 @@ namespace elsa ...@@ -88,8 +88,9 @@ namespace elsa
* @return the local coordinate corresponding to the index * @return the local coordinate corresponding to the index
* *
* The local coordinates are integers, running from 0 to * The local coordinates are integers, running from 0 to
* _numberOfCoefficientsPerDimension[i]-1 for every dimension i = 0,...,_numberOfDimensions. * _numberOfCoefficientsPerDimension[i]-1 for every dimension i =
* Linearization is assumed to be done in order of the dimensions. * 0,...,_numberOfDimensions. Linearization is assumed to be done in order of the
* dimensions.
*/ */
IndexVector_t getCoordinateFromIndex(index_t index) const; IndexVector_t getCoordinateFromIndex(index_t index) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment