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 "xtensor/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 <
42 class align,
43 class requested_type,
44 std::size_t N,
45 class E,
46 class MF = M,
47 class = std::enable_if_t<
48 (std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF),
49 int>>
50 auto proxy_simd_load(const E& expr, std::size_t n) const
51 {
52 // TODO refactor using shuffle only
53 auto batch = expr.template load_simd<align, requested_type, N>(n);
54 if (I == 0)
55 {
56 return batch.real();
57 }
58 else
59 {
60 return batch.imag();
61 }
62 }
63
64 template <
65 class align,
66 class simd,
67 class E,
68 class MF = M,
69 class = std::enable_if_t<
70 (std::is_same<MF, double>::value || std::is_same<MF, float>::value) && I <= sizeof(MF),
71 int>>
72 auto proxy_simd_store(E& expr, std::size_t n, const simd& batch) const
73 {
74 auto x = expr.template load_simd<align, double, simd::size>(n);
75 if (I == 0)
76 {
77 x.real() = batch;
78 }
79 else
80 {
81 x.imag() = batch;
82 }
83 expr.template store_simd<align>(n, x);
84 }
85 };
86 }
87
88 template <class CT, class M, std::size_t I>
89 using xoffset_view = xfunctor_view<detail::offset_forwarder<M, I>, CT>;
90
91 template <class CT, class M, std::size_t I>
92 using xoffset_adaptor = xfunctor_adaptor<detail::offset_forwarder<M, I>, CT>;
93}
94
95#endif
standard mathematical functions for xexpressions