DPNP C++ backend kernel library 0.20.0dev0
Data Parallel Extension for NumPy*
Loading...
Searching...
No Matches
dpnp_fptr.hpp
1//*****************************************************************************
2// Copyright (c) 2016, Intel Corporation
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7// - Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// - Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// - Neither the name of the copyright holder nor the names of its contributors
13// may be used to endorse or promote products derived from this software
14// without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26// THE POSSIBILITY OF SUCH DAMAGE.
27//*****************************************************************************
28
29/*
30 * This header file contains internal function declarations related to FPTR
31 * interface. It should not contains public declarations
32 */
33
34#pragma once
35#ifndef BACKEND_FPTR_H // Cython compatibility
36#define BACKEND_FPTR_H
37
38#include <complex>
39#include <map>
40#include <stdexcept>
41
42#include <sycl/sycl.hpp>
43
44#include <dpnp_iface_fptr.hpp>
45
60typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
61typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
62typedef std::map<DPNPFuncName, map_1p_t> func_map_t;
63
74
79template <typename T, typename... Ts>
80struct is_any : std::disjunction<std::is_same<T, Ts>...>
81{
82};
83
88template <typename T, typename... Ts>
89struct are_same : std::conjunction<std::is_same<T, Ts>...>
90{
91};
92
96template <typename T, typename... Ts>
97constexpr auto is_any_v = is_any<T, Ts...>::value;
98
103template <typename T1, typename T2, typename... Ts>
104constexpr auto both_types_are_same =
105 std::conjunction_v<is_any<T1, Ts...>, are_same<T1, T2>>;
106
114template <typename _Tp>
115using dpnp_remove_cvref_t =
116 typename std::remove_cv_t<typename std::remove_reference_t<_Tp>>;
117
124{
125public:
126 template <typename _Xp, typename _Yp>
127 bool operator()(_Xp &&__x, _Yp &&__y) const
128 {
129 if constexpr (both_types_are_same<
130 dpnp_remove_cvref_t<_Xp>, dpnp_remove_cvref_t<_Yp>,
131 std::complex<float>, std::complex<double>>)
132 {
133 bool ret = false;
134 _Xp a = std::forward<_Xp>(__x);
135 _Yp b = std::forward<_Yp>(__y);
136
137 if (a.real() < b.real()) {
138 ret = (a.imag() == a.imag() || b.imag() != b.imag());
139 }
140 else if (a.real() > b.real()) {
141 ret = (b.imag() != b.imag() && a.imag() == a.imag());
142 }
143 else if (a.real() == b.real() ||
144 (a.real() != a.real() && b.real() != b.real())) {
145 ret = (a.imag() < b.imag() ||
146 (b.imag() != b.imag() && a.imag() == a.imag()));
147 }
148 else {
149 ret = (b.real() != b.real());
150 }
151 return ret;
152 }
153 else {
154 return std::forward<_Xp>(__x) < std::forward<_Yp>(__y);
155 }
156 }
157};
158
162void func_map_init_arraycreation(func_map_t &fmap);
163void func_map_init_linalg(func_map_t &fmap);
164void func_map_init_mathematical(func_map_t &fmap);
165void func_map_init_random(func_map_t &fmap);
166void func_map_init_sorting(func_map_t &fmap);
167
168#endif // BACKEND_FPTR_H
"<" comparison with complex types support.
DPNPFuncType
Template types which are used in this interface.