• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpnp / 12895869998

21 Jan 2025 09:07PM UTC coverage: 71.211% (+0.4%) from 70.856%
12895869998

Pull #2201

github

web-flow
Merge cf50357ca into 356184a29
Pull Request #2201: Implement extension for `dpnp.choose`

4568 of 9390 branches covered (48.65%)

Branch coverage included in aggregate %.

282 of 333 new or added lines in 5 files covered. (84.68%)

4 existing lines in 3 files now uncovered.

16935 of 20806 relevant lines covered (81.39%)

20542.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.37
/dpnp/dpnp_algo/dpnp_algo.pyx
1
# cython: language_level=3
1✔
2
# cython: linetrace=True
3
# -*- coding: utf-8 -*-
4
# *****************************************************************************
5
# Copyright (c) 2016-2025, Intel Corporation
6
# All rights reserved.
7
#
8
# Redistribution and use in source and binary forms, with or without
9
# modification, are permitted provided that the following conditions are met:
10
# - Redistributions of source code must retain the above copyright notice,
11
#   this list of conditions and the following disclaimer.
12
# - Redistributions in binary form must reproduce the above copyright notice,
13
#   this list of conditions and the following disclaimer in the documentation
14
#   and/or other materials provided with the distribution.
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
"""Module Backend
30

31
This module contains interface functions between C backend layer
32
and the rest of the library
33

34
"""
35

36
from libc.time cimport time, time_t
37
from libcpp.vector cimport vector
38

39
import dpctl
1✔
40

41
import dpnp
1✔
42
import dpnp.config as config
1✔
43
import dpnp.dpnp_container as dpnp_container
1✔
44
import dpnp.dpnp_utils as utils_py
1✔
45
from dpnp.dpnp_array import dpnp_array
1✔
46

47
cimport cpython
48
cimport numpy
49

50
cimport dpnp.dpnp_utils as utils
51

52
import operator
1✔
53

54
import numpy
1✔
55

56
__all__ = [
1✔
57
]
58

59

60
include "dpnp_algo_indexing.pxi"
61
include "dpnp_algo_mathematical.pxi"
62
include "dpnp_algo_sorting.pxi"
63
include "dpnp_algo_special.pxi"
64

65

66
"""
67
Internal functions
68
"""
69
cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype):
1✔
70
    dt_c = dpnp.dtype(dtype).char
1✔
71
    kind = dpnp.dtype(dtype).kind
1✔
72
    if isinstance(kind, int):
1✔
73
        kind = chr(kind)
×
74
    itemsize = dpnp.dtype(dtype).itemsize
1✔
75

76
    if dt_c == 'd':
1✔
77
        return DPNP_FT_DOUBLE
1✔
78
    elif dt_c == 'f':
1✔
79
        return DPNP_FT_FLOAT
1✔
80
    elif kind == 'i':
1✔
81
        if itemsize == 8:
1✔
82
            return DPNP_FT_LONG
1✔
83
        elif itemsize == 4:
1✔
84
            return DPNP_FT_INT
1✔
85
        else:
86
            utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)
×
87
    elif dt_c == 'F':
1✔
88
        return DPNP_FT_CMPLX64
1✔
89
    elif dt_c == 'D':
1✔
90
        return DPNP_FT_CMPLX128
1✔
91
    elif dt_c == '?':
1✔
92
        return DPNP_FT_BOOL
1✔
93
    else:
UNCOV
94
        utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)
×
95

96

97
cdef dpnp_DPNPFuncType_to_dtype(size_t type):
1✔
98
    """
99
    Type 'size_t' used instead 'DPNPFuncType' because Cython has lack of Enum support (0.29)
100
    TODO needs to use DPNPFuncType here
101
    """
102
    if type == <size_t > DPNP_FT_DOUBLE:
1✔
103
        return dpnp.float64
1✔
104
    elif type == <size_t > DPNP_FT_FLOAT:
1✔
105
        return dpnp.float32
1✔
106
    elif type == <size_t > DPNP_FT_LONG:
1✔
107
        return dpnp.int64
1✔
108
    elif type == <size_t > DPNP_FT_INT:
1✔
109
        return dpnp.int32
1✔
110
    elif type == <size_t > DPNP_FT_CMPLX64:
1✔
111
        return dpnp.complex64
1✔
112
    elif type == <size_t > DPNP_FT_CMPLX128:
1✔
113
        return dpnp.complex128
1✔
114
    elif type == <size_t > DPNP_FT_BOOL:
1✔
115
        return dpnp.bool
1✔
116
    else:
117
        utils.checker_throw_type_error("dpnp_DPNPFuncType_to_dtype", type)
×
118

119

120
cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,
1✔
121
                                                      utils.dpnp_descriptor x1,
122
                                                      object dtype=None,
123
                                                      utils.dpnp_descriptor out=None,
124
                                                      object where=True,
125
                                                      func_name=None):
126

127
    """ Convert type (x1.dtype) to C enum DPNPFuncType """
128
    cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
1✔
129

130
    """ get the FPTR data structure """
131
    cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, param1_type, param1_type)
1✔
132

133
    x1_obj = x1.get_array()
1✔
134

135
    # get FPTR function and return type
136
    cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
1✔
137
                                                                                x1_obj.sycl_device.has_aspect_fp64)
1✔
138
    cdef DPNPFuncType return_type = ret_type_and_func[0]
1✔
139
    cdef fptr_1in_1out_strides_t func = < fptr_1in_1out_strides_t > ret_type_and_func[1]
1✔
140

141
    result_type = dpnp_DPNPFuncType_to_dtype( < size_t > return_type)
1✔
142

143
    cdef shape_type_c x1_shape = x1.shape
1✔
144
    cdef shape_type_c x1_strides = utils.strides_to_vector(x1.strides, x1_shape)
1✔
145

146
    cdef shape_type_c result_shape = x1_shape
1✔
147
    cdef utils.dpnp_descriptor result
148

149
    if out is None:
1✔
150
        """ Create result array with type given by FPTR data """
151
        result = utils.create_output_descriptor(result_shape,
1✔
152
                                                return_type,
153
                                                None,
154
                                                device=x1_obj.sycl_device,
1✔
155
                                                usm_type=x1_obj.usm_type,
1✔
156
                                                sycl_queue=x1_obj.sycl_queue)
1✔
157
    else:
158
        if out.dtype != result_type:
×
159
            utils.checker_throw_value_error(func_name, 'out.dtype', out.dtype, result_type)
×
160
        if out.shape != result_shape:
×
161
            utils.checker_throw_value_error(func_name, 'out.shape', out.shape, result_shape)
×
162

163
        result = out
×
164

165
        utils.get_common_usm_allocation(x1, result)  # check USM allocation is common
×
166

167
    result_sycl_queue = result.get_array().sycl_queue
1✔
168

169
    cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
1✔
170
    cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
1✔
171

172
    cdef shape_type_c result_strides = utils.strides_to_vector(result.strides, result_shape)
1✔
173

174
    """ Call FPTR function """
175
    cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
1✔
176
                                                    result.get_data(),
1✔
177
                                                    result.size,
1✔
178
                                                    result.ndim,
1✔
179
                                                    result_shape.data(),
180
                                                    result_strides.data(),
181
                                                    x1.get_data(),
1✔
182
                                                    x1.size,
1✔
183
                                                    x1.ndim,
1✔
184
                                                    x1_shape.data(),
185
                                                    x1_strides.data(),
186
                                                    NULL,
187
                                                    NULL)  # dep_events_ref
188

189
    with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
1✔
190
    c_dpctl.DPCTLEvent_Delete(event_ref)
1✔
191

192
    return result
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc