Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes array_ref::{operator==, operator!=} #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions include/array/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,13 @@ class dim : protected interval<Min_, Extent_> {
using base_range::begin;
using base_range::end;
using base_range::extent;
using base_range::size;
using base_range::is_in_range;
using base_range::max;
using base_range::min;
using base_range::set_extent;
using base_range::set_max;
using base_range::set_min;
using base_range::size;

/** Get or set the distance in flat indices between neighboring elements
* in this dim. */
Expand Down Expand Up @@ -560,9 +560,7 @@ class split_iterator {
split_iterator<InnerExtent> result(*this);
return result += n;
}
NDARRAY_HOST_DEVICE split_iterator& operator++() {
return *this += 1;
}
NDARRAY_HOST_DEVICE split_iterator& operator++() { return *this += 1; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.clang-format did this. Happy to revert.

NDARRAY_HOST_DEVICE split_iterator operator++(int) {
split_iterator<InnerExtent> result(*this);
*this += 1;
Expand Down Expand Up @@ -612,15 +610,13 @@ class split_result {
* - `split<5>(interval<>(0, 12))` produces the intervals `[0, 5)`,
* `[5, 10)`, `[7, 12)`. Note the last two intervals overlap. */
template <index_t InnerExtent, index_t Min, index_t Extent>
NDARRAY_HOST_DEVICE internal::split_result<InnerExtent> split(
const interval<Min, Extent>& v) {
NDARRAY_HOST_DEVICE internal::split_result<InnerExtent> split(const interval<Min, Extent>& v) {
assert(v.extent() >= InnerExtent);
return {{fixed_interval<InnerExtent>(v.min()), v.max()},
{fixed_interval<InnerExtent>(v.max() + 1), v.max()}};
}
template <index_t InnerExtent, index_t Min, index_t Extent, index_t Stride>
NDARRAY_HOST_DEVICE internal::split_result<InnerExtent> split(
const dim<Min, Extent, Stride>& v) {
NDARRAY_HOST_DEVICE internal::split_result<InnerExtent> split(const dim<Min, Extent, Stride>& v) {
return split<InnerExtent>(interval<Min, Extent>(v.min(), v.extent()));
}

Expand Down Expand Up @@ -1031,10 +1027,12 @@ NDARRAY_HOST_DEVICE const DimsSrc& assert_dims_compatible(const DimsSrc& src) {
return src;
}

/** Return a tuple of generic `dims` with same min and extents and all strides set to `unresolved`. */
/** Return a tuple of generic `dims` with same min and extents and all strides set to `unresolved`.
*/
template <class Dims, size_t... Is>
auto bounds_tuple(const Dims& dims, index_sequence<Is...>) {
return std::make_tuple(dim<>(std::get<Is>(dims).min(), std::get<Is>(dims).extent(), unresolved)...);
return std::make_tuple(
dim<>(std::get<Is>(dims).min(), std::get<Is>(dims).extent(), unresolved)...);
}

} // namespace internal
Expand Down Expand Up @@ -2174,26 +2172,6 @@ class array_ref {
NDARRAY_HOST_DEVICE index_t rows() const { return shape_.rows(); }
NDARRAY_HOST_DEVICE index_t columns() const { return shape_.columns(); }

/** Compare the contents of this array_ref to `other`. For two array_refs to
* be considered equal, they must have the same shape, and all elements
* addressable by the shape must also be equal. */
// TODO: Maybe this should just check for equality of the shape and pointer,
// and let the free function equal serve this purpose.
NDARRAY_HOST_DEVICE bool operator!=(const array_ref& other) const {
if (shape_ != other.shape_) { return true; }

// TODO: This currently calls operator!= on all elements of the array_ref,
// even after we find a non-equal element
// (https://github.com/dsharlet/array/issues/4).
bool result = false;
copy_shape_traits<Shape, Shape>::for_each_value(
shape_, base_, other.shape_, other.base_, [&](const_reference a, const_reference b) {
if (a != b) { result = true; }
});
return result;
}
NDARRAY_HOST_DEVICE bool operator==(const array_ref& other) const { return !operator!=(other); }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this build? array::operator== uses this.

It looks like travis stopped working (again).


NDARRAY_HOST_DEVICE const array_ref<T, Shape>& ref() const { return *this; }

/** Allow conversion from array_ref<T> to const_array_ref<T>. */
Expand Down Expand Up @@ -2983,7 +2961,8 @@ bool equal(const array<TA, ShapeA, AllocA>& a, const array<TB, ShapeB, AllocB>&
* `NewShape`. The new shape is copy constructed from `a.shape()`. */
template <class NewShape, class T, class OldShape>
NDARRAY_HOST_DEVICE array_ref<T, NewShape> convert_shape(const array_ref<T, OldShape>& a) {
return array_ref<T, NewShape>(a.base(), convert_shape<NewShape>(a.shape()), internal::no_resolve{});
return array_ref<T, NewShape>(
a.base(), convert_shape<NewShape>(a.shape()), internal::no_resolve{});
}
template <class NewShape, class T, class OldShape, class Allocator>
array_ref<T, NewShape> convert_shape(array<T, OldShape, Allocator>& a) {
Expand Down