xtensor
 
Loading...
Searching...
No Matches
xoffset_view.hpp
1/***************************************************************************
2 * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3 * Copyright (c) QuantStack *
4 * *
5 * Distributed under the terms of the BSD 3-Clause License. *
6 * *
7 * The full license is in the file LICENSE, distributed with this software. *
8 ****************************************************************************/
9
10#ifndef XTENSOR_OFFSET_VIEW_HPP
11#define XTENSOR_OFFSET_VIEW_HPP
12
13#include <xtl/xcomplex.hpp>
14
15#include "../views/xfunctor_view.hpp"
16
17namespace xt
18{
19 namespace detail
20 {
21 template <class M, std::size_t I>
22 struct offset_forwarder
23 {
24 using value_type = M;
25 using reference = M&;
26 using const_reference = const M&;
27 using pointer = M*;
28 using const_pointer = const M*;
29
30 using proxy = xtl::xproxy_wrapper<M>;
31
32 template <class value_type, class requested_type>
33 using simd_return_type = xt_simd::simd_return_type<value_type, requested_type>;
34
35 template <class T>
36 decltype(auto) operator()(T&& t) const
37 {
38 return xtl::forward_offset<M, I>(std::forward<T>(t));
39 }
40
41 template <class align, class requested_type, std::size_t N, class E, class MF = M>
42 auto proxy_simd_load(const E& expr, std::size_t n) const
43 requires((std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF))
44 {
45 // TODO refactor using shuffle only
46 auto batch = expr.template load_simd<align, requested_type, N>(n);
47 if (I == 0)
48 {
49 return batch.real();
50 }
51 else
52 {
53 return batch.imag();
54 }
55 }
56
57 template <class align, class simd, class E, class MF = M>
58 auto proxy_simd_store(E& expr, std::size_t n, const simd& batch) const
59 requires((std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF))
60 {
61 auto x = expr.template load_simd<align, double, simd::size>(n);
62 if (I == 0)
63 {
64 x.real() = batch;
65 }
66 else
67 {
68 x.imag() = batch;
69 }
70 expr.template store_simd<align>(n, x);
71 }
72 };
73 }
74
75 template <class CT, class M, std::size_t I>
76 using xoffset_view = xfunctor_view<detail::offset_forwarder<M, I>, CT>;
77
78 template <class CT, class M, std::size_t I>
79 using xoffset_adaptor = xfunctor_adaptor<detail::offset_forwarder<M, I>, CT>;
80}
81
82#endif
Adapt a container with a functor, forwarding methods such as resize / reshape.
View of an xexpression .
standard mathematical functions for xexpressions