Commit fdea0ce2 authored by Jens Petit's avatar Jens Petit

clang-format on all cpp-files

parent 6412d981
Pipeline #171383 passed with stages
in 27 minutes and 26 seconds
......@@ -5,10 +5,8 @@
namespace elsa
{
BlockDescriptor::BlockDescriptor(index_t numberOfBlocks, const DataDescriptor &dataDescriptor)
: DataDescriptor(dataDescriptor),
_blockDescriptors{},
_blockOffsets(numberOfBlocks)
BlockDescriptor::BlockDescriptor(index_t numberOfBlocks, const DataDescriptor& dataDescriptor)
: DataDescriptor(dataDescriptor), _blockDescriptors{}, _blockOffsets(numberOfBlocks)
{
// sanity check
if (numberOfBlocks <= 0)
......@@ -23,33 +21,32 @@ namespace elsa
_numberOfDimensions++;
_numberOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions);
_numberOfCoefficientsPerDimension(_numberOfDimensions-1) = numberOfBlocks;
_numberOfCoefficientsPerDimension(_numberOfDimensions - 1) = numberOfBlocks;
_spacingPerDimension.conservativeResize(_numberOfDimensions);
_spacingPerDimension(_numberOfDimensions-1) = 1.0;
_spacingPerDimension(_numberOfDimensions - 1) = 1.0;
_productOfCoefficientsPerDimension.conservativeResize(_numberOfDimensions);
_productOfCoefficientsPerDimension(_numberOfDimensions-1) =
_numberOfCoefficientsPerDimension.head(_numberOfDimensions-1).prod();
_productOfCoefficientsPerDimension(_numberOfDimensions - 1) =
_numberOfCoefficientsPerDimension.head(_numberOfDimensions - 1).prod();
}
index_t BlockDescriptor::getNumberOfBlocks() const {
return _blockDescriptors.size();
}
index_t BlockDescriptor::getNumberOfBlocks() const { return _blockDescriptors.size(); }
const DataDescriptor& BlockDescriptor::getIthDescriptor(index_t i) const {
const DataDescriptor& BlockDescriptor::getIthDescriptor(index_t i) const
{
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())
throw std::invalid_argument("BlockDescriptor: index i is out of bounds");
return _blockOffsets.coeff(i);
}
BlockDescriptor::BlockDescriptor(const BlockDescriptor &blockDescriptor)
BlockDescriptor::BlockDescriptor(const BlockDescriptor& blockDescriptor)
: DataDescriptor(blockDescriptor),
_blockDescriptors{},
_blockOffsets{blockDescriptor._blockOffsets}
......@@ -58,10 +55,7 @@ namespace elsa
_blockDescriptors.emplace_back(descriptor->clone());
}
BlockDescriptor* BlockDescriptor::cloneImpl() const
{
return new BlockDescriptor(*this);
}
BlockDescriptor* BlockDescriptor::cloneImpl() const { return new BlockDescriptor(*this); }
bool BlockDescriptor::isEqual(const DataDescriptor& other) const
{
......
#pragma once
#include "elsa.h"
#include "Cloneable.h"
#include "DataDescriptor.h"
......@@ -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 David Frank - rewrite
* \author Nikola Dinev - various enhancements
* \author Tobias Lasser - rewrite, modularization, modernization
*
* This class provides metadata about a signal that is stored in memory (typically a DataContainer).
* This signal can be n-dimensional, and will be stored in memory in a linearized fashion in blocks.
* The blocks can be used to support various operations (like blocked operators or ordered subsets),
* however, the blocks have to lie in memory one after the other (i.e. no stride is supported).
* This class provides metadata about a signal that is stored in memory (typically a
* DataContainer). This signal can be n-dimensional, and will be stored in memory in a
* linearized fashion in blocks. The blocks can be used to support various operations (like
* 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
{
......@@ -34,16 +35,17 @@ namespace elsa
~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] 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
*/
explicit BlockDescriptor(index_t numberOfBlocks, const DataDescriptor& dataDescriptor);
/// return the number of blocks
index_t getNumberOfBlocks() const;
......
#pragma once
#include <memory>
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
*
* 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
{
public:
......@@ -23,18 +24,15 @@ namespace elsa
virtual ~Cloneable() = default;
/// clone object, returning an owning unique_ptr
std::unique_ptr<Derived> clone() const {
return std::unique_ptr<Derived>(cloneImpl());
}
std::unique_ptr<Derived> clone() const { return std::unique_ptr<Derived>(cloneImpl()); }
/// comparison operators
bool operator==(const Derived& other) const {
bool operator==(const Derived& other) const
{
return typeid(*this) == typeid(other) && isEqual(other);
}
bool operator!=(const Derived& other) const {
return !(*this == other);
}
bool operator!=(const Derived& other) const { return !(*this == other); }
protected:
/// actual clone implementation method, abstract to force override in derived classes
......@@ -43,7 +41,8 @@ namespace elsa
/// actual comparison method, abstract to force override in derived classes
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;
/// default copy assignment, protected to not be publicly available
Cloneable& operator=(const Cloneable&) = default;
......
......@@ -4,32 +4,36 @@
#include <stdexcept>
#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>
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())}
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor,
DataHandlerType handlerType)
: _dataDescriptor{dataDescriptor.clone()},
_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())
throw std::invalid_argument("DataContainer: initialization vector has invalid size");
for (index_t i = 0; i < _dataHandler->getSize(); ++i)
(*_dataHandler)[i] = data[i];
}
template <typename data_t>
DataContainer<data_t>::DataContainer(const DataContainer<data_t> &other)
: _dataDescriptor{other._dataDescriptor->clone()},
_dataHandler{other._dataHandler}
{}
DataContainer<data_t>::DataContainer(const DataContainer<data_t>& other)
: _dataDescriptor{other._dataDescriptor->clone()}, _dataHandler{other._dataHandler}
{
}
template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator=(const DataContainer<data_t>& other)
......@@ -43,7 +47,7 @@ namespace elsa {
}
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)},
_dataHandler{std::move(other._dataHandler)}
{
......@@ -65,55 +69,51 @@ namespace elsa {
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;
}
template<typename data_t>
template <typename data_t>
index_t DataContainer<data_t>::getSize() const
{
return _dataHandler->getSize();
}
template<typename data_t>
data_t &DataContainer<data_t>::operator[](index_t index)
template <typename data_t>
data_t& DataContainer<data_t>::operator[](index_t index)
{
detach();
return (*_dataHandler)[index];
}
template<typename data_t>
const data_t &DataContainer<data_t>::operator[](index_t index) const
template <typename data_t>
const data_t& DataContainer<data_t>::operator[](index_t index) const
{
return (*_dataHandler)[index];
}
template<typename data_t>
data_t &DataContainer<data_t>::operator()(IndexVector_t coordinate)
template <typename data_t>
data_t& DataContainer<data_t>::operator()(IndexVector_t coordinate)
{
detach();
return (*_dataHandler)[_dataDescriptor->getIndexFromCoordinate(coordinate)];
}
template<typename data_t>
const data_t &DataContainer<data_t>::operator()(IndexVector_t coordinate) const
template <typename data_t>
const data_t& DataContainer<data_t>::operator()(IndexVector_t coordinate) const
{
return (*_dataHandler)[_dataDescriptor->getIndexFromCoordinate(coordinate)];
}
template<typename data_t>
data_t DataContainer<data_t>::dot(const DataContainer<data_t> &other) const
template <typename data_t>
data_t DataContainer<data_t>::dot(const DataContainer<data_t>& other) const
{
return _dataHandler->dot(*other._dataHandler);
}
template<typename data_t>
template <typename data_t>
data_t DataContainer<data_t>::squaredL2Norm() const
{
return _dataHandler->squaredL2Norm();
......@@ -131,38 +131,36 @@ namespace elsa {
return _dataHandler->lInfNorm();
}
template<typename data_t>
template <typename data_t>
data_t DataContainer<data_t>::sum() const
{
return _dataHandler->sum();
}
template<typename data_t>
template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::square() const
{
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->square());
}
template<typename data_t>
template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::sqrt() const
{
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->sqrt());
}
template<typename data_t>
template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::exp() const
{
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->exp());
}
template<typename data_t>
template <typename data_t>
DataContainer<data_t> DataContainer<data_t>::log() const
{
return DataContainer<data_t>(*_dataDescriptor, _dataHandler->log());
}
template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator+=(const DataContainer<data_t>& dc)
{
......@@ -195,7 +193,6 @@ namespace elsa {
return *this;
}
template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator+=(data_t scalar)
{
......@@ -228,7 +225,6 @@ namespace elsa {
return *this;
}
template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator=(data_t scalar)
{
......@@ -237,11 +233,11 @@ namespace elsa {
return *this;
}
template<typename data_t>
template<typename ... Args>
template <typename data_t>
template <typename... Args>
std::unique_ptr<DataHandler<data_t>>
DataContainer<data_t>::createDataHandler(DataHandlerType handlerType, Args &&... args) {
DataContainer<data_t>::createDataHandler(DataHandlerType handlerType, Args&&... args)
{
switch (handlerType) {
case DataHandlerType::CPU:
return std::make_unique<DataHandlerCPU<data_t>>(std::forward<Args>(args)...);
......@@ -250,16 +246,13 @@ namespace elsa {
}
}
template<typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor &dataDescriptor,
template <typename data_t>
DataContainer<data_t>::DataContainer(const DataDescriptor& dataDescriptor,
std::unique_ptr<DataHandler<data_t>> dataHandler)
: _dataDescriptor{dataDescriptor.clone()},
_dataHandler{std::move(dataHandler)}
: _dataDescriptor{dataDescriptor.clone()}, _dataHandler{std::move(dataHandler)}
{
}
template <typename data_t>
bool DataContainer<data_t>::operator==(const DataContainer<data_t>& other) const
{
......
#pragma once
#include "elsa.h"
#include "DataDescriptor.h"
#include "DataHandler.h"
......@@ -12,9 +11,11 @@
namespace elsa
{
// 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)
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
......@@ -33,14 +34,16 @@ namespace elsa
* detach() function first to trigger the copy-on-write mechanism.
*/
template <typename data_t>
class DataContainer {
class DataContainer
{
public:
/**
* \brief type of the DataHandler used to store the actual data
*
* The following handler types are currently supported:
* - CPU: data is stored as an Eigen::Matrix in CPU main memory
* - MAP: data is not explicitly stored, but using an Eigen::Map to refer to other storage
* - MAP: data is not explicitly stored, but using an Eigen::Map to refer to other
* storage
*/
enum class DataHandlerType { CPU };
......@@ -54,19 +57,18 @@ namespace elsa
* \param[in] handlerType the data handler (default: CPU)
*/
explicit DataContainer(const DataDescriptor& dataDescriptor,
DataHandlerType handlerType = DataHandlerType::CPU);
DataHandlerType handlerType = DataHandlerType::CPU);
/**
* \brief Constructor for DataContainer, initializing it with a DataVector
*
*
* \param[in] dataDescriptor containing the associated metadata
* \param[in] data vector containing the initialization data
* \param[in] handlerType the data handler (default: CPU)
*/
DataContainer(const DataDescriptor& dataDescriptor, const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data,
DataHandlerType handlerType = DataHandlerType::CPU);
DataContainer(const DataDescriptor& dataDescriptor,
const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& data,
DataHandlerType handlerType = DataHandlerType::CPU);
/**
* \brief Copy constructor for DataContainer
......@@ -107,10 +109,10 @@ namespace elsa
/// return the current DataDescriptor
const DataDescriptor& getDataDescriptor() const;
/// return the size of the stored data (i.e. the number of elements in the linearized signal)
/// return the size of the stored data (i.e. the number of elements in the linearized
/// signal)
index_t getSize() const;
/// return the index-th element of linearized signal (not bounds-checked!)
data_t& operator[](index_t index);
......@@ -124,20 +126,24 @@ namespace elsa
const data_t& operator()(IndexVector_t coordinate) const;
/// return an element by its coordinates (not bounds-checked!)
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
data_t& operator()(idx0_t idx0, idx_t... indices) {
IndexVector_t coordinate(sizeof...(indices)+1);
((coordinate<<idx0) , ... , indices);
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<
std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
data_t& operator()(idx0_t idx0, idx_t... indices)
{
IndexVector_t coordinate(sizeof...(indices) + 1);
((coordinate << idx0), ..., indices);
return operator()(coordinate);
}
/// return an element by its coordinates as read-only (not bounds-checked!)
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
const data_t& operator()(idx0_t idx0, idx_t... indices) const{
IndexVector_t coordinate(sizeof...(indices)+1);
((coordinate<<idx0) , ... , indices);
template <typename idx0_t, typename... idx_t,
typename = std::enable_if_t<
std::is_integral_v<idx0_t> && (... && std::is_integral_v<idx_t>)>>
const data_t& operator()(idx0_t idx0, idx_t... indices) const
{
IndexVector_t coordinate(sizeof...(indices) + 1);
((coordinate << idx0), ..., indices);
return operator()(coordinate);
}
......@@ -156,7 +162,6 @@ namespace elsa
/// return the sum of all elements of this signal
data_t sum() const;
/// return a new DataContainer with element-wise squared values of this one
DataContainer<data_t> square() const;
......@@ -169,7 +174,6 @@ namespace elsa
/// return a new DataContainer with element-wise logarithms of this one
DataContainer<data_t> log() const;
/// compute in-place element-wise addition of another container
DataContainer<data_t>& operator+=(const DataContainer<data_t>& dc);
......@@ -182,7 +186,6 @@ namespace elsa
/// compute in-place element-wise division by another container
DataContainer<data_t>& operator/=(const DataContainer<data_t>& dc);
/// compute in-place addition of a scalar
DataContainer<data_t>& operator+=(data_t scalar);
......@@ -195,11 +198,9 @@ namespace elsa
/// compute in-place division by a scalar
DataContainer<data_t>& operator/=(data_t scalar);
/// assign a scalar to the DataContainer
DataContainer<data_t>& operator=(data_t scalar);
/// comparison with another DataContainer
bool operator==(const DataContainer<data_t>& other) const;
......@@ -207,7 +208,7 @@ namespace elsa
bool operator!=(const DataContainer<data_t>& other) const;
/// used for testing only and defined in test file
friend int useCount <> (const DataContainer<data_t>& dc);
friend int useCount<>(const DataContainer<data_t>& dc);
/// iterator for DataContainer (random access and continuous)
using iterator = DataContainerIterator<DataContainer<data_t>>;
......@@ -216,9 +217,9 @@ namespace elsa
using const_iterator = ConstDataContainerIterator<DataContainer<data_t>>;
/// alias for reverse iterator
using reverse_iterator = std::reverse_iterator<iterator>;
using reverse_iterator = std::reverse_iterator<iterator>;
/// alias for const reverse iterator
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
/// returns iterator to the first element of the container
iterator begin();
......@@ -232,38 +233,44 @@ namespace elsa
/// returns iterator to one past the last element of the container
iterator end();
/// returns const iterator to one past the last element of the container (cannot mutate data)
/// returns const iterator to one past the last element of the container (cannot mutate
/// data)
const_iterator end() const;
/// returns const iterator to one past the last element of the container (cannot mutate data)
/// returns const iterator to one past the last element of the container (cannot mutate
/// data)
const_iterator cend() const;
/// returns reversed iterator to the last element of the container
reverse_iterator rbegin();
/// returns const reversed iterator to the last element of the container (cannot mutate data)
/// returns const reversed iterator to the last element of the container (cannot mutate
/// data)
const_reverse_iterator rbegin() const;
/// returns const reversed iterator to the last element of the container (cannot mutate data)
/// returns const reversed iterator to the last element of the container (cannot mutate