DPNP C++ backend kernel library 0.22.0dev2
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#include <type_traits>
42
43#include <sycl/sycl.hpp>
44
45#include <dpnp_iface_fptr.hpp>
46
61typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
62typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
63typedef std::map<DPNPFuncName, map_1p_t> func_map_t;
64
75
80template <typename T, typename... Ts>
81struct is_any : std::disjunction<std::is_same<T, Ts>...>
82{
83};
84
89template <typename T, typename... Ts>
90struct are_same : std::conjunction<std::is_same<T, Ts>...>
91{
92};
93
97template <typename T, typename... Ts>
98constexpr auto is_any_v = is_any<T, Ts...>::value;
99
104template <typename T1, typename T2, typename... Ts>
105constexpr auto both_types_are_same =
106 std::conjunction_v<is_any<T1, Ts...>, are_same<T1, T2>>;
107
114{
115public:
116 template <typename _Xp, typename _Yp>
117 bool operator()(_Xp &&__x, _Yp &&__y) const
118 {
119 if constexpr (both_types_are_same<
120 std::remove_cvref_t<_Xp>, std::remove_cvref_t<_Yp>,
121 std::complex<float>, std::complex<double>>) {
122 bool ret = false;
123 _Xp a = std::forward<_Xp>(__x);
124 _Yp b = std::forward<_Yp>(__y);
125
126 if (a.real() < b.real()) {
127 ret = (a.imag() == a.imag() || b.imag() != b.imag());
128 }
129 else if (a.real() > b.real()) {
130 ret = (b.imag() != b.imag() && a.imag() == a.imag());
131 }
132 else if (a.real() == b.real() ||
133 (a.real() != a.real() && b.real() != b.real())) {
134 ret = (a.imag() < b.imag() ||
135 (b.imag() != b.imag() && a.imag() == a.imag()));
136 }
137 else {
138 ret = (b.real() != b.real());
139 }
140 return ret;
141 }
142 else {
143 return std::forward<_Xp>(__x) < std::forward<_Yp>(__y);
144 }
145 }
146};
147
151void func_map_init_arraycreation(func_map_t &fmap);
152void func_map_init_linalg(func_map_t &fmap);
153void func_map_init_random(func_map_t &fmap);
154void func_map_init_sorting(func_map_t &fmap);
155
156#endif // BACKEND_FPTR_H
"<" comparison with complex types support.
DPNPFuncType
Template types which are used in this interface.