10#ifndef XTENSOR_ASSIGNER_HPP
11#define XTENSOR_ASSIGNER_HPP
13#include "../core/xassign_proxy.hpp"
14#include "../core/xfunction.hpp"
16#if defined(XTENSOR_USE_TBB)
20#if defined(XTENSOR_USE_OPENMP)
30 template <
class E1,
class E2>
35 template <
bool simd_assign>
36 void linear_assign(E1& e1,
const E2& e2)
const;
38 template <layout_type L>
39 void stepper_assign(E1& e1,
const E2& e2)
const;
41 void strided_loop_assign(E1& e1,
const E2& e2)
const;
45 void linear_assign_no_simd(E1& e1,
const E2& e2)
const;
48#if defined(XTENSOR_USE_TBB)
49 template <
class E1,
class E2>
54 template <
bool simd_assign>
55 void linear_assign(E1& e1,
const E2& e2)
const;
57 template <layout_type L>
58 void stepper_assign(E1& e1,
const E2& e2)
const;
60 void strided_loop_assign(E1& e1,
const E2& e2)
const;
64 void linear_assign_no_simd(E1& e1,
const E2& e2)
const;
68#if defined(XTENSOR_USE_OPENMP)
69 template <
class E1,
class E2>
74 template <
bool simd_assign>
75 void linear_assign(E1& e1,
const E2& e2)
const;
77 template <layout_type L>
78 void stepper_assign(E1& e1,
const E2& e2)
const;
80 void strided_loop_assign(E1& e1,
const E2& e2)
const;
84 void linear_assign_no_simd(E1& e1,
const E2& e2)
const;
88 template <
class E1,
class E2>
93 template <
bool simd_assign>
94 void linear_assign(E1& e1,
const E2& e2)
const;
96 template <layout_type L>
97 void stepper_assign(E1& e1,
const E2& e2)
const;
99 void strided_loop_assign(E1& e1,
const E2& e2)
const;
106 template <
class E1,
class E2,
class Tag>
109 template <
class E1,
class E2>
115#if defined(XTENSOR_USE_TBB)
116 template <
class E1,
class E2>
119 using type = tbb_assigner<E1, E2>;
123#if defined(XTENSOR_USE_OPENMP)
124 template <
class E1,
class E2>
125 struct parallel_assigner<E1, E2, openmp_tag>
127 using type = openmp_assigner<E1, E2>;
131 template <
class E1,
class E2>
137 template <
class E1,
class E2,
class Tag>
144 template <
class FROM,
class TO>
147 using argument_type = std::decay_t<FROM>;
148 using result_type = std::decay_t<TO>;
150 static const bool value = xtl::is_arithmetic<result_type>::value
151 && (
sizeof(result_type) <
sizeof(argument_type)
152 || (xtl::is_integral<result_type>::value
153 && std::is_floating_point<argument_type>::value));
156 template <
class FROM,
class TO>
159 using argument_type = std::decay_t<FROM>;
160 using result_type = std::decay_t<TO>;
162 static const bool value = xtl::is_signed<argument_type>::value != xtl::is_signed<result_type>::value;
165 template <
class FROM,
class TO>
168 using argument_type = std::decay_t<FROM>;
169 using result_type = std::decay_t<TO>;
171 static const bool value = is_narrowing_conversion<argument_type, result_type>::value
172 || has_sign_conversion<argument_type, result_type>::value;
193 template <
class T1,
class T2>
194 struct conditional_promote_to_complex
196 static constexpr bool cond = xtl::is_gen_complex<T1>::value && !xtl::is_gen_complex<T2>::value;
198 using type = std::conditional_t<cond, T1, T2>;
201 template <
class T1,
class T2>
202 using conditional_promote_to_complex_t =
typename conditional_promote_to_complex<T1, T2>::type;
205 template <
class E1,
class E2>
208 using e1_value_type =
typename E1::value_type;
209 using e2_value_type =
typename E2::value_type;
211 using e2_requested_value_type = std::
212 conditional_t<std::same_as<e2_value_type, bool>,
typename E2::bool_load_type, e2_value_type>;
213 using type = detail::conditional_promote_to_complex_t<e1_value_type, e2_requested_value_type>;
216 template <
class E1,
class E2>
217 using requested_value_type_t =
typename requested_value_type<E1, E2>::type;
219 template <
class E1,
class E2>
224 using lhs_align_mode = xt_simd::container_alignment_t<E1>;
225 static constexpr bool is_aligned = std::is_same<lhs_align_mode, aligned_mode>::value;
226 using rhs_align_mode = std::conditional_t<is_aligned, inner_aligned_mode, unaligned_mode>;
227 using e1_value_type =
typename E1::value_type;
228 using e2_value_type =
typename E2::value_type;
229 using value_type = requested_value_type_t<E1, E2>;
230 using simd_type = xt_simd::simd_type<value_type>;
231 using size_type =
typename E1::size_type;
232 static constexpr size_type simd_size = xt_simd::simd_traits<value_type>::size;
233 static constexpr bool needs_cast = has_assign_conversion<e2_value_type, e1_value_type>::value;
234 static constexpr bool is_convertible = std::is_convertible<e2_value_type, e1_value_type>::value;
236 size_type alignment_begin(
const E1& e1, size_type size)
const;
237 size_type alignment_end(size_type align_begin, size_type size)
const;
239 void assign_elements(E1& e1,
const E2& e2, size_type begin, size_type end)
const;
240 void assign_simd(E1& e1,
const E2& e2, size_type begin, size_type end)
const;
243 void assign_elements_no_simd(E1& e1,
const E2& e2, size_type begin, size_type end)
const;
246 template <
class E1,
class E2, layout_type L>
247 class stepper_assigner
251 using lhs_iterator =
typename E1::stepper;
252 using rhs_iterator =
typename E2::const_stepper;
253 using shape_type =
typename E1::shape_type;
254 using index_type = xindex_type_t<shape_type>;
255 using size_type =
typename lhs_iterator::size_type;
256 using difference_type =
typename lhs_iterator::difference_type;
258 stepper_assigner(E1& e1,
const E2& e2);
262 void step(size_type i);
263 void step(size_type i, size_type n);
264 void reset(size_type i);
278 namespace strided_assign_detail
282 bool can_do_strided_assign;
284 std::size_t inner_loop_size;
285 std::size_t outer_loop_size;
287 std::size_t dimension;
291 template <
class E1,
class E2>
292 class strided_loop_assigner
296 using size_type = std::size_t;
297 using index_type = dynamic_shape<std::size_t>;
299 using lhs_stepper =
typename E1::stepper;
300 using rhs_stepper =
typename E2::const_stepper;
301 using e1_value_type =
typename E1::value_type;
302 using e2_value_type =
typename E2::value_type;
303 using value_type = requested_value_type_t<E1, E2>;
304 using simd_type = std::conditional_t<
305 std::is_same<e1_value_type, bool>::value,
306 xt_simd::simd_bool_type<value_type>,
307 xt_simd::simd_type<value_type>>;
308 static constexpr bool needs_cast = has_assign_conversion<e2_value_type, e1_value_type>::value;
310 strided_loop_assigner(E1& e1,
const E2& e2);
312 bool can_do_strided_assign()
const noexcept;
313 size_type inner_loop_size()
const noexcept;
314 size_type outer_loop_size()
const noexcept;
317 void run(size_type begin, size_type end)
const;
321 void nth_idx(size_type n, index_type& index)
const;
322 void next_idx(index_type& index)
const;
326 loop_sizes_t m_loop_sizes;
327 index_type m_max_shape;
328 size_type m_step_dim;
329 size_type m_simd_size;
330 size_type m_simd_rest;
337 template <
class E1,
class E2>
338 template <
bool simd_assign>
339 void noparallel_assigner<E1, E2>::linear_assign(E1& e1,
const E2& e2)
const
341 if constexpr (!simd_assign)
343 linear_assign_no_simd(e1, e2);
347 using assigner_t = linear_assigner<E1, E2>;
348 using size_type =
typename assigner_t::size_type;
351 size_type size = e1.size();
352 auto align_begin = helper.alignment_begin(e1, size);
353 auto align_end = helper.alignment_end(align_begin, size);
355 helper.assign_elements(e1, e2, 0u, align_begin);
356 helper.assign_simd(e1, e2, align_begin, align_end);
357 helper.assign_elements(e1, e2, align_end, size);
361 template <
class E1,
class E2>
362 template <layout_type L>
363 void noparallel_assigner<E1, E2>::stepper_assign(E1& e1,
const E2& e2)
const
369 template <
class E1,
class E2>
370 void noparallel_assigner<E1, E2>::strided_loop_assign(E1& e1,
const E2& e2)
const
373 if (!helper.can_do_strided_assign())
375 stepper_assign<default_assignable_layout(E1::static_layout)>(e1, e2);
379 helper.run(0u, helper.outer_loop_size());
382 template <
class E1,
class E2>
383 void noparallel_assigner<E1, E2>::linear_assign_no_simd(E1& e1,
const E2& e2)
const
392#if defined(XTENSOR_USE_TBB)
393 template <
class E1,
class E2>
394 template <
bool simd_assign>
395 void tbb_assigner<E1, E2>::linear_assign(E1& e1,
const E2& e2)
const
397 if constexpr (!simd_assign)
399 linear_assign_no_simd(e1, e2);
404 using size_type =
typename assigner_t::size_type;
405 constexpr size_type simd_size = assigner_t::simd_size;
408 size_type size = e1.size();
409 auto align_begin = helper.alignment_begin(e1, size);
410 auto align_end = helper.alignment_end(align_begin, size);
412 helper.assign_elements(e1, e2, 0u, align_begin);
413 if (size >= XTENSOR_TBB_THRESHOLD)
415 tbb::static_partitioner ap;
420 [&helper, &e1, &e2](size_type i)
422 helper.assign_simd(e1, e2, i, i + simd_size);
429 helper.assign_simd(e1, e2, align_begin, align_end);
431 helper.assign_elements(e1, e2, align_end, size);
435 template <
class E1,
class E2>
436 template <layout_type L>
437 void tbb_assigner<E1, E2>::stepper_assign(E1& e1,
const E2& e2)
const
443 template <
class E1,
class E2>
444 void tbb_assigner<E1, E2>::strided_loop_assign(E1& e1,
const E2& e2)
const
447 using size_type =
typename assigner_t::size_type;
449 assigner_t helper(e1, e2);
450 if (!helper.can_do_strided_assign())
452 stepper_assign<default_assignable_layout(E1::static_layout)>(e1, e2);
456 size_type outer_loop_size = helper.outer_loop_size();
457 if (outer_loop_size > XTENSOR_TBB_THRESHOLD / helper.inner_loop_size())
459 tbb::static_partitioner sp;
461 tbb::blocked_range<size_type>(size_type(0), outer_loop_size),
462 [&helper](
const tbb::blocked_range<size_type>& r)
464 helper.run(r.begin(), r.end());
471 helper.run(0u, outer_loop_size);
475 template <
class E1,
class E2>
476 void tbb_assigner<E1, E2>::linear_assign_no_simd(E1& e1,
const E2& e2)
const
479 using size_type =
typename assigner_t::size_type;
482 tbb::static_partitioner sp;
484 tbb::blocked_range<size_type>(size_type(0), e1.size()),
485 [&helper, &e1, &e2](
const tbb::blocked_range<size_type>& r)
487 helper.assign_elements_no_simd(e1, e2, r.begin(), r.end());
498#if defined(XTENSOR_USE_OPENMP)
499 template <
class E1,
class E2>
500 template <
bool simd_assign>
501 void openmp_assigner<E1, E2>::linear_assign(E1& e1,
const E2& e2)
const
503 if constexpr (!simd_assign)
505 linear_assign_no_simd(e1, e2);
510 using size_type =
typename assigner_t::size_type;
511 constexpr size_type simd_size = assigner_t::simd_size;
514 size_type size = e1.size();
515 auto align_begin = helper.alignment_begin(e1, size);
516 auto align_end = helper.alignment_end(align_begin, size);
518 helper.assign_elements(e1, e2, 0u, align_begin);
519 if (size >= size_type(XTENSOR_OPENMP_TRESHOLD))
522#pragma omp parallel for default(none) shared(helper, align_begin, align_end, e1, e2)
523 for (
auto i =
static_cast<std::ptrdiff_t
>(align_begin);
524 i < static_cast<std::ptrdiff_t>(align_end);
525 i +=
static_cast<std::ptrdiff_t
>(simd_size))
527 size_type ui =
static_cast<size_type
>(i);
528 helper.assign_simd(e1, e2, ui, ui + simd_size);
533 helper.assign_simd(e1, e2, align_begin, align_end);
535 helper.assign_elements(e1, e2, align_end, size);
539 template <
class E1,
class E2>
540 template <layout_type L>
541 void openmp_assigner<E1, E2>::stepper_assign(E1& e1,
const E2& e2)
const
547 template <
class E1,
class E2>
548 void openmp_assigner<E1, E2>::strided_loop_assign(E1& e1,
const E2& e2)
const
551 using size_type =
typename assigner_t::size_type;
553 assigner_t helper(e1, e2);
554 if (!helper.can_do_strided_assign())
556 stepper_assign<default_assignable_layout(E1::static_layout)>(e1, e2);
560 size_type outer_loop_size = helper.outer_loop_size();
561 if (outer_loop_size >= XTENSOR_OPENMP_TRESHOLD / helper.inner_loop_size())
565#pragma omp parallel default(none) shared(helper, outer_loop_size)
567 size_type nb_threads =
static_cast<size_type
>(omp_get_num_threads());
568 size_type thread_id =
static_cast<size_type
>(omp_get_thread_num());
569 size_type chunk = outer_loop_size / nb_threads;
570 size_type rest = outer_loop_size % nb_threads;
571 size_type begin = thread_id * chunk + std::min(thread_id, rest);
572 size_type end = begin + chunk + (thread_id < rest ? 1u : 0u);
573 helper.run(begin, end);
578 helper.run(0u, outer_loop_size);
582 template <
class E1,
class E2>
583 void openmp_assigner<E1, E2>::linear_assign_no_simd(E1& e1,
const E2& e2)
const
586 using size_type =
typename assigner_t::size_type;
589 size_type n = e1.size();
591 if (n >= size_type(XTENSOR_OPENMP_TRESHOLD))
594#pragma omp parallel default(none) shared(helper, e1, e2, n)
596 size_type nb_threads =
static_cast<size_type
>(omp_get_num_threads());
597 size_type thread_id =
static_cast<size_type
>(omp_get_thread_num());
598 size_type chunk = n / nb_threads;
599 size_type rest = n % nb_threads;
600 size_type begin = thread_id * chunk + std::min(thread_id, rest);
601 size_type end = begin + chunk + (thread_id < rest ? 1u : 0u);
602 helper.assign_elements_no_simd(e1, e2, begin, end);
607 helper.assign_elements_no_simd(e1, e2, 0u, n);
616 template <
class E1,
class E2>
617 template <
bool simd_assign>
618 void waterfall_assigner<E1, E2>::linear_assign(E1& e1,
const E2& e2)
const
620#if defined(XTENSOR_USE_TBB)
621 tbb_assigner<E1, E2>{}.template linear_assign<simd_assign>(e1, e2);
622#elif defined(XTENSOR_USE_OPENMP)
623 openmp_assigner<E1, E2>{}.template linear_assign<simd_assign>(e1, e2);
629 template <
class E1,
class E2>
630 template <layout_type L>
631 void waterfall_assigner<E1, E2>::stepper_assign(E1& e1,
const E2& e2)
const
637 template <
class E1,
class E2>
638 void waterfall_assigner<E1, E2>::strided_loop_assign(E1& e1,
const E2& e2)
const
640#if defined(XTENSOR_USE_TBB)
641 tbb_assigner<E1, E2>{}.strided_loop_assign(e1, e2);
642#elif defined(XTENSOR_USE_OPENMP)
643 openmp_assigner<E1, E2>{}.strided_loop_assign(e1, e2);
653 template <
class E1,
class E2>
654 auto linear_assigner<E1, E2>::alignment_begin(
const E1& e1, size_type size)
const -> size_type
656 size_type align_begin = is_aligned ? 0 : xt_simd::get_alignment_offset(e1.data(), size, simd_size);
660 template <
class E1,
class E2>
661 auto linear_assigner<E1, E2>::alignment_end(size_type align_begin, size_type size)
const -> size_type
663 size_type align_end = align_begin + ((size - align_begin) & ~(simd_size - 1));
667 template <
class E1,
class E2>
668 void linear_assigner<E1, E2>::assign_elements(E1& e1,
const E2& e2, size_type begin, size_type end)
const
670 for (size_type i = begin; i < end; ++i)
676 template <
class E1,
class E2>
677 void linear_assigner<E1, E2>::assign_simd(E1& e1,
const E2& e2, size_type begin, size_type end)
const
679 for (size_type i = begin; i < end; i += simd_size)
681 e1.template store_simd<lhs_align_mode>(i, e2.template load_simd<rhs_align_mode, value_type>(i));
685 template <
class E1,
class E2>
687 linear_assigner<E1, E2>::assign_elements_no_simd(E1& e1,
const E2& e2, size_type begin, size_type end)
const
691 if constexpr (!is_convertible)
693 XTENSOR_PRECONDITION(
false,
"Internal error: linear_assigner called with unrelated types.");
697 using difference_type = std::ptrdiff_t;
698 auto src = linear_begin(e2) +
static_cast<difference_type
>(begin);
699 auto dst = linear_begin(e1) +
static_cast<difference_type
>(begin);
700 for (size_type i = begin; i < end; ++i)
702 *dst =
static_cast<e1_value_type
>(*src);
713 template <
class E1,
class E2, layout_type L>
714 inline stepper_assigner<E1, E2, L>::stepper_assigner(E1& e1,
const E2& e2)
716 , m_lhs(e1.stepper_begin(e1.shape()))
717 , m_rhs(e2.stepper_begin(e1.shape()))
718 , m_index(xtl::make_sequence<index_type>(e1.shape().size(), size_type(0)))
722 template <
class E1,
class E2, layout_type L>
723 inline void stepper_assigner<E1, E2, L>::run()
725 using tmp_size_type =
typename E1::size_type;
726 using argument_type = std::decay_t<
decltype(*m_rhs)>;
727 using result_type = std::decay_t<
decltype(*m_lhs)>;
728 constexpr bool needs_cast = has_assign_conversion<argument_type, result_type>::value;
730 tmp_size_type s = m_e1.size();
731 for (tmp_size_type i = 0; i < s; ++i)
734 stepper_tools<L>::increment_stepper(*
this, m_index, m_e1.shape());
738 template <
class E1,
class E2, layout_type L>
739 inline void stepper_assigner<E1, E2, L>::step(size_type i)
745 template <
class E1,
class E2, layout_type L>
746 inline void stepper_assigner<E1, E2, L>::step(size_type i, size_type n)
752 template <
class E1,
class E2, layout_type L>
753 inline void stepper_assigner<E1, E2, L>::reset(size_type i)
759 template <
class E1,
class E2, layout_type L>
760 inline void stepper_assigner<E1, E2, L>::to_end(
layout_type l)
770 namespace strided_assign_detail
772 template <layout_type layout>
779 static void next_idx(T& outer_index,
const T& outer_shape)
781 auto i = outer_index.size();
784 if (outer_index[i - 1] + 1 >= outer_shape[i - 1])
786 outer_index[i - 1] = 0;
790 outer_index[i - 1]++;
797 static void nth_idx(
size_t n, T& outer_index,
const T& outer_shape)
799 dynamic_shape<std::size_t> stride_sizes;
800 xt::resize_container(stride_sizes, outer_shape.size());
802 using size_type =
typename T::size_type;
803 for (size_type i = outer_shape.size(); i > 0; i--)
805 stride_sizes[i - 1] = (i == outer_shape.size()) ? 1 : stride_sizes[i] * outer_shape[i];
809 for (size_type i = 0; i < outer_shape.size(); i++)
811 auto d_idx = n / stride_sizes[i];
812 outer_index[i] = d_idx;
813 n -= d_idx * stride_sizes[i];
822 static void next_idx(T& outer_index,
const T& outer_shape)
824 using size_type =
typename T::size_type;
826 auto sz = outer_index.size();
829 if (outer_index[i] + 1 >= outer_shape[i])
842 static void nth_idx(
size_t n, T& outer_index,
const T& outer_shape)
844 dynamic_shape<std::size_t> stride_sizes;
845 xt::resize_container(stride_sizes, outer_shape.size());
847 using size_type =
typename T::size_type;
850 for (size_type i = 0; i < outer_shape.size(); i++)
852 stride_sizes[i] = (i == 0) ? 1 : stride_sizes[i - 1] * outer_shape[i - 1];
856 for (size_type i = outer_shape.size(); i > 0;)
859 auto d_idx = n / stride_sizes[i];
860 outer_index[i] = d_idx;
861 n -= d_idx * stride_sizes[i];
866 template <layout_type L,
class S>
867 struct check_strides_functor
869 using strides_type = S;
871 check_strides_functor(
const S&
strides)
877 template <
class T, layout_type LE = L>
878 std::enable_if_t<LE == layout_type::row_major, std::size_t> operator()(
const T& el)
889 template <
class T, layout_type LE = L>
890 std::enable_if_t<LE == layout_type::column_major, std::size_t> operator()(
const T& el)
907 template <
class F,
class... CT>
910 xt::for_each(*
this, xf.arguments());
917 const strides_type& m_strides;
920 template <
bool possible = true,
class E1,
class E2, std::enable_if_t<!str
ided_expression<E1> || !possible,
bool> = true>
923 return {
false,
true, 1, e1.size(), e1.dimension(), e1.dimension()};
926 template <
bool possible = true,
class E1,
class E2, std::enable_if_t<str
ided_expression<E1> && possible,
bool> = true>
927 loop_sizes_t get_loop_sizes(
const E1& e1,
const E2& e2)
929 using shape_value_type =
typename E1::shape_type::value_type;
930 bool is_row_major =
true;
935 auto is_zero = [](
auto i)
940 auto it_bwd = std::find_if_not(
strides.rbegin(),
strides.rend(), is_zero);
941 bool de1_row_contiguous = it_bwd !=
strides.rend() && *it_bwd == 1;
942 auto it_fwd = std::find_if_not(
strides.begin(),
strides.end(), is_zero);
943 bool de1_col_contiguous = it_fwd !=
strides.end() && *it_fwd == 1;
944 if (de1_row_contiguous)
948 else if (de1_col_contiguous)
950 is_row_major =
false;
955 return {
false,
true, 1, e1.size(), e1.dimension(), e1.dimension()};
966 if (cut < e1.strides().size() - 1)
969 cut = e1.strides().size() - 1;
972 else if (!is_row_major)
984 std::size_t outer_loop_size =
static_cast<std::size_t
>(std::accumulate(
986 e1.shape().begin() +
static_cast<std::ptrdiff_t
>(cut),
988 std::multiplies<shape_value_type>{}
990 std::size_t inner_loop_size =
static_cast<std::size_t
>(std::accumulate(
991 e1.shape().begin() +
static_cast<std::ptrdiff_t
>(cut),
994 std::multiplies<shape_value_type>{}
999 std::swap(outer_loop_size, inner_loop_size);
1002 return {inner_loop_size > 1, is_row_major, inner_loop_size, outer_loop_size, cut, e1.dimension()};
1006 template <
class E1,
class E2>
1007 inline strided_loop_assigner<E1, E2>::strided_loop_assigner(E1& e1,
const E2& e2)
1010 , m_loop_sizes(strided_assign_detail::get_loop_sizes(e1, e2))
1016 if (!m_loop_sizes.can_do_strided_assign)
1021 auto cut =
static_cast<std::ptrdiff_t
>(m_loop_sizes.cut);
1022 if (m_loop_sizes.is_row_major)
1024 m_max_shape.assign(e1.shape().begin(), e1.shape().begin() + cut);
1028 m_max_shape.assign(e1.shape().begin() + cut, e1.shape().end());
1029 m_step_dim = m_loop_sizes.cut;
1032 m_simd_size = m_loop_sizes.inner_loop_size / simd_type::size;
1033 m_simd_rest = m_loop_sizes.inner_loop_size % simd_type::size;
1036 template <
class E1,
class E2>
1037 inline bool strided_loop_assigner<E1, E2>::can_do_strided_assign() const noexcept
1039 return m_loop_sizes.can_do_strided_assign;
1042 template <
class E1,
class E2>
1043 inline auto strided_loop_assigner<E1, E2>::inner_loop_size() const noexcept -> size_type
1045 return m_loop_sizes.inner_loop_size;
1048 template <
class E1,
class E2>
1049 inline auto strided_loop_assigner<E1, E2>::outer_loop_size() const noexcept -> size_type
1051 return m_loop_sizes.outer_loop_size;
1054 template <
class E1,
class E2>
1055 inline void strided_loop_assigner<E1, E2>::run(size_type begin, size_type end)
const
1062 const size_type step_dim = m_step_dim;
1063 const size_type simd_size = m_simd_size;
1064 const size_type simd_rest = m_simd_rest;
1066 lhs_stepper lhs = m_e1.stepper_begin(m_e1.shape());
1067 rhs_stepper rhs = m_e2.stepper_begin(m_e1.shape());
1068 index_type index = xtl::make_sequence<index_type>(m_max_shape.size(), size_type(0));
1070 if (begin != size_type(0))
1072 nth_idx(begin, index);
1073 for (size_type i = 0; i < index.size(); ++i)
1075 lhs.step(i + step_dim, index[i]);
1076 rhs.step(i + step_dim, index[i]);
1080 for (size_type ox = begin; ox < end; ++ox)
1082 for (size_type i = 0; i < simd_size; ++i)
1084 lhs.store_simd(rhs.template step_simd<value_type>());
1086 for (size_type i = 0; i < simd_rest; ++i)
1097 if (!E1::contiguous_layout)
1100 for (size_type i = 0; i < index.size(); ++i)
1102 lhs.step(i + step_dim, index[i]);
1103 rhs.step(i + step_dim, index[i]);
1108 for (size_type i = 0; i < index.size(); ++i)
1110 rhs.step(i + step_dim, index[i]);
1116 template <
class E1,
class E2>
1117 inline void strided_loop_assigner<E1, E2>::nth_idx(size_type n, index_type& index)
const
1119 if (m_loop_sizes.is_row_major)
1121 strided_assign_detail::idx_tools<layout_type::row_major>::nth_idx(n, index, m_max_shape);
1125 strided_assign_detail::idx_tools<layout_type::column_major>::nth_idx(n, index, m_max_shape);
1129 template <
class E1,
class E2>
1130 inline void strided_loop_assigner<E1, E2>::next_idx(index_type& index)
const
1132 if (m_loop_sizes.is_row_major)
1134 strided_assign_detail::idx_tools<layout_type::row_major>::next_idx(index, m_max_shape);
1138 strided_assign_detail::idx_tools<layout_type::column_major>::next_idx(index, m_max_shape);
Multidimensional function operating on xtensor expressions.
auto strides(const E &e, stride_type type=stride_type::normal) noexcept
Get strides of an object.
standard mathematical functions for xexpressions
auto conditional_cast(U &&u)
Perform a type cast when a condition is true.