Skip to content

Commit

Permalink
review updates:
Browse files Browse the repository at this point in the history
- use this->
- use assert_eq instead of compatible_bounds
- remove compatible_bounds

Co-authored-by: Pratik Nayak <[email protected]>
  • Loading branch information
MarcelKoch and pratikvn committed Dec 6, 2023
1 parent 665cca0 commit 93777dc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 35 deletions.
10 changes: 5 additions & 5 deletions core/matrix/coo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ void Coo<ValueType, IndexType>::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<matrix_data_entry<ValueType, IndexType>*>(
Expand Down
10 changes: 5 additions & 5 deletions core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ void Csr<ValueType, IndexType>::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<IndexType>{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<matrix_data_entry<ValueType, IndexType>*>(
Expand All @@ -444,7 +444,7 @@ void Csr<ValueType, IndexType>::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();
}

Expand Down
6 changes: 3 additions & 3 deletions core/test/base/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
}


Expand Down
6 changes: 3 additions & 3 deletions include/ginkgo/core/base/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<OtherValueType> tmp{this->exec_};
const OtherValueType* source = other.get_const_data();
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 0 additions & 19 deletions include/ginkgo/core/base/exception_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93777dc

Please sign in to comment.