DPNP C++ backend kernel library 0.18.0dev0
Data Parallel Extension for NumPy*
Loading...
Searching...
No Matches
dpnp_fptr.hpp
1//*****************************************************************************
2// Copyright (c) 2016-2025, 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//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23// THE POSSIBILITY OF SUCH DAMAGE.
24//*****************************************************************************
25
26/*
27 * This header file contains internal function declarations related to FPTR
28 * interface. It should not contains public declarations
29 */
30
31#pragma once
32#ifndef BACKEND_FPTR_H // Cython compatibility
33#define BACKEND_FPTR_H
34
35#include <complex>
36#include <map>
37#include <stdexcept>
38
39#include <sycl/sycl.hpp>
40
41#include <dpnp_iface_fptr.hpp>
42
57typedef std::map<DPNPFuncType, DPNPFuncData_t> map_2p_t;
58typedef std::map<DPNPFuncType, map_2p_t> map_1p_t;
59typedef std::map<DPNPFuncName, map_1p_t> func_map_t;
60
71
76template <typename T, typename... Ts>
77struct is_any : std::disjunction<std::is_same<T, Ts>...>
78{
79};
80
85template <typename T, typename... Ts>
86struct are_same : std::conjunction<std::is_same<T, Ts>...>
87{
88};
89
93template <typename T, typename... Ts>
94constexpr auto is_any_v = is_any<T, Ts...>::value;
95
100template <typename T1, typename T2, typename... Ts>
101constexpr auto both_types_are_same =
102 std::conjunction_v<is_any<T1, Ts...>, are_same<T1, T2>>;
103
111template <typename _Tp>
112using dpnp_remove_cvref_t =
113 typename std::remove_cv_t<typename std::remove_reference_t<_Tp>>;
114
121{
122public:
123 template <typename _Xp, typename _Yp>
124 bool operator()(_Xp &&__x, _Yp &&__y) const
125 {
126 if constexpr (both_types_are_same<
127 dpnp_remove_cvref_t<_Xp>, dpnp_remove_cvref_t<_Yp>,
128 std::complex<float>, std::complex<double>>)
129 {
130 bool ret = false;
131 _Xp a = std::forward<_Xp>(__x);
132 _Yp b = std::forward<_Yp>(__y);
133
134 if (a.real() < b.real()) {
135 ret = (a.imag() == a.imag() || b.imag() != b.imag());
136 }
137 else if (a.real() > b.real()) {
138 ret = (b.imag() != b.imag() && a.imag() == a.imag());
139 }
140 else if (a.real() == b.real() ||
141 (a.real() != a.real() && b.real() != b.real())) {
142 ret = (a.imag() < b.imag() ||
143 (b.imag() != b.imag() && a.imag() == a.imag()));
144 }
145 else {
146 ret = (b.real() != b.real());
147 }
148 return ret;
149 }
150 else {
151 return std::forward<_Xp>(__x) < std::forward<_Yp>(__y);
152 }
153 }
154};
155
159void func_map_init_arraycreation(func_map_t &fmap);
160void func_map_init_elemwise(func_map_t &fmap);
161void func_map_init_linalg(func_map_t &fmap);
162void func_map_init_mathematical(func_map_t &fmap);
163void func_map_init_random(func_map_t &fmap);
164void func_map_init_sorting(func_map_t &fmap);
165
166#endif // BACKEND_FPTR_H
"<" comparison with complex types support.
DPNPFuncType
Template types which are used in this interface.