Skip to content

Adding concept to a part of the code (part 2) #2846

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions include/xtensor/misc/xtl_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ namespace xtl
{
template <typename T>
concept integral_concept = xtl::is_integral<T>::value;

template <typename T>
concept non_integral_concept = !xtl::is_integral<T>::value;

template <typename T>
concept complex_concept = xtl::is_complex<typename std::decay<T>::type::value_type>::value;

template <typename T>
concept pointer_concept = std::is_pointer<T>::value;
}

#endif // XTENSOR_CONCEPTS_HPP
23 changes: 10 additions & 13 deletions include/xtensor/views/xaxis_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ namespace xt
value_type m_sv;

template <class T, class CTA>
std::enable_if_t<std::is_pointer<T>::value, T> get_storage_init(CTA&& e) const;

template <class T, class CTA>
std::enable_if_t<!std::is_pointer<T>::value, T> get_storage_init(CTA&& e) const;
T get_storage_init(CTA&& e) const;
};

template <class CT>
Expand Down Expand Up @@ -125,16 +122,16 @@ namespace xt

template <class CT>
template <class T, class CTA>
inline std::enable_if_t<std::is_pointer<T>::value, T> xaxis_iterator<CT>::get_storage_init(CTA&& e) const
inline T xaxis_iterator<CT>::get_storage_init(CTA&& e) const
{
return &e;
}

template <class CT>
template <class T, class CTA>
inline std::enable_if_t<!std::is_pointer<T>::value, T> xaxis_iterator<CT>::get_storage_init(CTA&& e) const
{
return e;
if constexpr (xtl::pointer_concept<T>)
{
return &e;
}
else
{
return e;
}
}

/**
Expand Down
25 changes: 10 additions & 15 deletions include/xtensor/views/xaxis_slice_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ namespace xt
value_type m_sv;

template <class T, class CTA>
std::enable_if_t<std::is_pointer<T>::value, T> get_storage_init(CTA&& e) const;

template <class T, class CTA>
std::enable_if_t<!std::is_pointer<T>::value, T> get_storage_init(CTA&& e) const;
T get_storage_init(CTA&& e) const;
};

template <class CT>
Expand All @@ -99,18 +96,16 @@ namespace xt

template <class CT>
template <class T, class CTA>
inline std::enable_if_t<std::is_pointer<T>::value, T>
xaxis_slice_iterator<CT>::get_storage_init(CTA&& e) const
{
return &e;
}

template <class CT>
template <class T, class CTA>
inline std::enable_if_t<!std::is_pointer<T>::value, T>
xaxis_slice_iterator<CT>::get_storage_init(CTA&& e) const
T xaxis_slice_iterator<CT>::get_storage_init(CTA&& e) const
{
return e;
if constexpr (xtl::pointer_concept<T>)
{
return &e;
}
else
{
return e;
}
}

/**
Expand Down
14 changes: 8 additions & 6 deletions include/xtensor/views/xbroadcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ namespace xt
template <class CT, class X>
class xbroadcast;

template <class E>
concept xbroadcast_concept = is_specialization_of<xbroadcast, E>::value;

template <class CT, class X>
struct xiterable_inner_types<xbroadcast<CT, X>>
{
Expand Down Expand Up @@ -122,10 +125,9 @@ namespace xt
* overlapping_memory_checker_traits *
*************************************/

template <class E>
struct overlapping_memory_checker_traits<
E,
std::enable_if_t<!has_memory_address<E>::value && is_specialization_of<xbroadcast, E>::value>>
template <xbroadcast_concept E>
requires(without_memory_address_concept<E>)
struct overlapping_memory_checker_traits<E>
{
static bool check_overlap(const E& expr, const memory_range& dst_range)
{
Expand Down Expand Up @@ -223,7 +225,7 @@ namespace xt
template <class S>
const_stepper stepper_end(const S& shape, layout_type l) const noexcept;

template <class E, class XCT = CT, class = std::enable_if_t<xt::is_xscalar<XCT>::value>>
template <class E, xscalar_concept XCT = CT>
void assign_to(xexpression<E>& e) const;

template <class E>
Expand Down Expand Up @@ -463,7 +465,7 @@ namespace xt
}

template <class CT, class X>
template <class E, class XCT, class>
template <class E, xscalar_concept XCT>
inline void xbroadcast<CT, X>::assign_to(xexpression<E>& e) const
{
auto& ed = e.derived_cast();
Expand Down
21 changes: 4 additions & 17 deletions include/xtensor/views/xoffset_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ namespace xt
return xtl::forward_offset<M, I>(std::forward<T>(t));
}

template <
class align,
class requested_type,
std::size_t N,
class E,
class MF = M,
class = std::enable_if_t<
(std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF),
int>>
template <class align, class requested_type, std::size_t N, class E, class MF = M>
auto proxy_simd_load(const E& expr, std::size_t n) const
requires((std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF))
{
// TODO refactor using shuffle only
auto batch = expr.template load_simd<align, requested_type, N>(n);
Expand All @@ -61,15 +54,9 @@ namespace xt
}
}

template <
class align,
class simd,
class E,
class MF = M,
class = std::enable_if_t<
(std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF),
int>>
template <class align, class simd, class E, class MF = M>
auto proxy_simd_store(E& expr, std::size_t n, const simd& batch) const
requires((std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF))
{
auto x = expr.template load_simd<align, double, simd::size>(n);
if (I == 0)
Expand Down
Loading
Loading