From 93777dce24818ec2122fe5b0290d172cb540a2e2 Mon Sep 17 00:00:00 2001 From: Marcel Koch Date: Wed, 6 Dec 2023 08:25:04 +0000 Subject: [PATCH] review updates: - use this-> - use assert_eq instead of compatible_bounds - remove compatible_bounds Co-authored-by: Pratik Nayak --- core/matrix/coo.cpp | 10 +++++----- core/matrix/csr.cpp | 10 +++++----- core/test/base/array.cpp | 6 +++--- include/ginkgo/core/base/array.hpp | 6 +++--- .../ginkgo/core/base/exception_helpers.hpp | 19 ------------------- 5 files changed, 16 insertions(+), 35 deletions(-) diff --git a/core/matrix/coo.cpp b/core/matrix/coo.cpp index d34a4f238f9..91f0360ad68 100644 --- a/core/matrix/coo.cpp +++ b/core/matrix/coo.cpp @@ -185,11 +185,11 @@ void Coo::read(const mat_data& data) auto size = data.size; auto exec = this->get_executor(); this->set_size(size); - row_idxs_.resize_and_reset(data.nonzeros.size()); - col_idxs_.resize_and_reset(data.nonzeros.size()); - values_.resize_and_reset(data.nonzeros.size()); - device_mat_data view{exec, size, row_idxs_.as_view(), col_idxs_.as_view(), - values_.as_view()}; + this->row_idxs_.resize_and_reset(data.nonzeros.size()); + this->col_idxs_.resize_and_reset(data.nonzeros.size()); + this->values_.resize_and_reset(data.nonzeros.size()); + device_mat_data view{exec, size, this->row_idxs_.as_view(), + this->col_idxs_.as_view(), this->values_.as_view()}; const auto host_data = make_array_view(exec->get_master(), data.nonzeros.size(), const_cast*>( diff --git a/core/matrix/csr.cpp b/core/matrix/csr.cpp index 2a1bf7cecd7..96f72059ce5 100644 --- a/core/matrix/csr.cpp +++ b/core/matrix/csr.cpp @@ -427,15 +427,15 @@ void Csr::read(const mat_data& data) auto size = data.size; auto exec = this->get_executor(); this->set_size(size); - row_ptrs_.resize_and_reset(size[0] + 1); - col_idxs_.resize_and_reset(data.nonzeros.size()); - values_.resize_and_reset(data.nonzeros.size()); + this->row_ptrs_.resize_and_reset(size[0] + 1); + this->col_idxs_.resize_and_reset(data.nonzeros.size()); + this->values_.resize_and_reset(data.nonzeros.size()); // the device matrix data contains views on the column indices // and values array of this matrix, and an owning array for the // row indices (which doesn't exist in this matrix) device_mat_data view{exec, size, array{exec, data.nonzeros.size()}, - col_idxs_.as_view(), values_.as_view()}; + this->col_idxs_.as_view(), this->values_.as_view()}; const auto host_data = make_array_view(exec->get_master(), data.nonzeros.size(), const_cast*>( @@ -444,7 +444,7 @@ void Csr::read(const mat_data& data) csr::make_aos_to_soa(*make_temporary_clone(exec, &host_data), view)); exec->run(csr::make_convert_idxs_to_ptrs(view.get_const_row_idxs(), view.get_num_stored_elements(), - size[0], get_row_ptrs())); + size[0], this->get_row_ptrs())); this->make_srow(); } diff --git a/core/test/base/array.cpp b/core/test/base/array.cpp index 1ea0b601ae4..a47138a15c7 100644 --- a/core/test/base/array.cpp +++ b/core/test/base/array.cpp @@ -498,7 +498,7 @@ TYPED_TEST(Array, CopyViewToView) EXPECT_EQ(view.get_size(), 3); EXPECT_EQ(view2.get_size(), 3); EXPECT_EQ(view2.get_data()[0], TypeParam{2}); - ASSERT_THROW(view2 = view_size4, gko::OutOfBoundsError); + ASSERT_THROW(view2 = view_size4, gko::ValueMismatch); } @@ -534,8 +534,8 @@ TYPED_TEST(Array, CopyArrayToView) EXPECT_EQ(data[1], TypeParam{4}); EXPECT_EQ(view.get_size(), 2); EXPECT_EQ(array_size2.get_size(), 2); - ASSERT_THROW(view = array_size1, gko::OutOfBoundsError); - ASSERT_THROW(view = array_size4, gko::OutOfBoundsError); + ASSERT_THROW(view = array_size1, gko::ValueMismatch); + ASSERT_THROW(view = array_size4, gko::ValueMismatch); } diff --git a/include/ginkgo/core/base/array.hpp b/include/ginkgo/core/base/array.hpp index 9e1e8337a65..f85e561df44 100644 --- a/include/ginkgo/core/base/array.hpp +++ b/include/ginkgo/core/base/array.hpp @@ -441,7 +441,7 @@ class array { if (this->is_owning()) { this->resize_and_reset(other.get_size()); } else { - GKO_ENSURE_COMPATIBLE_BOUNDS(other.get_size(), this->get_size()); + GKO_ASSERT_EQ(other.get_size(), this->get_size()); } exec_->copy_from(other.get_executor(), other.get_size(), other.get_const_data(), this->get_data()); @@ -536,7 +536,7 @@ class array { if (this->is_owning()) { this->resize_and_reset(other.get_size()); } else { - GKO_ENSURE_COMPATIBLE_BOUNDS(other.get_size(), this->get_size()); + GKO_ASSERT_EQ(other.get_size(), this->get_size()); } array tmp{this->exec_}; const OtherValueType* source = other.get_const_data(); @@ -582,7 +582,7 @@ class array { if (this->is_owning()) { this->resize_and_reset(other.get_size()); } else { - GKO_ENSURE_COMPATIBLE_BOUNDS(other.get_size(), this->get_size()); + GKO_ASSERT_EQ(other.get_size(), this->get_size()); } array tmp{this->exec_}; const ValueType* source = other.get_const_data(); diff --git a/include/ginkgo/core/base/exception_helpers.hpp b/include/ginkgo/core/base/exception_helpers.hpp index 64bbdb1ac1e..10c1f98abd6 100644 --- a/include/ginkgo/core/base/exception_helpers.hpp +++ b/include/ginkgo/core/base/exception_helpers.hpp @@ -755,25 +755,6 @@ inline T ensure_allocated_impl(T ptr, const std::string& file, int line, "semi-colon warnings") -/** - * Ensures that two dimensions have compatible bounds, in particular before a - * copy operation. This means the target should have the same number of elements - * as the source. - * - * @param _source the source of the expected copy operation - * @param _target the destination of the expected copy operation - * - * @throw OutOfBoundsError if `_source != _target` - */ -#define GKO_ENSURE_COMPATIBLE_BOUNDS(_source, _target) \ - if ((_source) != (_target)) { \ - throw ::gko::OutOfBoundsError(__FILE__, __LINE__, _source, _target); \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") - - /** * Creates a StreamError exception. * This macro sets the correct information about the location of the error