Skip to content
Open
Show file tree
Hide file tree
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
53 changes: 29 additions & 24 deletions include/integratorxx/batch/spherical_micro_batcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ class SphericalMicroBatcher {

using value_type =
std::tuple<point_type,point_type,point_container,weight_container>;
using different_type = size_t;
using pointer = value_type*;
using reference = value_type&;
using iterator_catagory = std::input_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = value_type;
using iterator_category = std::input_iterator_tag;

index_iterator idx_it;
point_iterator point_begin;
Expand All @@ -275,17 +275,18 @@ class SphericalMicroBatcher {
return retval;
}

iterator& operator+(int i) {
idx_it += i;
return *this;
}
iterator operator+(difference_type i) const {
iterator copy = *this;
copy.idx_it += i;
return copy;
}

bool operator==( iterator other ){ return idx_it == other.idx_it; }
bool operator!=( iterator other ){ return !(*this == other); }
bool operator==( const iterator& other ) const { return idx_it == other.idx_it; }
bool operator!=( const iterator& other ) const { return !(*this == other); }



auto range() {
auto range() const {

const auto idx = *idx_it;
const auto idx_next = *(idx_it+1);
Expand All @@ -302,7 +303,7 @@ class SphericalMicroBatcher {

}

value_type operator*() {
value_type operator*() const {

auto [npts,pb,pe,wb,we] = range();
auto [box_lo, box_up] = detail::get_box_bounds_points(pb, pe);
Expand All @@ -325,10 +326,10 @@ class SphericalMicroBatcher {

using value_type =
std::tuple<point_type,point_type,point_container,weight_container>;
using different_type = size_t;
using pointer = value_type*;
using reference = value_type&;
using iterator_catagory = std::input_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = value_type;
using iterator_category = std::input_iterator_tag;

const_index_iterator idx_it;
const_point_iterator point_begin;
Expand All @@ -346,17 +347,18 @@ class SphericalMicroBatcher {
return retval;
}

const_iterator& operator+(int i) {
idx_it += i;
return *this;
}
const_iterator operator+(difference_type i) const {
const_iterator copy = *this;
copy.idx_it += i;
return copy;
}

bool operator==( iterator other ){ return idx_it == other.idx_it; }
bool operator!=( iterator other ){ return !(*this == other); }
bool operator==( const const_iterator& other ) const { return idx_it == other.idx_it; }
bool operator!=( const const_iterator& other ) const { return !(*this == other); }



auto range() {
auto range() const {

const auto idx = *idx_it;
const auto idx_next = *(idx_it+1);
Expand All @@ -373,7 +375,7 @@ class SphericalMicroBatcher {

}

value_type operator*() {
value_type operator*() const {

auto [npts,pb,pe,wb,we] = range();
auto [box_lo, box_up] = detail::get_box_bounds_points(pb, pe);
Expand Down Expand Up @@ -465,6 +467,9 @@ class SphericalMicroBatcher {
quad_->weights().cbegin() );
}

const_iterator begin() const { return cbegin(); }
const_iterator end() const { return cend(); }

typename iterator::value_type at( size_t i ) {
if( i >= nbatches() )
throw std::runtime_error("Index out of bounds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ class RadialGridPartition {
using index_range_type = std::pair<size_t,size_t>;
using quad_type = Quadrature<AngularQuad>;
using value_type = std::pair<index_range_type, quad_type>;
using difference_type = size_t;
using pointer = value_type*;
using reference = value_type&;
using iterator_catagory = std::input_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = void;
using reference = value_type;
using iterator_category = std::input_iterator_tag;

index_iterator idx_it;
quad_iterator quad_it;
Expand All @@ -98,21 +98,22 @@ class RadialGridPartition {

rgp_iterator& operator++(){ idx_it++; quad_it++; return *this; }
rgp_iterator operator++(int) {
iterator retval = *this;
rgp_iterator retval = *this;
++(*this);
return retval;
}

rgp_iterator& operator+(int i) {
idx_it += i;
quad_it += i;
return (*this);
rgp_iterator operator+(difference_type i) const {
rgp_iterator copy = *this;
copy.idx_it += i;
copy.quad_it += i;
return copy;
}

bool operator==(rgp_iterator other) const {
bool operator==(const rgp_iterator& other) const {
return idx_it == other.idx_it && quad_it == other.quad_it;
}
bool operator!=(rgp_iterator other) const { return !(*this == other); }
bool operator!=(const rgp_iterator& other) const { return !(*this == other); }

value_type operator*() {
return std::make_pair( std::make_pair(*idx_it, *(idx_it+1)), *quad_it );
Expand Down
20 changes: 20 additions & 0 deletions test/composite_quadratures.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ TEST_CASE( "Spherical Quadratures", "[sph-quad]" ) {

CHECK( npts_c == npts );

// Iterating a const batcher: const_iterator compared against the
// non-const iterator type, so this could not previously compile.
npts_c = 0;
for( auto&& [box_lo, box_up, points_b, weights_b] : cbatcher ) {

auto npts_b = points_b.size();
CHECK( npts_b != 0 );
npts_c += npts_b;

}

CHECK( npts_c == npts );

npts_c = 0;
for( auto it = cbatcher.cbegin(); it != cbatcher.cend(); ++it ) {
npts_c += std::get<2>(*it).size();
}

CHECK( npts_c == npts );

auto batcher_clone = batcher.clone();
CHECK( &batcher.quadrature() != &batcher_clone.quadrature() );
CHECK( batcher.npts() == batcher_clone.npts() );
Expand Down
Loading