diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bdae9bc3ae..c192c2b7bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,7 @@ build: script: - mkdir build - cd build - - cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gitlab-ci.cmake + - cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/gitlab-ci.cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -D${TA_PYTHON} -D${ENABLE_MKL} diff --git a/CMakeLists.txt b/CMakeLists.txt index e6e91d1e6f..e22ea821df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,11 +262,15 @@ check_type_size("long long" TILEDARRAY_HAS_LONG_LONG LANGUAGE CXX) # convert string values of TA_ERROR to numerical values expected by TA_DEFAULT_ERROR ########################## set (TA_DEFAULT_ERROR 3) # default is to abort so that it works with or without NDEBUG - # assert when CMAKE_BUILD_TYPE is Debug or RelWithDebugUnfo + # assert when CMAKE_BUILD_TYPE is Debug or RelWithDebInfo string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELWITHDEBINFO)$") set (TA_DEFAULT_ERROR 2) endif() +# if building unit tests default to throw to be able to test TA_ASSERT statements +if (TA_BUILD_UNITTEST) + set (TA_DEFAULT_ERROR 1) +endif(TA_BUILD_UNITTEST) if (TA_ERROR STREQUAL none) set (TA_DEFAULT_ERROR 0) diff --git a/INSTALL.md b/INSTALL.md index 80a4f4aacd..3dc8fe3344 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -362,7 +362,7 @@ support may be added. ## Expert configure options: * `TA_EXPERT` -- Set to `ON` to disable automatic installation of prerequisites. Useful for experts, hence the name. [Default=OFF]. -* `TA_ERROR` -- Set to `none` to disable `TA_ASSERT` assertions, `throw` to cause `TA_ASSERT` assertions to throw, `abort` to cause `TA_ASSERT` assertions to abort, or `assert` to cause `TA_ASSERT` assertions to use C++ assert. +* `TA_ERROR` -- Set to `none` to disable `TA_ASSERT` assertions, `throw` to cause `TA_ASSERT` assertions to throw, `abort` to cause `TA_ASSERT` assertions to abort, or `assert` to cause `TA_ASSERT` assertions to use C++ assert. The default is `throw` if `TA_BUILD_UNITTEST` is set, else is `assert` if `CMAKE_BUILD_TYPE` is `Debug` or `RelWithDebInfo`, else is `abort`. * `TA_TRACE_TASKS` -- Set to `ON` to enable tracing of MADNESS tasks using custom task tracer. Note that standard profilers/tracers are generally useless (except in the trivial cases) with MADWorld-based programs since the submission context of tasks is not captured by standard tracing tools; this makes it impossible in a nontrivial program to attribute tasks to source code. WARNING: task tracing his will greatly increase the memory requirements. [Default=OFF]. * `TA_ENABLE_RANGEV3` -- Set to `ON` to find or fetch the Range-V3 library and enable additional tests of TA components with constructs anticipated to be supported in the future. [Default=OFF]. * `TA_SIGNED_1INDEX_TYPE` -- Set to `OFF` to use unsigned 1-index coordinate type (default for TiledArray 1.0.0-alpha.2 and older). The default is `ON`, which enables the use of negative indices in coordinates. diff --git a/bin/build-linux.sh b/bin/build-linux.sh index 5c935ca93a..7146fde5ff 100755 --- a/bin/build-linux.sh +++ b/bin/build-linux.sh @@ -97,7 +97,6 @@ if [ "$BUILD_TYPE" = "Debug" ]; then -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \ -DTA_PYTHON="${TA_PYTHON}" \ -DTA_BUILD_UNITTEST=ON \ - -DTA_ERROR="throw" \ -DENABLE_SCALAPACK=ON else @@ -128,7 +127,6 @@ else -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \ -DTA_PYTHON="${TA_PYTHON}" \ -DTA_BUILD_UNITTEST=ON \ - -DTA_ERROR="throw" \ -DENABLE_SCALAPACK=ON fi diff --git a/cmake/gitlab-ci.cmake b/cmake/toolchains/gitlab-ci.cmake similarity index 100% rename from cmake/gitlab-ci.cmake rename to cmake/toolchains/gitlab-ci.cmake diff --git a/src/TiledArray/conversions/btas.h b/src/TiledArray/conversions/btas.h index eeded267db..e093ad7289 100644 --- a/src/TiledArray/conversions/btas.h +++ b/src/TiledArray/conversions/btas.h @@ -215,14 +215,14 @@ DistArray_ btas_tensor_to_array(World& world, bool replicated = false) { // Test preconditions const auto rank = trange.tiles_range().rank(); - TA_USER_ASSERT(rank == src.range().rank(), - "TiledArray::btas_tensor_to_array(): rank of destination " - "trange does not match the rank of source BTAS tensor."); + TA_ASSERT(rank == src.range().rank() && + "TiledArray::btas_tensor_to_array(): rank of destination " + "trange does not match the rank of source BTAS tensor."); auto dst_range_extents = trange.elements_range().extent(); for (std::remove_const_t d = 0; d != rank; ++d) { - TA_USER_ASSERT(dst_range_extents[d] == src.range().extent(d), - "TiledArray::btas_tensor_to_array(): source dimension does " - "not match destination dimension."); + TA_ASSERT(dst_range_extents[d] == src.range().extent(d) && + "TiledArray::btas_tensor_to_array(): source dimension does " + "not match destination dimension."); } using Tensor_ = btas::Tensor; @@ -231,8 +231,8 @@ DistArray_ btas_tensor_to_array(World& world, // Check that this is not a distributed computing environment if (!replicated) - TA_USER_ASSERT( - world.size() == 1, + TA_ASSERT( + world.size() == 1 && "An array can be created from a btas::Tensor if the number of World " "ranks is greater than 1 only when replicated=true."); @@ -302,8 +302,8 @@ array_to_btas_tensor(const TiledArray::DistArray& src, int target_rank = -1) { // Test preconditions if (target_rank == -1 && !src.pmap()->is_replicated()) - TA_USER_ASSERT( - src.world().size() == 1, + TA_ASSERT( + src.world().size() == 1 && "TiledArray::array_to_btas_tensor(): a non-replicated array can only " "be converted to a btas::Tensor on every rank if the number of World " "ranks is 1."); diff --git a/src/TiledArray/conversions/eigen.h b/src/TiledArray/conversions/eigen.h index 58e9db51f0..f077c8e8e3 100644 --- a/src/TiledArray/conversions/eigen.h +++ b/src/TiledArray/conversions/eigen.h @@ -27,8 +27,8 @@ #define TILEDARRAY_CONVERSIONS_EIGEN_H__INCLUDED #include -#include #include +#include #include #include #include @@ -413,23 +413,23 @@ A eigen_to_array(World& world, const typename A::trange_type& trange, typedef typename A::index1_type size_type; // Check that trange matches the dimensions of other if ((matrix.cols() > 1) && (matrix.rows() > 1)) { - TA_USER_ASSERT(trange.tiles_range().rank() == 2, - "TiledArray::eigen_to_array(): The number of dimensions in " - "trange is not equal to that of the Eigen matrix."); - TA_USER_ASSERT( - trange.elements_range().extent(0) == size_type(matrix.rows()), + TA_ASSERT(trange.tiles_range().rank() == 2 && + "TiledArray::eigen_to_array(): The number of dimensions in " + "trange is not equal to that of the Eigen matrix."); + TA_ASSERT( + trange.elements_range().extent(0) == size_type(matrix.rows()) && "TiledArray::eigen_to_array(): The number of rows in trange is not " "equal to the number of rows in the Eigen matrix."); - TA_USER_ASSERT( - trange.elements_range().extent(1) == size_type(matrix.cols()), + TA_ASSERT( + trange.elements_range().extent(1) == size_type(matrix.cols()) && "TiledArray::eigen_to_array(): The number of columns in trange is not " "equal to the number of columns in the Eigen matrix."); } else { - TA_USER_ASSERT(trange.tiles_range().rank() == 1, - "TiledArray::eigen_to_array(): The number of dimensions in " - "trange must match that of the Eigen matrix."); - TA_USER_ASSERT( - trange.elements_range().extent(0) == size_type(matrix.size()), + TA_ASSERT(trange.tiles_range().rank() == 1 && + "TiledArray::eigen_to_array(): The number of dimensions in " + "trange must match that of the Eigen matrix."); + TA_ASSERT( + trange.elements_range().extent(0) == size_type(matrix.size()) && "TiledArray::eigen_to_array(): The size of trange must be equal to the " "matrix size."); } @@ -501,17 +501,18 @@ array_to_eigen(const DistArray& array) { const auto rank = array.trange().tiles_range().rank(); // Check that the array will fit in a matrix or vector - TA_USER_ASSERT((rank == 2u) || (rank == 1u), - "TiledArray::array_to_eigen(): The array dimensions must be " - "equal to 1 or 2."); + TA_ASSERT((rank == 2u) || + (rank == 1u) && + "TiledArray::array_to_eigen(): The array dimensions must be " + "equal to 1 or 2."); // Check that this is not a distributed computing environment or that the // array is replicated if (!array.pmap()->is_replicated()) - TA_USER_ASSERT(array.world().size() == 1, - "TiledArray::array_to_eigen(): non-replicated Array cannot " - "be assigned to an Eigen::Matrix when the number of World " - "ranks is greater than 1."); + TA_ASSERT(array.world().size() == 1 && + "TiledArray::array_to_eigen(): non-replicated Array cannot " + "be assigned to an Eigen::Matrix when the number of World " + "ranks is greater than 1."); // Construct the Eigen matrix const auto* MADNESS_RESTRICT const array_extent = @@ -594,12 +595,12 @@ inline A row_major_buffer_to_array( const typename A::value_type::value_type* buffer, const std::size_t m, const std::size_t n, const bool replicated = false, std::shared_ptr pmap = {}) { - TA_USER_ASSERT(trange.elements_range().extent(0) == m, - "TiledArray::eigen_to_array(): The number of rows in trange " - "is not equal to m."); - TA_USER_ASSERT(trange.elements_range().extent(1) == n, - "TiledArray::eigen_to_array(): The number of columns in " - "trange is not equal to n."); + TA_ASSERT(trange.elements_range().extent(0) == m && + "TiledArray::eigen_to_array(): The number of rows in trange " + "is not equal to m."); + TA_ASSERT(trange.elements_range().extent(1) == n && + "TiledArray::eigen_to_array(): The number of columns in " + "trange is not equal to n."); typedef Eigen::Matrix @@ -663,12 +664,12 @@ inline A column_major_buffer_to_array( const typename A::value_type::value_type* buffer, const std::size_t m, const std::size_t n, const bool replicated = false, std::shared_ptr pmap = {}) { - TA_USER_ASSERT(trange.elements_range().extent(0) == m, - "TiledArray::eigen_to_array(): The number of rows in trange " - "is not equal to m."); - TA_USER_ASSERT(trange.elements_range().extent(1) == n, - "TiledArray::eigen_to_array(): The number of columns in " - "trange is not equal to n."); + TA_ASSERT(trange.elements_range().extent(0) == m && + "TiledArray::eigen_to_array(): The number of rows in trange " + "is not equal to m."); + TA_ASSERT(trange.elements_range().extent(1) == n && + "TiledArray::eigen_to_array(): The number of columns in " + "trange is not equal to n."); typedef Eigen::Matrix diff --git a/src/TiledArray/conversions/foreach.h b/src/TiledArray/conversions/foreach.h index 8a5b886875..5a3011d7fb 100644 --- a/src/TiledArray/conversions/foreach.h +++ b/src/TiledArray/conversions/foreach.h @@ -186,8 +186,7 @@ inline std:: "if inplace==false, Op must be callable with signature " "void(ResultTile&,const ArgTile&, const ArgTiles&...)"); - TA_USER_ASSERT(compare_trange(arg, args...), - "Tiled ranges of args must match"); + TA_ASSERT(compare_trange(arg, args...) && "Tiled ranges of args must match"); typedef DistArray arg_array_type; typedef DistArray result_array_type; @@ -261,8 +260,8 @@ inline std:: "ret(ResultTile&,const ArgTile&, const ArgTiles&...), where " "ret={void,Policy::shape_type::value_type}"); - TA_USER_ASSERT(detail::compare_trange(arg, args...), - "Tiled ranges of args must match"); + TA_ASSERT(detail::compare_trange(arg, args...) && + "Tiled ranges of args must match"); typedef DistArray arg_array_type; typedef DistArray result_array_type; diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index b2c7f74d6a..aad2234fa9 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -207,25 +207,25 @@ class DistArray : public madness::archive::ParallelSerializableObject { pmap = Policy::default_pmap(world, trange.tiles_range().volume()); } else { // Validate the process map - TA_USER_ASSERT(pmap->size() == trange.tiles_range().volume(), - "Array::Array() -- The size of the process map is not " - "equal to the number of tiles in the TiledRange object."); - TA_USER_ASSERT( - pmap->rank() == typename pmap_interface::size_type(world.rank()), + TA_ASSERT(pmap->size() == trange.tiles_range().volume() && + "Array::Array() -- The size of the process map is not " + "equal to the number of tiles in the TiledRange object."); + TA_ASSERT( + pmap->rank() == typename pmap_interface::size_type(world.rank()) && "Array::Array() -- The rank of the process map is not equal to that " "of the world object."); - TA_USER_ASSERT( - pmap->procs() == typename pmap_interface::size_type(world.size()), + TA_ASSERT( + pmap->procs() == typename pmap_interface::size_type(world.size()) && "Array::Array() -- The number of processes in the process map is not " "equal to that of the world object."); } // Validate the shape - TA_USER_ASSERT(!shape.empty(), - "Array::Array() -- The shape is not initialized."); - TA_USER_ASSERT(shape.validate(trange.tiles_range()), - "Array::Array() -- The range of the shape is not equal to " - "the tiles range."); + TA_ASSERT(!shape.empty() && + "Array::Array() -- The shape is not initialized."); + TA_ASSERT(shape.validate(trange.tiles_range()) && + "Array::Array() -- The range of the shape is not equal to " + "the tiles range."); return std::shared_ptr(new impl_type(world, trange, shape, pmap), lazy_deleter); @@ -1434,16 +1434,16 @@ class DistArray : public madness::archive::ParallelSerializableObject { template std::enable_if_t, void> check_index( const Index i) const { - TA_USER_ASSERT( - impl_ref().tiles_range().includes(i), + TA_ASSERT( + impl_ref().tiles_range().includes(i) && "The ordinal index used to access an array tile is out of range."); } template std::enable_if_t, void> check_index( const Index& i) const { - TA_USER_ASSERT( - impl_ref().tiles_range().includes(i), + TA_ASSERT( + impl_ref().tiles_range().includes(i) && "The coordinate index used to access an array tile is out of range."); } @@ -1456,18 +1456,18 @@ class DistArray : public madness::archive::ParallelSerializableObject { std::enable_if_t, void> check_local_index( const Index i) const { check_index(i); - TA_USER_ASSERT( - pimpl_->is_local(i), // pimpl_ already checked - "The ordinal index used to access an array tile is not local."); + TA_ASSERT(pimpl_->is_local(i) // pimpl_ already checked + && + "The ordinal index used to access an array tile is not local."); } template std::enable_if_t, void> check_local_index( const Index& i) const { check_index(i); - TA_USER_ASSERT( - pimpl_->is_local(i), // pimpl_ already checked - "The coordinate index used to access an array tile is not local."); + TA_ASSERT( + pimpl_->is_local(i) // pimpl_ already checked + && "The coordinate index used to access an array tile is not local."); } template @@ -1510,9 +1510,9 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// Code factorization of the actual assert for the other overloads void assert_pimpl() const { - TA_USER_ASSERT(pimpl_, - "The Array has not been initialized, likely reason: it was " - "default constructed and used."); + TA_ASSERT(pimpl_ && + "The Array has not been initialized, likely reason: it was " + "default constructed and used."); } /// If this is in an initialized state this returns a const @@ -1605,9 +1605,8 @@ inline std::ostream& operator<<(std::ostream& os, return os; } - template -auto rank(const DistArray &a) { +auto rank(const DistArray& a) { return a.trange().tiles_range().rank(); } @@ -1632,7 +1631,8 @@ auto abs_max(const DistArray& a) { template auto dot(const DistArray& a, const DistArray& b) { return (a(detail::dummy_annotation(rank(a))) - .dot(b(detail::dummy_annotation(rank(b))))).get(); + .dot(b(detail::dummy_annotation(rank(b))))) + .get(); } template diff --git a/src/TiledArray/distributed_storage.h b/src/TiledArray/distributed_storage.h index 14839bcc2a..6189ce0f72 100644 --- a/src/TiledArray/distributed_storage.h +++ b/src/TiledArray/distributed_storage.h @@ -74,10 +74,8 @@ class DistributedStorage : public madness::WorldObject > { void set_handler(const size_type i, const value_type& value) { future& f = get_local(i); -#ifndef NDEBUG // Check that the future has not been set already. - if (f.probe()) TA_EXCEPTION("Tile has already been assigned."); -#endif // NDEBUG + TA_ASSERT(!f.probe() && "Tile has already been assigned."); f.set(value); } @@ -281,9 +279,7 @@ class DistributedStorage : public madness::WorldObject > { acc.release(); // Check that the future has not been set already. -#ifndef NDEBUG - if (existing_f.probe()) TA_EXCEPTION("Tile has already been assigned."); -#endif // NDEBUG + TA_ASSERT(!existing_f.probe() && "Tile has already been assigned."); // Set the future existing_f.set(f); } diff --git a/src/TiledArray/error.h b/src/TiledArray/error.h index ef5bf869ec..6012f64381 100644 --- a/src/TiledArray/error.h +++ b/src/TiledArray/error.h @@ -127,28 +127,4 @@ inline void exception_break() {} std::cerr << "!! ERROR TiledArray: " << m << "\n"; #endif // TILEDARRAY_NO_USER_ERROR_MESSAGES -#ifndef NDEBUG -// User interface assertion -#define TA_USER_ASSERT(a, m) \ - do { \ - if (!(a)) { \ - TA_USER_ERROR_MESSAGE(m) \ - TiledArray::exception_break(); \ - throw TiledArray::Exception(m); \ - } \ - } while (0) - -#else - -// Disable user interface assertion when NDEBUG is defined -// this avoids unused variable warnings, see -// http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ -#define TA_USER_ASSERT(a, m) \ - do { \ - (void)sizeof(a); \ - } while (0) -#define TA_USER_ASSERT_DISABLED 1 - -#endif - #endif // TILEDARRAY_ERROR_H__INCLUDED diff --git a/src/TiledArray/external/btas.h b/src/TiledArray/external/btas.h index 8a5c7497ef..ae706a7ba5 100644 --- a/src/TiledArray/external/btas.h +++ b/src/TiledArray/external/btas.h @@ -66,9 +66,9 @@ inline const TiledArray::Range& make_ta_range(const TiledArray::Range& range) { template inline TiledArray::Range make_ta_range( const btas::RangeNd& range) { - TA_USER_ASSERT(Order == CblasRowMajor, - "TiledArray::detail::make_ta_range(btas::RangeNd): " - "not supported for col-major Order"); + TA_ASSERT(Order == CblasRowMajor && + "TiledArray::detail::make_ta_range(btas::RangeNd): " + "not supported for col-major Order"); return TiledArray::Range(range.lobound(), range.upbound()); } @@ -632,11 +632,9 @@ inline btas::Tensor gemm( T factor_t(factor); - TiledArray::blas::gemm( - gemm_helper.left_op(), gemm_helper.right_op(), m, n, k, - factor_t, left.data(), lda, right.data(), ldb, T(0), - result.data(), n - ); + TiledArray::blas::gemm(gemm_helper.left_op(), gemm_helper.right_op(), m, n, k, + factor_t, left.data(), lda, right.data(), ldb, T(0), + result.data(), n); return result; } @@ -708,11 +706,9 @@ inline void gemm(btas::Tensor& result, T factor_t(factor); - TiledArray::blas::gemm( - gemm_helper.left_op(), gemm_helper.right_op(), m, n, k, - factor_t, left.data(), lda, right.data(), ldb, T(1), - result.data(), n - ); + TiledArray::blas::gemm(gemm_helper.left_op(), gemm_helper.right_op(), m, n, k, + factor_t, left.data(), lda, right.data(), ldb, T(1), + result.data(), n); } // sum of the hyperdiagonal elements diff --git a/src/TiledArray/external/madness.h b/src/TiledArray/external/madness.h index 277f06b84d..0bd27c05f0 100644 --- a/src/TiledArray/external/madness.h +++ b/src/TiledArray/external/madness.h @@ -52,9 +52,9 @@ namespace detail { struct default_world { static World& get() { if (!world()) { - TA_USER_ASSERT(madness::initialized(), - "TiledArray::detail::default_world::get() called " - "before madness::initialize()"); + TA_ASSERT(madness::initialized() && + "TiledArray::detail::default_world::get() called " + "before madness::initialize()"); world() = &madness::World::get_default(); } return *world(); diff --git a/src/TiledArray/math/linalg/diis.h b/src/TiledArray/math/linalg/diis.h index 723be23d4a..b1335e3666 100644 --- a/src/TiledArray/math/linalg/diis.h +++ b/src/TiledArray/math/linalg/diis.h @@ -26,8 +26,8 @@ #ifndef TILEDARRAY_MATH_LINALG_DIIS_H__INCLUDED #define TILEDARRAY_MATH_LINALG_DIIS_H__INCLUDED -#include "TiledArray/dist_array.h" #include +#include "TiledArray/dist_array.h" #include "TiledArray/external/eigen.h" #include @@ -142,7 +142,6 @@ class DIIS { /// \param extrapolate_error whether to extrapolate the error (default = /// false). void extrapolate(D& x, D& error, bool extrapolate_error = false) { - iter++; // compute extrapolation coefficients C_ and number of skipped vectors @@ -155,9 +154,9 @@ class DIIS { const unsigned int nvec = errors_.size(); // sizes of the x set and the error set should equal, otherwise throw - TA_USER_ASSERT(x_.size() == errors_.size(), - "DIIS: numbers of guess and error vectors do not match, " - "likely due to a programming error"); + TA_ASSERT(x_.size() == errors_.size() && + "DIIS: numbers of guess and error vectors do not match, " + "likely due to a programming error"); // extrapolate the error if needed if (extrapolate_error && (mixing_fraction == 0.0 || x_extrap_.empty())) { @@ -177,7 +176,6 @@ class DIIS { /// (default = false) void extrapolate(D& x, const Vector& c, unsigned int nskip = 0, bool increase_iter = false) { - if (increase_iter) { iter++; } @@ -207,8 +205,8 @@ class DIIS { const unsigned int nvec = x_.size(); const unsigned int rank = nvec - nskip + 1; // size of coefficients - TA_USER_ASSERT(c.size() == rank, - "DIIS: numbers of coefficients and x's do not match"); + TA_ASSERT(c.size() == rank && + "DIIS: numbers of coefficients and x's do not match"); zero(x); for (unsigned int k = nskip, kk = 1; k < nvec; ++k, ++kk) { if (not do_mixing || x_extrap_.empty()) { @@ -234,7 +232,6 @@ class DIIS { /// (default = false) void compute_extrapolation_parameters(const D& error, bool increase_iter = false) { - if (increase_iter) { iter++; } @@ -254,8 +251,7 @@ class DIIS { // and compute the most recent elements of B, B(i,j) = for (unsigned int i = 0; i < nvec - 1; i++) - B_(i, nvec - 1) = B_(nvec - 1, i) = - dot(errors_[i], errors_[nvec - 1]); + B_(i, nvec - 1) = B_(nvec - 1, i) = dot(errors_[i], errors_[nvec - 1]); B_(nvec - 1, nvec - 1) = dot(errors_[nvec - 1], errors_[nvec - 1]); using std::abs; using std::sqrt; @@ -356,9 +352,8 @@ class DIIS { /// calling this function returns extrapolation coefficients const Vector& get_coeffs() { - TA_USER_ASSERT( - parameters_computed_ && C_.size() > 0, - "DIIS: empty coefficients, because they have not been computed"); + TA_ASSERT(parameters_computed_ && C_.size() > 0 && + "DIIS: empty coefficients, because they have not been computed"); return C_; } @@ -384,8 +379,8 @@ class DIIS { //!< decreasing damping factor once //!< error 2-norm falls below this - Matrix B_; //!< B(i,j) = - Vector C_; //! DIIS coefficients + Matrix B_; //!< B(i,j) = + Vector C_; //! DIIS coefficients bool parameters_computed_; //! whether diis parameters C_ and nskip_ have //! been computed unsigned int nskip_; //! number of skipped vectors in extrapolation @@ -424,7 +419,7 @@ class DIIS { } // namespace TiledArray::math::linalg namespace TiledArray { - using TiledArray::math::linalg::DIIS; +using TiledArray::math::linalg::DIIS; } #endif // TILEDARRAY_MATH_LINALG_DIIS_H__INCLUDED diff --git a/src/TiledArray/range.h b/src/TiledArray/range.h index 1438f11c2b..eb8ac5cd53 100644 --- a/src/TiledArray/range.h +++ b/src/TiledArray/range.h @@ -659,8 +659,8 @@ class Range { /// Conversion to bool - /// \return false if is null state, i.e. \c this->volume()==0 - explicit operator bool() const { return volume() != 0; } + /// \return false if is null state, i.e. \c this->rank()==0 + explicit operator bool() const { return rank() != 0; } /// Rank accessor @@ -824,6 +824,7 @@ class Range { typename std::enable_if, bool>::type* = nullptr> bool includes(const Index& index) const { + TA_ASSERT(*this); const auto* MADNESS_RESTRICT const lower = lobound_data(); const auto* MADNESS_RESTRICT const upper = upbound_data(); @@ -869,6 +870,7 @@ class Range { template typename std::enable_if, bool>::type includes( Ordinal i) const { + TA_ASSERT(*this); return include_ordinal_(i); } diff --git a/src/TiledArray/tensor/utility.h b/src/TiledArray/tensor/utility.h index 6a4d6efda9..6ba90f2fb3 100644 --- a/src/TiledArray/tensor/utility.h +++ b/src/TiledArray/tensor/utility.h @@ -325,10 +325,10 @@ inline constexpr bool empty() { return true; } /// \tparam Ts The remaining tensor types /// \param tensor1 The first tensor to test /// \param tensors The remaining tensors to test -/// \return \c true if one or more tensors are empty +/// \return \c true if one _or_ more tensors are empty template inline bool empty(const T1& tensor1, const Ts&... tensors) { - return tensor1.empty() && empty(tensors...); + return tensor1.empty() || empty(tensors...); } } // namespace detail diff --git a/src/TiledArray/tiled_range1.h b/src/TiledArray/tiled_range1.h index 89e3d91375..ed61147205 100644 --- a/src/TiledArray/tiled_range1.h +++ b/src/TiledArray/tiled_range1.h @@ -66,8 +66,10 @@ class TiledRange1 { TiledRange1() : range_(0, 0), elements_range_(0, 0), tiles_ranges_(), elem2tile_() {} - /// Constructs a range with the boundaries provided by [first, last). - /// Start_tile_index is the index of the first tile. + /// Constructs a range with the boundaries provided by + /// the range [ \p first , \p last ). + /// \note validity of the [ \p first , \p last ) range is checked using + /// #TA_ASSERT() only if preprocessor macro \c NDEBUG is not defined template ::value>::type* = nullptr> @@ -84,11 +86,14 @@ class TiledRange1 { /// Construct a 1D tiled range. - /// This will construct a 1D tiled range with tile boundaries {t0, t_rest} + /// This will construct a 1D tiled range with tile boundaries + /// {\p t0 , \p t_rest... } /// The number of tile boundaries is n + 1, where n is the number of tiles. - /// Tiles are defined as [t0, t1), [t1, t2), [t2, t3), ... + /// Tiles are defined as [\p t0, t1), [t1, t2), [t2, t3), ... /// \param t0 The starting index of the first tile /// \param t_rest The rest of tile boundaries + /// \note validity of the {\p t0 , \p t_rest... } range is checked using + /// #TA_ASSERT() only if preprocessor macro \c NDEBUG is not defined template explicit TiledRange1(const index1_type& t0, const _sizes&... t_rest) { const auto n = sizeof...(_sizes) + 1; @@ -98,12 +103,15 @@ class TiledRange1 { /// Construct a 1D tiled range. - /// This will construct a 1D tiled range with tile boundaries {t0, t_rest} + /// This will construct a 1D tiled range with tile boundaries + /// {\p t0 , \p t_rest... } /// The number of tile boundaries is n + 1, where n is the number of tiles. - /// Tiles are defined as [t0, t1), [t1, t2), [t2, t3), ... + /// Tiles are defined as [\p t0 , t1), [t1, t2), [t2, t3), ... /// Tiles are indexed starting with 0. /// \tparam Integer An integral type /// \param list The list of tile boundaries in order from smallest to largest + /// \note validity of the {\p t0 , \p t_rest... } range is checked using + /// #TA_ASSERT() only if preprocessor macro \c NDEBUG is not defined template >> explicit TiledRange1(const std::initializer_list& list) { @@ -230,18 +238,18 @@ class TiledRange1 { template static void valid_(RandIter first, RandIter last) { // Verify at least 2 elements are present if the vector is not empty. - TA_USER_ASSERT((std::distance(first, last) >= 2), - "TiledRange1 construction failed: You need at least 2 " - "elements in the tile boundary list."); + TA_ASSERT((std::distance(first, last) >= 2) && + "TiledRange1 construction failed: You need at least 2 " + "elements in the tile boundary list."); // Verify the requirement that a0 < a1 < a2 < ... for (; first != (last - 1); ++first) { - TA_USER_ASSERT( - *first < *(first + 1), + TA_ASSERT( + *first < *(first + 1) && "TiledRange1 construction failed: Invalid tile boundary, tile " "boundary i must be greater than tile boundary i+1 for all i. "); - TA_USER_ASSERT( + TA_ASSERT( static_cast(*first) < - static_cast(*(first + 1)), + static_cast(*(first + 1)) && "TiledRange1 construction failed: Invalid tile boundary, tile " "boundary i must be greater than tile boundary i+1 for all i. "); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cb82b27627..0bec5e9e3f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,7 +60,7 @@ set(ta_test_src_files ta_test.cpp cyclic_pmap.cpp replicated_pmap.cpp dense_shape.cpp - #sparse_shape.cpp + sparse_shape.cpp distributed_storage.cpp tensor_impl.cpp array_impl.cpp @@ -97,8 +97,8 @@ set(ta_test_src_files ta_test.cpp initializer_list.cpp diagonal_array.cpp retile.cpp - # tot_dist_array_part1.cpp - # tot_dist_array_part2.cpp + tot_dist_array_part1.cpp + tot_dist_array_part2.cpp random.cpp trace.cpp tot_expressions.cpp @@ -143,9 +143,10 @@ target_include_directories(${executable} PRIVATE ) # unit tests # 1. should disable error messages -# 2. must emit exceptions in asserts since some tests check for exceptions +# N.B. used to manually define TA_EXCEPTION_ERROR here; since some code is now compiled (rather than is header-only) it +# is too late to do this here; must set TA_ERROR=throw if want to run unit tests target_compile_definitions(${executable} PRIVATE TILEDARRAY_NO_USER_ERROR_MESSAGES=1 - TA_EXCEPTION_ERROR=1 MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE=0) + MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE=0) # optional dependencies if (TARGET range-v3::range-v3) target_link_libraries(${executable} PRIVATE range-v3::range-v3) diff --git a/tests/bitset.cpp b/tests/bitset.cpp index 84451555c4..6153b6b972 100644 --- a/tests/bitset.cpp +++ b/tests/bitset.cpp @@ -98,12 +98,10 @@ BOOST_AUTO_TEST_CASE(accessor) { // check that all bits are correctly initialized to false. for (std::size_t i = 0; i < set.size(); ++i) BOOST_CHECK(!set[i]); - // Check that exceptions are thrown when accessing an element that is out of - // range. -#ifdef TA_EXCEPTION_ERROR + // Check that exceptions are thrown when accessing an element that is out of + // range. BOOST_CHECK_THROW(set[set.size()], Exception); BOOST_CHECK_THROW(set[set.size() + 1], Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(set_bit) { @@ -144,10 +142,8 @@ BOOST_AUTO_TEST_CASE(set_bit) { // Check that exceptions are thrown when accessing an element that is out of // range. -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(set.set(set.size()), Exception); BOOST_CHECK_THROW(set.set(set.size() + 1), Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(set_all) { @@ -236,10 +232,8 @@ BOOST_AUTO_TEST_CASE(reset_bit) { // Check that exceptions are thrown when accessing an element that is out of // range. -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(set.reset(set.size()), Exception); BOOST_CHECK_THROW(set.reset(set.size() + 1), Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(reset_all) { @@ -285,10 +279,8 @@ BOOST_AUTO_TEST_CASE(bit_flip) { // Check that exceptions are thrown when accessing an element that is out of // range. -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(set.flip(set.size()), Exception); BOOST_CHECK_THROW(set.flip(set.size() + 1), Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(flip_all) { @@ -400,12 +392,10 @@ BOOST_AUTO_TEST_CASE(bit_assignment) { } // Check that assignment of bitsets with different size throws. -#ifdef TA_EXCEPTION_ERROR Bitset bad(size / 2); BOOST_CHECK_THROW(bad &= set, Exception); BOOST_CHECK_THROW(bad |= set, Exception); BOOST_CHECK_THROW(bad ^= set, Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(bit_operators) { @@ -471,12 +461,10 @@ BOOST_AUTO_TEST_CASE(bit_operators) { } // Check that assignment of bitsets with different size throws. -#ifdef TA_EXCEPTION_ERROR Bitset bad(size / 2); BOOST_CHECK_THROW(bad & set, Exception); BOOST_CHECK_THROW(bad | set, Exception); BOOST_CHECK_THROW(bad ^ set, Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(left_shift_assign) { diff --git a/tests/block_range.cpp b/tests/block_range.cpp index 8d8205e220..c20fb4af3e 100644 --- a/tests/block_range.cpp +++ b/tests/block_range.cpp @@ -56,11 +56,10 @@ BOOST_AUTO_TEST_CASE(block_zero_lower_bound) { auto count_valid = 0; auto count_invalid = 0; - auto skip = []() { - return GlobalFixture::world->rand() % 20 > 9; - }; + auto skip = []() { return GlobalFixture::world->rand() % 20 > 9; }; - // loop over all possible subblocks, skipping randomly, until target_count valid+invalid block ranges have been considered + // loop over all possible subblocks, skipping randomly, until target_count + // valid+invalid block ranges have been considered for (auto lower_it = r0.begin(); lower_it != r0.end(); ++lower_it) { const auto lower = *lower_it; for (auto upper_it = r0.begin(); upper_it != r0.end(); ++upper_it) { @@ -109,21 +108,16 @@ BOOST_AUTO_TEST_CASE(block_zero_lower_bound) { // Check that the index returned by idx is correct BOOST_CHECK_EQUAL(block_range.idx(index), *it); } - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { if (count_invalid == target_count) continue; ++count_invalid; // Check for exception with invalid input BOOST_CHECK_THROW(BlockRange(r0, lower, upper), TiledArray::Exception); } -#else // TA_EXCEPTION_ERROR - count_invalid = target_count; -#endif // TA_EXCEPTION_ERROR } } - end: ; +end:; } BOOST_AUTO_TEST_CASE(block) { @@ -131,11 +125,10 @@ BOOST_AUTO_TEST_CASE(block) { auto count_valid = 0; auto count_invalid = 0; - auto skip = []() { - return GlobalFixture::world->rand() % 20 > 9; - }; + auto skip = []() { return GlobalFixture::world->rand() % 20 > 9; }; - // loop over all possible subblocks, skipping randomly, until target_count valid+invalid block ranges have been considered + // loop over all possible subblocks, skipping randomly, until target_count + // valid+invalid block ranges have been considered for (auto lower_it = r.begin(); lower_it != r.end(); ++lower_it) { const auto lower = *lower_it; for (auto upper_it = r.begin(); upper_it != r.end(); ++upper_it) { @@ -264,21 +257,16 @@ BOOST_AUTO_TEST_CASE(block) { BOOST_CHECK_EQUAL(br6, bref); } } - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { if (count_invalid == target_count) continue; ++count_invalid; // Check for exception with invalid input BOOST_CHECK_THROW(BlockRange(r, lower, upper), TiledArray::Exception); } -#else // TA_EXCEPTION_ERROR - count_invalid = target_count; -#endif // TA_EXCEPTION_ERROR } } - end: ; +end:; } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/btas.cpp b/tests/btas.cpp index ac33e6ad57..4f8157fba5 100644 --- a/tests/btas.cpp +++ b/tests/btas.cpp @@ -318,12 +318,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(dense_array_conversion, bTensor, tensor_types) { using TArray = TiledArray::TArray; TArray dst; const auto replicated = true; -#if !defined(TA_USER_ASSERT_DISABLED) if (GlobalFixture::world->size() > 1) BOOST_REQUIRE_THROW(dst = btas_tensor_to_array( *GlobalFixture::world, trange, src, not replicated), TiledArray::Exception); -#endif BOOST_REQUIRE_NO_THROW(dst = btas_tensor_to_array( *GlobalFixture::world, trange, src, replicated)); @@ -381,12 +379,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(sparse_array_conversion, bTensor, tensor_types) { using TSpArray = TiledArray::TSpArray; TSpArray dst; const auto replicated = true; -#if !defined(TA_USER_ASSERT_DISABLED) if (GlobalFixture::world->size() > 1) BOOST_REQUIRE_THROW(dst = btas_tensor_to_array( *GlobalFixture::world, trange, src, not replicated), TiledArray::Exception); -#endif BOOST_REQUIRE_NO_THROW(dst = btas_tensor_to_array( *GlobalFixture::world, trange, src, replicated)); diff --git a/tests/cyclic_pmap.cpp b/tests/cyclic_pmap.cpp index 3798b3a1c5..509b9f92bf 100644 --- a/tests/cyclic_pmap.cpp +++ b/tests/cyclic_pmap.cpp @@ -58,7 +58,6 @@ BOOST_AUTO_TEST_CASE(constructor) { } } -#ifdef TA_EXCEPTION_ERROR ProcessID size = GlobalFixture::world->size(); BOOST_CHECK_THROW(TiledArray::detail::CyclicPmap pmap(*GlobalFixture::world, @@ -84,7 +83,6 @@ BOOST_AUTO_TEST_CASE(constructor) { *GlobalFixture::world, 10ul, 10ul, size, size), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(owner) { diff --git a/tests/dist_array.cpp b/tests/dist_array.cpp index 9cc45ae92b..223380c2b1 100644 --- a/tests/dist_array.cpp +++ b/tests/dist_array.cpp @@ -385,11 +385,9 @@ BOOST_AUTO_TEST_CASE(find_local) { } } else { -#ifdef TA_EXCEPTION_ERROR // Check that an exception is thrown when using a default constructed // object BOOST_CHECK_THROW(a.find_local(tile_idx), TiledArray::Exception); -#endif // TA_EXCEPTION_ERROR } } } diff --git a/tests/dist_op_group.cpp b/tests/dist_op_group.cpp index 6c00d98d86..8027eab7e1 100644 --- a/tests/dist_op_group.cpp +++ b/tests/dist_op_group.cpp @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(constructor_empty) { BOOST_CHECK(empty_group.empty()); BOOST_CHECK_EQUAL(empty_group.size(), 0); -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) +#if defined(MADNESS_ASSERTIONS_THROW) // Check that accessing group data throws exceptions for an empty group. BOOST_CHECK_THROW(empty_group.id(), madness::MadnessException); BOOST_CHECK_THROW(empty_group.get_world(), madness::MadnessException); @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(constructor_empty) { ProcessID parent, child1, child2; BOOST_CHECK_THROW(empty_group.make_tree(0, parent, child1, child2), madness::MadnessException); -#endif // TA_EXCEPTION_ERROR +#endif // MADNESS_ASSERTIONS_THROW } BOOST_AUTO_TEST_CASE(constructor_new_group) { diff --git a/tests/distributed_storage.cpp b/tests/distributed_storage.cpp index 6ec332250c..b5a82121c1 100644 --- a/tests/distributed_storage.cpp +++ b/tests/distributed_storage.cpp @@ -79,10 +79,8 @@ BOOST_AUTO_TEST_CASE(set_value) { BOOST_CHECK_EQUAL(n, t.max_size()); // Check throw for an out-of-range set. -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(t.set(t.max_size(), 1), TiledArray::Exception); BOOST_CHECK_THROW(t.set(t.max_size() + 2, 1), TiledArray::Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(array_operator) { @@ -99,10 +97,8 @@ BOOST_AUTO_TEST_CASE(array_operator) { BOOST_CHECK_EQUAL(n, t.max_size()); // Check throw for an out-of-range set. -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(t.get(t.max_size()), TiledArray::Exception); BOOST_CHECK_THROW(t.get(t.max_size() + 2), TiledArray::Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/eigen.cpp b/tests/eigen.cpp index 37eef88220..4d25461e4b 100644 --- a/tests/eigen.cpp +++ b/tests/eigen.cpp @@ -238,9 +238,7 @@ BOOST_AUTO_TEST_CASE(array_to_matrix) { } } else { // Check that eigen_to_array throws when there is more than one node -#if !defined(TA_USER_ASSERT_DISABLED) BOOST_CHECK_THROW(array_to_eigen(array), TiledArray::Exception); -#endif // Fill local tiles with data GlobalFixture::world->srand(27); @@ -322,9 +320,7 @@ BOOST_AUTO_TEST_CASE(array_to_vector) { } } else { // Check that eigen_to_array throws when there is more than one node -#if !defined(TA_USER_ASSERT_DISABLED) BOOST_CHECK_THROW(array_to_eigen(array1), TiledArray::Exception); -#endif // Fill local tiles with data GlobalFixture::world->srand(27); diff --git a/tests/index_list.cpp b/tests/index_list.cpp index 5c7523ca4b..bd3ea6466e 100644 --- a/tests/index_list.cpp +++ b/tests/index_list.cpp @@ -170,13 +170,11 @@ BOOST_AUTO_TEST_CASE(constructor) { BOOST_CHECK_EQUAL(v10.at(2), "c"); BOOST_CHECK_EQUAL(v10.at(3), "d"); -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(IndexList v3(",a,b,c"), Exception); // check invalid input BOOST_CHECK_THROW(IndexList v4("a,,b,c"), Exception); BOOST_CHECK_THROW(IndexList v5(" ,a,b"), Exception); BOOST_CHECK_THROW(IndexList v6("a, b, , c"), Exception); -#endif // TA_EXCEPTION_ERROR IndexList v7(" a , b, c, d , e e ,f f, g10,h, i "); // check input with // various spacings. diff --git a/tests/initializer_list.cpp b/tests/initializer_list.cpp index a95afac4bd..0fde6f207d 100644 --- a/tests/initializer_list.cpp +++ b/tests/initializer_list.cpp @@ -196,11 +196,9 @@ BOOST_AUTO_TEST_CASE(scalar) { } BOOST_AUTO_TEST_CASE(empty_vector) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) vector_il il{}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(tiled_range_from_il(il), Exception); -#endif } BOOST_AUTO_TEST_CASE(vector) { @@ -303,12 +301,10 @@ BOOST_AUTO_TEST_CASE(vector) { } BOOST_AUTO_TEST_CASE(bad_matrix) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) std::array buffer{}; matrix_il il{{1, 2}, {3, 4, 5}}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(flatten_il(il, buffer.begin()), Exception); -#endif } BOOST_AUTO_TEST_CASE(empty_matrix) { @@ -531,11 +527,9 @@ BOOST_AUTO_TEST_CASE(scalar) { } BOOST_AUTO_TEST_CASE_TEMPLATE(empty_vector, T, scalar_type_list) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) vector_il il{}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(array_from_il>(world, il), Exception); -#endif } BOOST_AUTO_TEST_CASE_TEMPLATE(vector, T, scalar_type_list) { @@ -548,19 +542,15 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(vector, T, scalar_type_list) { } BOOST_AUTO_TEST_CASE_TEMPLATE(empty_matrix, T, scalar_type_list) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) matrix_il il{{}}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(array_from_il>(world, il), Exception); -#endif } BOOST_AUTO_TEST_CASE_TEMPLATE(bad_matrix, T, scalar_type_list) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) matrix_il il{{1, 2}, {3, 4, 5}}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(array_from_il>(world, il), Exception); -#endif } BOOST_AUTO_TEST_CASE_TEMPLATE(square_matrix, T, scalar_type_list) { @@ -609,19 +599,15 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(short_matrix, T, scalar_type_list) { } BOOST_AUTO_TEST_CASE_TEMPLATE(empty_rank3, T, scalar_type_list) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) tensor3_il il{{{}}}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(array_from_il>(world, il), Exception); -#endif } BOOST_AUTO_TEST_CASE_TEMPLATE(bad_rank3, T, scalar_type_list) { -#if defined(TA_EXCEPTION_ERROR) && defined(MADNESS_ASSERTIONS_THROW) tensor3_il il{{{1, 2}, {3, 4, 5}}}; if (world.rank() == 0) // only rank 0 does the work BOOST_CHECK_THROW(array_from_il>(world, il), Exception); -#endif } BOOST_AUTO_TEST_CASE_TEMPLATE(square_rank3, T, scalar_type_list) { diff --git a/tests/perm_index.cpp b/tests/perm_index.cpp index 10644e84be..7b25637d15 100644 --- a/tests/perm_index.cpp +++ b/tests/perm_index.cpp @@ -60,10 +60,8 @@ BOOST_AUTO_TEST_CASE(default_constructor) { BOOST_CHECK(!bool(x)); BOOST_CHECK(!x.data()); -#ifdef TA_EXCEPTION_ERROR // Check that an exception is thrown when using a default constructed object BOOST_CHECK_THROW(x(0), TiledArray::Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(constructor) { diff --git a/tests/range.cpp b/tests/range.cpp index afbac08106..4029a1d500 100644 --- a/tests/range.cpp +++ b/tests/range.cpp @@ -152,9 +152,7 @@ BOOST_AUTO_TEST_CASE(constructors) { Range r(ranges::views::zip(p2, f2))); // uses zipped range of p2 and f2 #endif -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(Range r2(f2, p2), Exception); // lobound > upbound -#endif // TA_EXCEPTION_ERROR Range r2(p2, f2); BOOST_CHECK_EQUAL_COLLECTIONS( r2.lobound_data(), r2.lobound_data() + r2.rank(), p2.begin(), p2.end()); @@ -179,10 +177,8 @@ BOOST_AUTO_TEST_CASE(constructors) { // test the rest of bound-based ctors { Range ref({0, 1, 2}, {4, 6, 8}); -#ifdef TA_EXCEPTION_ERROR // BOOST_CHECK_THROW(Range ref{{0, 1, 2}, {4, 6, 8}}, Exception); // mind // the parens! -#endif // TA_EXCEPTION_ERROR // uses initializer_list of pairs BOOST_REQUIRE_NO_THROW( @@ -326,10 +322,8 @@ BOOST_AUTO_TEST_CASE(constructors) { BOOST_CHECK_EQUAL(r2.volume(), 48); } #else // TA_SIGNED_1INDEX_TYPE -#ifdef TA_EXCEPTION_ERROR BOOST_REQUIRE_THROW(Range r2({{-1, 1}, {-2, 2}, {0, 6}}), TiledArray::Exception); -#endif #endif // TA_SIGNED_1INDEX_TYPE // Copy Constructor diff --git a/tests/sparse_shape.cpp b/tests/sparse_shape.cpp index 76b50580d8..5aa89c93d8 100644 --- a/tests/sparse_shape.cpp +++ b/tests/sparse_shape.cpp @@ -48,7 +48,6 @@ BOOST_AUTO_TEST_CASE(default_constructor) { BOOST_CHECK(!x.is_dense()); BOOST_CHECK(!x.validate(tr.tiles_range())); -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(x[0], Exception); BOOST_CHECK_THROW(x.perm(perm), Exception); @@ -77,7 +76,6 @@ BOOST_AUTO_TEST_CASE(default_constructor) { BOOST_CHECK_THROW(x.gemm(y, 2.0, gemm_helper), Exception); BOOST_CHECK_THROW(x.gemm(y, 2.0, gemm_helper, perm), Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(non_comm_constructor) { @@ -324,14 +322,11 @@ BOOST_AUTO_TEST_CASE(block) { auto result4 = sparse_shape.block(ranges::views::zip(lower, upper)); BOOST_CHECK_EQUAL(result, result4); #endif - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { // Check that block throws an exception with a bad block range BOOST_CHECK_THROW(sparse_shape.block(lower, upper), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR } } } @@ -419,14 +414,11 @@ BOOST_AUTO_TEST_CASE(block_scale) { BOOST_CHECK_EQUAL(result, result4); #endif - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { // Check that block throws an exception with a bad block range BOOST_CHECK_THROW(sparse_shape.block(lower, upper), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR } } } @@ -516,14 +508,11 @@ BOOST_AUTO_TEST_CASE(block_perm) { BOOST_CHECK_EQUAL(result, result4); #endif - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { // Check that block throws an exception with a bad block range BOOST_CHECK_THROW(sparse_shape.block(lower, upper), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR } } } @@ -617,14 +606,11 @@ BOOST_AUTO_TEST_CASE(block_scale_perm) { BOOST_CHECK_EQUAL(result, result4); #endif - } -#ifdef TA_EXCEPTION_ERROR - else { + } else { // Check that block throws an exception with a bad block range BOOST_CHECK_THROW(sparse_shape.block(lower, upper), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR } } } diff --git a/tests/ta_test.cpp b/tests/ta_test.cpp index 40700c6b62..c342e7523a 100644 --- a/tests/ta_test.cpp +++ b/tests/ta_test.cpp @@ -23,6 +23,12 @@ #include "TiledArray/external/madness.h" #include "unit_test_config.h" +#include +#ifndef TA_EXCEPTION_ERROR +#error \ + "TiledArray unit tests can only be built if CMake variable TA_ERROR is set of \"throw\"" +#endif + GlobalFixture::GlobalFixture() { if (world == nullptr) { world = &TiledArray::initialize( diff --git a/tests/tensor.cpp b/tests/tensor.cpp index cdc6771ec9..15c74aafe3 100644 --- a/tests/tensor.cpp +++ b/tests/tensor.cpp @@ -51,9 +51,7 @@ BOOST_AUTO_TEST_CASE(default_constructor) { const_cast(x).end()); // check for element access error -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(x[0], Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(range_constructor) { @@ -327,10 +325,8 @@ BOOST_AUTO_TEST_CASE(element_access) { #endif // check out of range error -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(t[r.upbound()], Exception); BOOST_CHECK_THROW(t[r.volume()], Exception); -#endif // TA_EXCEPTION_ERROR } BOOST_AUTO_TEST_CASE(iteration) { diff --git a/tests/tile_op_contract_reduce.cpp b/tests/tile_op_contract_reduce.cpp index 56e000a792..2f39516a02 100644 --- a/tests/tile_op_contract_reduce.cpp +++ b/tests/tile_op_contract_reduce.cpp @@ -93,7 +93,6 @@ BOOST_AUTO_TEST_CASE(make_result) { BOOST_CHECK(result.empty()); } -#ifdef TA_EXCEPTION_ERROR BOOST_AUTO_TEST_CASE(permute_empty) { // Check the seed operation produces an empty tensor. ContractReduce op( @@ -101,7 +100,6 @@ BOOST_AUTO_TEST_CASE(permute_empty) { TensorI t, result; BOOST_REQUIRE_THROW(result = op(t), TiledArray::Exception); } -#endif // TA_EXCEPTION_ERROR // TODO: Test non-empty permutation diff --git a/tests/tiled_range1.cpp b/tests/tiled_range1.cpp index f6e3c27e06..c47f22bc30 100644 --- a/tests/tiled_range1.cpp +++ b/tests/tiled_range1.cpp @@ -60,9 +60,7 @@ BOOST_AUTO_TEST_CASE(constructor) { BOOST_CHECK_EQUAL(r.tiles_range().second, 0ul); BOOST_CHECK_EQUAL(r.elements_range().first, 0ul); BOOST_CHECK_EQUAL(r.elements_range().second, 0ul); -#ifdef TA_EXCEPTION_ERROR BOOST_CHECK_THROW(r.tile(0), Exception); -#endif // TA_EXCEPTION_ERROR } // check construction with a iterators and the range info. @@ -122,10 +120,8 @@ BOOST_AUTO_TEST_CASE(constructor) { BOOST_CHECK_EQUAL(r.elements_range().second, 28); } #else // TA_SIGNED_1INDEX_TYPE -#if !defined(TA_USER_ASSERT_DISABLED) BOOST_CHECK_THROW(TiledRange1 r({-1, 0, 2, 5, 10, 17, 28}), TiledArray::Exception); -#endif #endif // TA_SIGNED_1INDEX_TYPE // check copy constructor @@ -157,8 +153,8 @@ BOOST_AUTO_TEST_CASE(constructor) { } // Check that invalid input throws an exception. - { #ifndef NDEBUG + { std::vector boundaries; BOOST_CHECK_THROW(TiledRange1 r(boundaries.begin(), boundaries.end()), Exception); @@ -168,8 +164,8 @@ BOOST_AUTO_TEST_CASE(constructor) { boundaries.push_back(0); BOOST_CHECK_THROW(TiledRange1 r(boundaries.begin(), boundaries.end()), Exception); -#endif // NDEBUG } +#endif } BOOST_AUTO_TEST_CASE(ostream) {