Commit fdea0ce2 authored by Jens Petit's avatar Jens Petit
Browse files

clang-format on all cpp-files

parent 6412d981
Pipeline #171383 passed with stages
in 27 minutes and 26 seconds
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
namespace elsa namespace elsa
{ {
BlockDescriptor::BlockDescriptor(index_t numberOfBlocks, const DataDescriptor &dataDescriptor) BlockDescriptor::BlockDescriptor(index_t numberOfBlocks, const DataDescriptor& dataDescriptor)
: DataDescriptor(dataDescriptor), : DataDescriptor(dataDescriptor), _blockDescriptors{}, _blockOffsets(numberOfBlocks)
_blockDescriptors{},
_blockOffsets(numberOfBlocks)
{ {
// sanity check // sanity check
if (numberOfBlocks <= 0) if (numberOfBlocks <= 0)
...@@ -23,33 +21,32 @@ namespace elsa ...@@ -23,33 +21,32 @@ namespace elsa
_numberOfDimensions++; _numberOfDimensions++;
_numberOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions); _numberOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions);
_numberOfCoefficientsPerDimension(_numberOfDimensions-1) = numberOfBlocks; _numberOfCoefficientsPerDimension(_numberOfDimensions - 1) = numberOfBlocks;
_spacingPerDimension.conservativeResize(_numberOfDimensions); _spacingPerDimension.conservativeResize(_numberOfDimensions);
_spacingPerDimension(_numberOfDimensions-1) = 1.0; _spacingPerDimension(_numberOfDimensions - 1) = 1.0;
_productOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions); _productOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions);
_productOfCoefficientsPerDimension(_numberOfDimensions-1) = _productOfCoefficientsPerDimension(_numberOfDimensions - 1) =
_numberOfCoefficientsPerDimension.head(_numberOfDimensions-1).prod(); _numberOfCoefficientsPerDimension.head(_numberOfDimensions - 1).prod();
} }
index_t BlockDescriptor::getNumberOfBlocks() const { index_t BlockDescriptor::getNumberOfBlocks() const { return _blockDescriptors.size(); }
return _blockDescriptors.size();
}
const DataDescriptor& BlockDescriptor::getIthDescriptor(index_t i) const { const DataDescriptor& BlockDescriptor::getIthDescriptor(index_t i) const
{
return *_blockDescriptors.at(i); return *_blockDescriptors.at(i);
} }
index_t BlockDescriptor::getIthBlockOffset(elsa::index_t i) const { index_t BlockDescriptor::getIthBlockOffset(elsa::index_t i) const
{
if (i < 0 || i >= _blockOffsets.size()) if (i < 0 || i >= _blockOffsets.size())
throw std::invalid_argument("BlockDescriptor: index i is out of bounds"); throw std::invalid_argument("BlockDescriptor: index i is out of bounds");
return _blockOffsets.coeff(i); return _blockOffsets.coeff(i);
} }
BlockDescriptor::BlockDescriptor(const BlockDescriptor& blockDescriptor)
BlockDescriptor::BlockDescriptor(const BlockDescriptor &blockDescriptor)
: DataDescriptor(blockDescriptor), : DataDescriptor(blockDescriptor),
_blockDescriptors{}, _blockDescriptors{},
_blockOffsets{blockDescriptor._blockOffsets} _blockOffsets{blockDescriptor._blockOffsets}
...@@ -58,10 +55,7 @@ namespace elsa ...@@ -58,10 +55,7 @@ namespace elsa
_blockDescriptors.emplace_back(descriptor->clone()); _blockDescriptors.emplace_back(descriptor->clone());
} }
BlockDescriptor* BlockDescriptor::cloneImpl() const BlockDescriptor* BlockDescriptor::cloneImpl() const { return new BlockDescriptor(*this); }
{
return new BlockDescriptor(*this);
}
bool BlockDescriptor::isEqual(const DataDescriptor& other) const bool BlockDescriptor::isEqual(const DataDescriptor& other) const
{ {
......
#pragma once #pragma once
#include "elsa.h" #include "elsa.h"
#include "Cloneable.h" #include "Cloneable.h"
#include "DataDescriptor.h" #include "DataDescriptor.h"
...@@ -12,17 +11,19 @@ namespace elsa ...@@ -12,17 +11,19 @@ namespace elsa
{ {
/** /**
* \brief Class representing metadata for blocked, linearized n-dimensional signal stored in memory * \brief Class representing metadata for blocked, linearized n-dimensional signal stored in
* memory
* *
* \author Matthias Wieczorek - initial code * \author Matthias Wieczorek - initial code
* \author David Frank - rewrite * \author David Frank - rewrite
* \author Nikola Dinev - various enhancements * \author Nikola Dinev - various enhancements
* \author Tobias Lasser - rewrite, modularization, modernization * \author Tobias Lasser - rewrite, modularization, modernization
* *
* This class provides metadata about a signal that is stored in memory (typically a DataContainer). * This class provides metadata about a signal that is stored in memory (typically a
* This signal can be n-dimensional, and will be stored in memory in a linearized fashion in blocks. * DataContainer). This signal can be n-dimensional, and will be stored in memory in a
* The blocks can be used to support various operations (like blocked operators or ordered subsets), * linearized fashion in blocks. The blocks can be used to support various operations (like
* however, the blocks have to lie in memory one after the other (i.e. no stride is supported). * blocked operators or ordered subsets), however, the blocks have to lie in memory one after
* the other (i.e. no stride is supported).
*/ */
class BlockDescriptor : public DataDescriptor class BlockDescriptor : public DataDescriptor
{ {
...@@ -34,16 +35,17 @@ namespace elsa ...@@ -34,16 +35,17 @@ namespace elsa
~BlockDescriptor() override = default; ~BlockDescriptor() override = default;
/** /**
* \brief Create a new descriptor, replicating the dataDescriptor numberOfBlocks times along a new dimension * \brief Create a new descriptor, replicating the dataDescriptor numberOfBlocks times
* along a new dimension
* *
* \param[in] numberOfBlocks is the desired number of blocks * \param[in] numberOfBlocks is the desired number of blocks
* \param[in] dataDescriptor is the descriptor that will be replicated numberOfBlocks times along a new dimension * \param[in] dataDescriptor is the descriptor that will be replicated numberOfBlocks times
* along a new dimension
* *
* \throw std::invalid_argument if numberOfBlocks is non-positive * \throw std::invalid_argument if numberOfBlocks is non-positive
*/ */
explicit BlockDescriptor(index_t numberOfBlocks, const DataDescriptor& dataDescriptor); explicit BlockDescriptor(index_t numberOfBlocks, const DataDescriptor& dataDescriptor);
/// return the number of blocks /// return the number of blocks
index_t getNumberOfBlocks() const; index_t getNumberOfBlocks() const;
......
#pragma once #pragma once
#include <memory> #include <memory>
namespace elsa namespace elsa
{ {
/** /**
* \brief Class implementing polymorphic clones with smart pointers and CRTP, as well as comparison operators. * \brief Class implementing polymorphic clones with smart pointers and CRTP, as well as
* comparison operators.
* *
* \author Tobias Lasser * \author Tobias Lasser
* *
* This class provides a clone method using CRTP to support covariance with smart pointers. * This class provides a clone method using CRTP to support covariance with smart pointers.
* For details see https://www.fluentcpp.com/2017/09/12/how-to-return-a-smart-pointer-and-use-covariance/. * For details see
* https://www.fluentcpp.com/2017/09/12/how-to-return-a-smart-pointer-and-use-covariance/.
*/ */
template<typename Derived> template <typename Derived>
class Cloneable class Cloneable
{ {
public: public:
...@@ -23,18 +24,15 @@ namespace elsa ...@@ -23,18 +24,15 @@ namespace elsa
virtual ~Cloneable() = default; virtual ~Cloneable() = default;
/// clone object, returning an owning unique_ptr /// clone object, returning an owning unique_ptr
std::unique_ptr<Derived> clone() const { std::unique_ptr<Derived> clone() const { return std::unique_ptr<Derived>(cloneImpl()); }
return std::unique_ptr<Derived>(cloneImpl());
}
/// comparison operators /// comparison operators
bool operator==(const Derived& other) const { bool operator==(const Derived& other) const
{
return typeid(*this) == typeid(other) && isEqual(other); return typeid(*this) == typeid(other) && isEqual(other);
} }
bool operator!=(const Derived& other) const { bool operator!=(const Derived& other) const { return !(*this == other); }
return !(*this == other);
}
protected: protected:
/// actual clone implementation method, abstract to force override in derived classes /// actual clone implementation method, abstract to force override in derived classes
...@@ -43,7 +41,8 @@ namespace elsa ...@@ -43,7 +41,8 @@ namespace elsa
/// actual comparison method, abstract to force override in derived classes /// actual comparison method, abstract to force override in derived classes
virtual bool isEqual(const Derived& other) const = 0; virtual bool isEqual(const Derived& other) const = 0;
/// default copy constructor, protected to not be publicly available (but available for cloneImpl) /// default copy constructor, protected to not be publicly available (but available for
/// cloneImpl)
Cloneable(const Cloneable&) = default; Cloneable(const Cloneable&) = default;
/// default copy assignment, protected to not be publicly available /// default copy assignment, protected to not be publicly available
Cloneable& operator=(const Cloneable&) = default; Cloneable& operator=(const Cloneable&) = default;
......
...@@ -4,32 +4,36 @@ ...@@ -4,32 +4,36 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
namespace elsa { namespace elsa
{
template<typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor &dataDescriptor, DataHandlerType handlerType)
: _dataDescriptor{dataDescriptor.clone()},
_dataHandler{createDataHandler(handlerType, _dataDescriptor->getNumberOfCoefficients())}
{}
template <typename data_t> template <typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor, const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data, DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor,
DataHandlerType handlerType) DataHandlerType handlerType)
: _dataDescriptor{dataDescriptor.clone()}, : _dataDescriptor{dataDescriptor.clone()},
_dataHandler{createDataHandler(handlerType, _dataDescriptor->getNumberOfCoefficients())} _dataHandler{createDataHandler(handlerType, _dataDescriptor->getNumberOfCoefficients())}
{
}
template <typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor,
const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data,
DataHandlerType handlerType)
: _dataDescriptor{dataDescriptor.clone()},
_dataHandler{createDataHandler(handlerType, _dataDescriptor->getNumberOfCoefficients())}
{ {
if (_dataHandler->getSize() != data.size()) if (_dataHandler->getSize() != data.size())
throw std::invalid_argument("DataContainer: initialization vector has invalid size"); throw std::invalid_argument("DataContainer: initialization vector has invalid size");
for (index_t i = 0; i < _dataHandler->getSize(); ++i) for (index_t i = 0; i < _dataHandler->getSize(); ++i)
(*_dataHandler)[i] = data[i]; (*_dataHandler)[i] = data[i];
} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>::DataContainer(const DataContainer<data_t> &other) DataContainer<data_t>::DataContainer(const DataContainer<data_t>& other)
: _dataDescriptor{other._dataDescriptor->clone()}, : _dataDescriptor{other._dataDescriptor->clone()}, _dataHandler{other._dataHandler}
_dataHandler{other._dataHandler} {
{} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator=(const DataContainer<data_t>& other) DataContainer<data_t>& DataContainer<data_t>::operator=(const DataContainer<data_t>& other)
...@@ -43,7 +47,7 @@ namespace elsa { ...@@ -43,7 +47,7 @@ namespace elsa {
} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>::DataContainer(DataContainer<data_t> &&other) noexcept DataContainer<data_t>::DataContainer(DataContainer<data_t>&& other) noexcept
: _dataDescriptor{std::move(other._dataDescriptor)}, : _dataDescriptor{std::move(other._dataDescriptor)},
_dataHandler{std::move(other._dataHandler)} _dataHandler{std::move(other._dataHandler)}
{ {
...@@ -65,55 +69,51 @@ namespace elsa { ...@@ -65,55 +69,51 @@ namespace elsa {
return *this; return *this;
} }
template <typename data_t>
const DataDescriptor& DataContainer<data_t>::getDataDescriptor() const
template<typename data_t>
const DataDescriptor &DataContainer<data_t>::getDataDescriptor() const
{ {
return *_dataDescriptor; return *_dataDescriptor;
} }
template<typename data_t> template <typename data_t>
index_t DataContainer<data_t>::getSize() const index_t DataContainer<data_t>::getSize() const
{ {
return _dataHandler->getSize(); return _dataHandler->getSize();
} }
template <typename data_t>
template<typename data_t> data_t& DataContainer<data_t>::operator[](index_t index)
data_t &DataContainer<data_t>::operator[](index_t index)
{ {
detach(); detach();
return (*_dataHandler)[index]; return (*_dataHandler)[index];
} }
template<typename data_t> template <typename data_t>
const data_t &DataContainer<data_t>::operator[](index_t index) const const data_t& DataContainer<data_t>::operator[](index_t index) const
{ {
return (*_dataHandler)[index]; return (*_dataHandler)[index];
} }
template<typename data_t> template <typename data_t>
data_t &DataContainer<data_t>::operator()(IndexVector_t coordinate) data_t& DataContainer<data_t>::operator()(IndexVector_t coordinate)
{ {
detach(); detach();
return (*_dataHandler)[_dataDescriptor->getIndexFromCoordinate(coordinate)]; return (*_dataHandler)[_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()(IndexVector_t coordinate) const
{ {
return (*_dataHandler)[_dataDescriptor->getIndexFromCoordinate(coordinate)]; return (*_dataHandler)[_dataDescriptor->getIndexFromCoordinate(coordinate)];
} }
template <typename data_t>
template<typename data_t> data_t DataContainer<data_t>::dot(const DataContainer<data_t>& other) const
data_t DataContainer<data_t>::dot(const DataContainer<data_t> &other) const
{ {
return _dataHandler->dot(*other._dataHandler); return _dataHandler->dot(*other._dataHandler);
} }
template<typename data_t> template <typename data_t>
data_t DataContainer<data_t>::squaredL2Norm() const data_t DataContainer<data_t>::squaredL2Norm() const
{ {
return _dataHandler->squaredL2Norm(); return _dataHandler->squaredL2Norm();
...@@ -131,38 +131,36 @@ namespace elsa { ...@@ -131,38 +131,36 @@ namespace elsa {
return _dataHandler->lInfNorm(); return _dataHandler->lInfNorm();
} }
template<typename data_t> template <typename data_t>
data_t DataContainer<data_t>::sum() const data_t DataContainer<data_t>::sum() const
{ {
return _dataHandler->sum(); return _dataHandler->sum();
} }
template <typename data_t>
template<typename data_t>
DataContainer<data_t> DataContainer<data_t>::square() const DataContainer<data_t> DataContainer<data_t>::square() const
{ {
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->square()); return DataContainer<data_t>(*_dataDescriptor, _dataHandler->square());
} }
template<typename data_t> template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::sqrt() const DataContainer<data_t> DataContainer<data_t>::sqrt() const
{ {
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->sqrt()); return DataContainer<data_t>(*_dataDescriptor, _dataHandler->sqrt());
} }
template<typename data_t> template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::exp() const DataContainer<data_t> DataContainer<data_t>::exp() const
{ {
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->exp()); return DataContainer<data_t>(*_dataDescriptor, _dataHandler->exp());
} }
template<typename data_t> template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::log() const DataContainer<data_t> DataContainer<data_t>::log() const
{ {
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->log()); return DataContainer<data_t>(*_dataDescriptor, _dataHandler->log());
} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator+=(const DataContainer<data_t>& dc) DataContainer<data_t>& DataContainer<data_t>::operator+=(const DataContainer<data_t>& dc)
{ {
...@@ -195,7 +193,6 @@ namespace elsa { ...@@ -195,7 +193,6 @@ namespace elsa {
return *this; return *this;
} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator+=(data_t scalar) DataContainer<data_t>& DataContainer<data_t>::operator+=(data_t scalar)
{ {
...@@ -228,7 +225,6 @@ namespace elsa { ...@@ -228,7 +225,6 @@ namespace elsa {
return *this; return *this;
} }
template <typename data_t> template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator=(data_t scalar) DataContainer<data_t>& DataContainer<data_t>::operator=(data_t scalar)
{ {
...@@ -237,11 +233,11 @@ namespace elsa { ...@@ -237,11 +233,11 @@ namespace elsa {
return *this; return *this;
} }
template <typename data_t>
template<typename data_t> template <typename... Args>
template<typename ... Args>
std::unique_ptr<DataHandler<data_t>> std::unique_ptr<DataHandler<data_t>>
DataContainer<data_t>::createDataHandler(DataHandlerType handlerType, Args &&... args) { DataContainer<data_t>::createDataHandler(DataHandlerType handlerType, Args&&... args)
{
switch (handlerType) { switch (handlerType) {
case DataHandlerType::CPU: case DataHandlerType::CPU:
return std::make_unique<DataHandlerCPU<data_t>>(std::forward<Args>(args)...); return std::make_unique<DataHandlerCPU<data_t>>(std::forward<Args>(args)...);
...@@ -250,16 +246,13 @@ namespace elsa { ...@@ -250,16 +246,13 @@ namespace elsa {
} }
} }
template <typename data_t>
template<typename data_t> DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor,
DataContainer<data_t>::DataContainer(const DataDescriptor &dataDescriptor,
std::unique_ptr<DataHandler<data_t>> dataHandler) std::unique_ptr<DataHandler<data_t>> dataHandler)
: _dataDescriptor{dataDescriptor.clone()}, : _dataDescriptor{dataDescriptor.clone()}, _dataHandler{std::move(dataHandler)}
_dataHandler{std::move(dataHandler)}
{ {
} }
template <typename data_t> template <typename data_t>
bool DataContainer<data_t>::operator==(const DataContainer<data_t>& other) const bool DataContainer<data_t>::operator==(const DataContainer<data_t>& other) const
{ {
......
#pragma once #pragma once
#include "elsa.h" #include "elsa.h"
#include "DataDescriptor.h" #include "DataDescriptor.h"
#include "DataHandler.h" #include "DataHandler.h"
...@@ -12,9 +11,11 @@ ...@@ -12,9 +11,11 @@
namespace elsa namespace elsa
{ {
// forward declaration for friend test function // forward declaration for friend test function
template <typename data_t = real_t> class DataContainer; template <typename data_t = real_t>
class DataContainer;
// used for testing and defined in test file (declared as friend) // used for testing and defined in test file (declared as friend)
template <typename data_t> int useCount(const DataContainer<data_t>&); template <typename data_t>
int useCount(const DataContainer<data_t>&);
/** /**
* \brief class representing and storing a linearized n-dimensional signal * \brief class representing and storing a linearized n-dimensional signal
...@@ -33,14 +34,16 @@ namespace elsa ...@@ -33,14 +34,16 @@ namespace elsa
* detach() function first to trigger the copy-on-write mechanism. * detach() function first to trigger the copy-on-write mechanism.
*/ */
template <typename data_t> template <typename data_t>
class DataContainer { class DataContainer
{
public: public:
/** /**
* \brief type of the DataHandler used to store the actual data * \brief type of the DataHandler used to store the actual data
* *
* The following handler types are currently supported: * The following handler types are currently supported:
* - CPU: data is stored as an Eigen::Matrix in CPU main memory * - CPU: data is stored a