forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blockwise reducers intital implementation
cleanup cleanup cleanup cleanup cleanup cleanup cleanup added explicit this cleanup const correctness const correctness more inline fixed broken tests ... added p norms added p norms fixed test winfix win fix win fix
- Loading branch information
1 parent
2618d5a
commit 8fb97e6
Showing
11 changed files
with
1,726 additions
and
43 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/*************************************************************************** | ||
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * | ||
* Copyright (c) QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
#ifndef XTENSOR_XGRID_ITERATOR | ||
#define XTENSOR_XGRID_ITERATOR | ||
|
||
#include "xtl/xsequence.hpp" | ||
|
||
|
||
#include "xstrided_view.hpp" | ||
|
||
namespace xt | ||
{ | ||
|
||
template<class S> | ||
class xsubgrid_iterator | ||
{ | ||
public: | ||
using self_type = xsubgrid_iterator<S>; | ||
using shape_type = S; | ||
|
||
using value_type = shape_type; | ||
using reference = value_type &; | ||
using pointer = value_type*; | ||
using difference_type = std::size_t; | ||
using iterator_category = std::forward_iterator_tag; | ||
|
||
xsubgrid_iterator() = default; | ||
xsubgrid_iterator(const xsubgrid_iterator&) = default; | ||
xsubgrid_iterator(xsubgrid_iterator&&) = default; | ||
xsubgrid_iterator& operator=(const xsubgrid_iterator&) = default; | ||
xsubgrid_iterator& operator=(xsubgrid_iterator&&) = default; | ||
|
||
template<class B, class E, class C> | ||
xsubgrid_iterator(B && begin, E && end, C && current, const std::size_t linear_index) | ||
: m_begin(std::forward<B>(begin)), | ||
m_end(std::forward<E>(end)), | ||
m_current(std::forward<C>(current)), | ||
m_linear_index(linear_index) | ||
{ | ||
|
||
} | ||
|
||
self_type& operator++() | ||
{ | ||
std::size_t i = m_begin.size(); | ||
while (i != 0) | ||
{ | ||
--i; | ||
if (m_current[i] + 1u == m_end[i]) | ||
{ | ||
m_current[i] = m_begin[i]; | ||
} | ||
else | ||
{ | ||
m_current[i] += 1; | ||
break; | ||
} | ||
} | ||
m_linear_index++; | ||
return *this; | ||
} | ||
|
||
self_type operator++(int) | ||
{ | ||
self_type it = *this; | ||
++(*this); | ||
return it; | ||
} | ||
shape_type & operator*() | ||
{ | ||
return m_current; | ||
} | ||
const shape_type & operator*() const | ||
{ | ||
return m_current; | ||
} | ||
|
||
bool operator==(const self_type& rhs) const | ||
{ | ||
return m_linear_index == rhs.m_linear_index; | ||
} | ||
bool operator!=(const self_type& rhs) const | ||
{ | ||
return !this->operator==(rhs); | ||
} | ||
|
||
private: | ||
shape_type m_begin; | ||
shape_type m_end; | ||
shape_type m_current; | ||
std::size_t m_linear_index{0}; | ||
}; | ||
|
||
|
||
template<class S, class B, class E> | ||
auto subgrid_iterator_begin(B && roi_begin, E && roi_end) | ||
{ | ||
S current; | ||
resize_container(current, roi_begin.size()); | ||
std::copy(roi_begin.begin(), roi_begin.end(), current.begin()); | ||
return xsubgrid_iterator<S>( | ||
std::forward<B>(roi_begin), | ||
std::forward<E>(roi_end), | ||
std::move(current), | ||
0 | ||
); | ||
} | ||
|
||
template<class S, class B, class E> | ||
auto subgrid_iterator_end(B && roi_begin, E && roi_end) | ||
{ | ||
S current; | ||
resize_container(current, roi_begin.size()); | ||
std::copy(roi_end.begin(), roi_end.end(), current.begin()); | ||
|
||
std::size_t linear_index = 1; | ||
for(std::size_t i=0; i<roi_begin.size(); ++i) | ||
{ | ||
linear_index *= roi_end[i] - roi_begin[i]; | ||
} | ||
|
||
return xsubgrid_iterator<S>( | ||
std::forward<B>(roi_begin), | ||
std::forward<E>(roi_end), | ||
std::move(current), | ||
linear_index | ||
); | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.