Skip to content

Commit 0821a17

Browse files
authored
move create_container() to separate py file (#880)
1 parent a6b21aa commit 0821a17

File tree

3 files changed

+79
-30
lines changed

3 files changed

+79
-30
lines changed

dpnp/dpnp_container.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding: utf-8 -*-
2+
# *****************************************************************************
3+
# Copyright (c) 2016-2020, Intel Corporation
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# - Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions and the following disclaimer.
10+
# - Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24+
# THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Container specific part of the DPNP
29+
30+
Notes
31+
-----
32+
This module contains code and dependency on diffrent containers used in DPNP
33+
34+
"""
35+
36+
37+
import dpnp.config as config
38+
from dpnp.dparray import dparray
39+
40+
import numpy
41+
42+
43+
try:
44+
"""
45+
Detect DPCtl availability to use data container
46+
"""
47+
import dpctl.tensor as dpctl
48+
49+
config.__DPNP_DPCTL_AVAILABLE__ = True
50+
51+
except ImportError:
52+
"""
53+
No DPCtl data container available
54+
"""
55+
config.__DPNP_DPCTL_AVAILABLE__ = False
56+
57+
# config.__DPNP_DPCTL_AVAILABLE__ = False
58+
59+
60+
__all__ = [
61+
"create_output_container"
62+
]
63+
64+
65+
def create_output_container(shape, type):
66+
if config.__DPNP_OUTPUT_NUMPY__:
67+
""" Create NumPy ndarray """
68+
# TODO need to use "buffer=" parameter to use SYCL aware memory
69+
result = numpy.ndarray(shape, dtype=type)
70+
elif config.__DPNP_DPCTL_AVAILABLE__:
71+
""" Create DPCTL array """
72+
result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name)
73+
else:
74+
""" Create DPNP array """
75+
result = dparray(shape, dtype=type)
76+
77+
return result

dpnp/dpnp_iface_arraycreation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def array(x1, dtype=None, copy=True, order='C', subok=False, ndmin=0, like=None)
200200
# usm_array has no element wise assignment (aka []) and
201201
# has no "flat" property and
202202
# "usm_data.copy_from_host" doesn't work with diffrent datatypes
203-
pass
203+
return numpy.array(x1, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
204204
elif subok is not False:
205205
pass
206206
elif copy is not True:

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import numpy
3535
import dpnp.config as config
3636
import dpnp
3737
from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncType, get_dpnp_function_ptr
38+
from dpnp.dpnp_container import create_output_container
3839
from libcpp cimport bool as cpp_bool
3940
from libcpp.complex cimport complex as cpp_complex
4041

@@ -44,21 +45,6 @@ cimport cpython
4445
cimport cython
4546
cimport numpy
4647

47-
try:
48-
"""
49-
Detect DPCtl availability to use data container
50-
"""
51-
import dpctl.tensor as dpctl
52-
53-
config.__DPNP_DPCTL_AVAILABLE__ = True
54-
55-
except ImportError:
56-
"""
57-
No DPCtl data container available
58-
"""
59-
config.__DPNP_DPCTL_AVAILABLE__ = False
60-
61-
# config.__DPNP_DPCTL_AVAILABLE__ = False
6248

6349
"""
6450
Python import functions
@@ -384,20 +370,6 @@ cdef DPNPFuncType get_output_c_type(DPNPFuncName funcID,
384370
checker_throw_value_error("get_output_c_type", "dtype and out", requested_dtype, requested_out)
385371

386372

387-
def create_output_container(shape, type):
388-
if config.__DPNP_OUTPUT_NUMPY__:
389-
""" Create NumPy ndarray """
390-
# TODO need to use "buffer=" parameter to use SYCL aware memory
391-
result = numpy.ndarray(shape, dtype=type)
392-
elif config.__DPNP_DPCTL_AVAILABLE__:
393-
""" Create DPCTL array """
394-
result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name)
395-
else:
396-
""" Create DPNP array """
397-
result = dparray(shape, dtype=type)
398-
399-
return result
400-
401373
cdef dpnp_descriptor create_output_descriptor(shape_type_c output_shape,
402374
DPNPFuncType c_type,
403375
dpnp_descriptor requested_out):

0 commit comments

Comments
 (0)