Commit 6ad7dc94 authored by Philipp  Trunschke's avatar Philipp Trunschke

Merge branch 'development' of git.hemio.de:xerus/xerus into development

parents 19bdac47 e8452bf5
Pipeline #937 passed with stages
in 8 minutes and 55 seconds
......@@ -73,28 +73,31 @@ namespace xerus {
/// @brief Empty constructor that creates a new Index with new ID. Use this to create indices.
Index();
Index() : valueId(idCounter++), span(1) { };
/// @brief Indices are default copy constructable.
Index(const Index& _other) noexcept = default;
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const int32 _i);
template<class I, typename std::enable_if<std::is_integral<I>::value && std::is_unsigned<I>::value, bool>::type = true>
Index(const I _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const uint32 _i) noexcept;
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const int64 _i);
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const uint64 _i) noexcept;
template<class I, typename std::enable_if<std::is_integral<I>::value && !std::is_unsigned<I>::value, bool>::type = true>
Index(const I _i) : Index(static_cast<uint64>(_i)) {
using ::xerus::misc::operator<<;
XERUS_REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
/// @brief Internal constructor, do not use this unless you know what you are doing.
explicit Index(const uint64 _valueId, const size_t _span) noexcept;
explicit Index(const uint64 _valueId, const size_t _span) noexcept : valueId(_valueId), span(_span) {};
/// @brief Internal constructor, do not use this unless you know what you are doing.
explicit Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept;
explicit Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept : valueId(_valueId), span(_span) {
flags[_flag1] = true;
}
......
......@@ -46,35 +46,15 @@ namespace xerus {
///@brief: Calculates _base^_exp by binary exponentiation
template<class T>
constexpr T pow(const T& _base, const uint32 _exp) noexcept {
return _exp==0 ? T(1) : (_exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1)));
}
///@brief: Calculates _base^_exp by binary exponentiation
template<class T>
constexpr T pow(const T &_base, const uint64 _exp) noexcept {
template<class T, class I, typename std::enable_if<std::is_integral<I>::value && std::is_unsigned<I>::value, bool>::type = true>
constexpr T pow(const T &_base, const I _exp) noexcept {
return _exp==0 ? T(1) : (_exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1)));
}
///@brief: Calculates _base^_exp by binary exponentiation
template<class T>
constexpr T pow(const T &_base, const int64 _exp) noexcept {
return _exp==0 ?
T(1) :
(
_exp<0 ?
T( 1/pow(_base, -_exp))
:
( _exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1)) )
);
}
///@brief: Calculates _base^_exp by binary exponentiation
template<class T>
constexpr T pow(const T &_base, const int32 _exp) noexcept {
template<class T, class I, typename std::enable_if<std::is_integral<I>::value && !std::is_unsigned<I>::value, bool>::type = true>
constexpr T pow(const T &_base, const I _exp) noexcept {
return _exp==0 ?
T(1) :
(
......
......@@ -287,5 +287,22 @@ static misc::UnitTest tensor_sparse_dense("Tensor", "Sparse_Dense_Conversions",
TEST(R.representation == Tensor::Representation::Dense);
});
static misc::UnitTest tensor_offset_add("Tensor", "Check_Offset_Add", [](){
auto first = xerus::Tensor::dirac({1,1,1,1},0);
auto second = xerus::Tensor::dirac({2,2,1,1},0);
second[3] = 4;
second[1] = 2;
second[2] = 3;
std::unique_ptr<Tensor> comb(new Tensor({3,3,2,2}));
comb->offset_add(first, std::vector<size_t>({0,0,0,0}));
comb->offset_add(second, std::vector<size_t>({1,1,1,1}));
TEST(((*comb)[0] - 1) * ((*comb)[0] - 1) <= 0.01);
TEST(((*comb)[19] - 1) * ((*comb)[19] - 1) <= 0.01);
TEST(((*comb)[23] - 2) * ((*comb)[23] - 2) <= 0.01);
TEST(((*comb)[31] - 3) * ((*comb)[31] - 3) <= 0.01);
TEST(((*comb)[35] - 4) * ((*comb)[35] - 4) <= 0.01);
TEST(((*comb)[1]) * ((*comb)[1]) <= 0.01);
TEST(((*comb)[2]) * ((*comb)[2]) <= 0.01);
});
......@@ -34,33 +34,6 @@ namespace xerus {
thread_local uint64 Index::idCounter = (idThreadInitCounter++)<<54;
Index::Index() : valueId(idCounter++), span(1) { }
Index::Index(const int32 _i) : Index(static_cast<uint64>(_i)) {
REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
Index::Index(const uint32 _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
Index::Index(const int64 _i) : Index(static_cast<uint64>(_i)) {
REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
Index::Index(const uint64 _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
Index::Index(const uint64 _valueId, const size_t _span) noexcept : valueId(_valueId), span(_span) {}
Index::Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept : valueId(_valueId), span(_span) {
flags[_flag1] = true;
}
void Index::set_span(const size_t _degree) {
REQUIRE(!flags[Flag::FIXED] || span == 1, "Fixed indices must have span one.");
if(flags[Flag::INVERSE_SPAN]) {
......
......@@ -26,6 +26,14 @@
#ifndef XERUS_NO_FANCY_CALLSTACK
#include <execinfo.h>
// workaround for deliberately incompatible bfd.h header files on some systems.
#ifndef PACKAGE
#define PACKAGE
#endif
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION
#endif
#include <bfd.h>
#include <dlfcn.h>
#include <unistd.h>
......
......@@ -999,10 +999,10 @@ namespace xerus {
inPosition += blockSize;
outPosition += stepSizes[index];
while(i%multStep == 0) {
outPosition -= dimensions[index]*stepSizes[index]; // "reset" current index to 0
outPosition -= _other.dimensions[index]*stepSizes[index]; // "reset" current index to 0
--index; // Advance to next index
outPosition += stepSizes[index]; // increase next index
multStep *= dimensions[index]; // next stepSize
multStep *= _other.dimensions[index]; // next stepSize
}
misc::add_scaled(outPosition, _other.factor, inPosition, blockSize);
......
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