From 787e93a44bc3a17f9a9283a20a75022bd4e758a4 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen <pauli.t.virtanen@jyu.fi> Date: Wed, 3 Aug 2022 16:56:56 +0300 Subject: [PATCH] array: move asserts to right place --- src/array.hpp | 9 +++------ src/main.cpp | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/array.hpp b/src/array.hpp index e223b14..6d7e763 100644 --- a/src/array.hpp +++ b/src/array.hpp @@ -99,10 +99,7 @@ namespace detail } public: - fixed_base() - { - static_assert(Shape::fixed, "array shape must be compile-time fixed"); - } + fixed_base() {} constexpr size_t dim(size_t i) const { return Shape::dim(i); } constexpr size_t stride(size_t i) const { return Shape::stride(i); } @@ -140,8 +137,6 @@ namespace detail dynamic_base(const std::array<size_t, Shape::ndim> shape) : shape_(shape) { - static_assert(!Shape::fixed, "array shape must not be compile-time fixed"); - for (size_t i = Shape::ndim; i > 0; --i) { if (Shape::stride(i-1) != Dynamic) strides_[i-1] = Shape::stride(i-1); @@ -205,12 +200,14 @@ public: Array(Scalar *data, size_t size, const std::array<size_t, Shape::ndim> shape) : Base(shape), data_(data) { + static_assert(!Shape::fixed, "array shape must not be compile-time fixed"); Base::data_bounds_check(size); } Array(Scalar *data, size_t size) : Base(), data_(data) { + static_assert(Shape::fixed, "array shape must be compile-time fixed"); Base::data_bounds_check(size); } diff --git a/src/main.cpp b/src/main.cpp index 5ffac0b..fdd5ad9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,8 @@ void dump(Array<Scalar,Shape> Q) int main() { - std::vector<double> v(7*2*2*2); - Array<double,Shape<Dynamic,Dynamic,2,2> > Q0(v.data(), v.size(), {7,2,2,2}); + std::vector<double> v(1*2*2*2); + Array<double,Shape<Dynamic,Dynamic,2,2> > Q0(v.data(), v.size(), {1,2,2,2}); auto Q = Q0.part(0u,1u); S_2(Q); -- GitLab