The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

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

#13 Add operator<< overloads to some types

operator<< is added for Eigen vectors, DataContainers and Descriptors.
These then can be used for spdlog to print them out quicker.
parent 92c2d447
Pipeline #459779 failed with stages
in 20 minutes and 53 seconds
......@@ -63,7 +63,7 @@ endif()
add_library(${ELSA_MODULE_TARGET_NAME} ${MODULE_HEADERS} ${MODULE_SOURCES})
add_library(elsa::${ELSA_MODULE_NAME} ALIAS ${ELSA_MODULE_TARGET_NAME})
target_link_libraries(${ELSA_MODULE_TARGET_NAME} PUBLIC Eigen3::Eigen)
target_link_libraries(${ELSA_MODULE_TARGET_NAME} PUBLIC Eigen3::Eigen elsa_logging)
# use OpenMP is available
find_package(OpenMP)
......
......@@ -6,6 +6,8 @@
#include <stdexcept>
#include <utility>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
......@@ -512,3 +514,33 @@ namespace elsa
template class DataContainer<index_t>;
} // namespace elsa
template <>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<float>& dc)
{
return os << "{ DataContainer<float> " << dc.getDataDescriptor() << "}";
}
template <>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<double>& dc)
{
return os << "{ DataContainer<double> " << dc.getDataDescriptor() << "}";
}
template <>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<elsa::index_t>& dc)
{
return os << "{ DataContainer<index_t> " << dc.getDataDescriptor() << "}";
}
template <>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<std::complex<float>>& dc)
{
return os << "{ DataContainer<cmpl<float>> " << dc.getDataDescriptor() << "}";
}
template <>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<std::complex<double>>& dc)
{
return os << "{ DataContainer<cmpl<double>> " << dc.getDataDescriptor() << "}";
}
#pragma once
#include "spdlog/fmt/ostr.h"
#include "elsaDefines.h"
#include "DataDescriptor.h"
#include "DataHandler.h"
......@@ -618,5 +620,7 @@ namespace elsa
return Expression{log, operand};
#endif
}
} // namespace elsa
template <typename data_t>
std::ostream& operator<<(std::ostream& os, const elsa::DataContainer<data_t>& dc);
#include "spdlog/fmt/ostr.h"
std::ostream& operator<<(std::ostream& os, const elsa::BlockDescriptor& desc)
{
return os << "{ BlockDescriptor { " << desc.getNumberOfBlocks() << " blocks"
<< " }}";
}
......@@ -44,3 +44,5 @@ namespace elsa
BlockDescriptor(const DataDescriptor& base) : DataDescriptor{base} {}
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::BlockDescriptor& desc);
......@@ -3,6 +3,8 @@
#include <stdexcept>
#include <algorithm>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
DataDescriptor::DataDescriptor(IndexVector_t numberOfCoefficientsPerDimension)
......@@ -113,3 +115,8 @@ namespace elsa
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::DataDescriptor& desc)
{
return os << "{ DataDescriptor " << desc.getNumberOfCoefficientsPerDimension() << " }";
}
......@@ -121,3 +121,5 @@ namespace elsa
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::DataDescriptor& desc);
#include "DetectorDescriptor.h"
#include <iostream>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
DetectorDescriptor::DetectorDescriptor(const IndexVector_t& numOfCoeffsPerDim,
......@@ -85,3 +87,8 @@ namespace elsa
std::cbegin(otherBlock->_geometry));
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::DetectorDescriptor& desc)
{
return os << "{ DetectorDescriptor " << desc.getNumberOfCoefficientsPerDimension() << " }";
}
......@@ -85,3 +85,5 @@ namespace elsa
std::vector<Geometry> _geometry;
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::DetectorDescriptor& desc);
#include "IdenticalBlocksDescriptor.h"
#include "VolumeDescriptor.h"
#include "spdlog/fmt/ostr.h"
namespace elsa
{
IdenticalBlocksDescriptor::IdenticalBlocksDescriptor(index_t numberOfBlocks,
......@@ -67,3 +69,9 @@ namespace elsa
return VolumeDescriptor(numberOfCoeffs, spacingOfCoeffs);
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::IdenticalBlocksDescriptor& desc)
{
return os << "{ IdenticalBlockDescriptor { " << desc.getNumberOfBlocks() << " blocks of size "
<< desc.getNumberOfCoefficientsPerDimension() << " }}";
}
......@@ -67,3 +67,5 @@ namespace elsa
VolumeDescriptor initBase(index_t numberOfBlocks, const DataDescriptor& dataDescriptor);
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::IdenticalBlocksDescriptor& desc);
......@@ -3,6 +3,8 @@
#include <unordered_map>
#include <type_traits>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
PartitionDescriptor::PartitionDescriptor(const DataDescriptor& dataDescriptor,
......@@ -131,3 +133,9 @@ namespace elsa
return std::make_unique<VolumeDescriptor>(coeffsPerDim, getSpacingPerDimension());
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::PartitionDescriptor& desc)
{
return os << "{ PartitionDescriptor { " << desc.getNumberOfBlocks() << " blocks"
<< " }}";
}
......@@ -93,3 +93,5 @@ namespace elsa
generateDescriptorOfPartition(index_t numberOfSlices) const;
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::PartitionDescriptor& desc);
#include "PlanarDetectorDescriptor.h"
#include <iostream>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
......@@ -83,3 +84,9 @@ namespace elsa
getSpacingPerDimension(), _geometry);
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::PlanarDetectorDescriptor& desc)
{
return os << "PlanarDetectorDescriptor { " << desc.getNumberOfCoefficientsPerDimension()
<< " }";
}
......@@ -50,3 +50,5 @@ namespace elsa
bool isEqual(const DataDescriptor& other) const override;
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::PlanarDetectorDescriptor& desc);
#include "RandomBlocksDescriptor.h"
#include "VolumeDescriptor.h"
#include "spdlog/fmt/ostr.h"
namespace elsa
{
RandomBlocksDescriptor::RandomBlocksDescriptor(
......@@ -92,3 +94,8 @@ namespace elsa
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::RandomBlocksDescriptor& desc)
{
return os << "{ RandomBlockDescriptor { " << desc.getNumberOfBlocks() << " blocks }}";
}
......@@ -77,4 +77,6 @@ namespace elsa
IndexVector_t
determineSize(const std::vector<std::unique_ptr<DataDescriptor>>& blockDescriptors);
};
} // namespace elsa
\ No newline at end of file
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::RandomBlocksDescriptor& desc);
......@@ -3,6 +3,8 @@
#include <stdexcept>
#include <algorithm>
#include "spdlog/fmt/ostr.h"
namespace elsa
{
VolumeDescriptor::VolumeDescriptor(IndexVector_t numberOfCoefficientsPerDimension)
......@@ -41,3 +43,8 @@ namespace elsa
}
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::VolumeDescriptor& desc)
{
return os << "{ VolumeDescriptor " << desc.getNumberOfCoefficientsPerDimension() << " }";
}
......@@ -83,3 +83,5 @@ namespace elsa
};
} // namespace elsa
std::ostream& operator<<(std::ostream& os, const elsa::VolumeDescriptor& desc);
......@@ -79,3 +79,10 @@ namespace elsa
constexpr bool isComplex = std::is_same<RemoveCvRef_t<T>, std::complex<float>>::value
|| std::is_same<RemoveCvRef_t<T>, std::complex<double>>::value;
} // namespace elsa
template <typename data_t>
std::ostream& operator<<(std::ostream& os, const Eigen::Matrix<data_t, Eigen::Dynamic, 1>& vec)
{
const Eigen::IOFormat fmt(4, 0, ", ", "\n", "[", "]");
return os << vec.transpose().format(fmt);
}
Markdown is supported
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