Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Normalize all text files to use LF (\n) line endings.
# More specific rules below this line may override this default,
# for example:
# *.bat text eol=crlf
* text=auto eol=lf

dpnp/_version.py export-subst
148 changes: 74 additions & 74 deletions dpnp/dpnp_iface_utils.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
# *****************************************************************************
# Copyright (c) 2024, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************
"""
Interface of the utils function of the DPNP
Notes
-----
This module is a face or public interface file for the library
"""
import dpnp
def byte_bounds(a):
"""
Returns a 2-tuple with pointers to the end-points of the array.
For full documentation refer to :obj:`numpy.lib.array_utils.byte_bounds`.
Parameters
----------
a : {dpnp.ndarray, usm_ndarray}
Input array
Returns
-------
(low, high) : tuple of 2 integers
The first integer is the first byte of the array, the second integer is
just past the last byte of the array. If `a` is not contiguous it will
not use every byte between the (`low`, `high`) values.
Examples
--------
>>> import dpnp as np
>>> I = np.eye(2, dtype=np.complex64);
>>> low, high = np.byte_bounds(I)
>>> high - low == I.size*I.itemsize
True
>>> I = np.eye(2);
>>> low, high = np.byte_bounds(I)
>>> high - low == I.size*I.itemsize
True
"""
# pylint: disable=protected-access
return dpnp.get_usm_ndarray(a)._byte_bounds
# *****************************************************************************
# Copyright (c) 2024, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

"""
Interface of the utils function of the DPNP

Notes
-----
This module is a face or public interface file for the library

"""

import dpnp


def byte_bounds(a):
"""
Returns a 2-tuple with pointers to the end-points of the array.

For full documentation refer to :obj:`numpy.lib.array_utils.byte_bounds`.

Parameters
----------
a : {dpnp.ndarray, usm_ndarray}
Input array

Returns
-------
(low, high) : tuple of 2 integers
The first integer is the first byte of the array, the second integer is
just past the last byte of the array. If `a` is not contiguous it will
not use every byte between the (`low`, `high`) values.

Examples
--------
>>> import dpnp as np
>>> I = np.eye(2, dtype=np.complex64);
>>> low, high = np.byte_bounds(I)
>>> high - low == I.size*I.itemsize
True
>>> I = np.eye(2);
>>> low, high = np.byte_bounds(I)
>>> high - low == I.size*I.itemsize
True

"""

# pylint: disable=protected-access
return dpnp.get_usm_ndarray(a)._byte_bounds
78 changes: 39 additions & 39 deletions dpnp/tests/test_array_utils.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import dpnp
def test_byte_bounds():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
low, high = dpnp.byte_bounds(a)
assert (high - low) == (a.size * a.itemsize)
def test_unusual_order_positive_stride():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
b = a.T
low, high = dpnp.byte_bounds(b)
assert (high - low) == (b.size * b.itemsize)
def test_unusual_order_negative_stride():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
b = a.T[::-1]
low, high = dpnp.byte_bounds(b)
assert (high - low) == (b.size * b.itemsize)
def test_strided():
a = dpnp.zeros(12, dtype=dpnp.int64, usm_type="shared")
a[:] = dpnp.arange(12, dtype="int64")
b = a[::2]
low, high = dpnp.byte_bounds(b)
expected_byte_diff = b.size * 2 * b.itemsize - b.itemsize
assert (high - low) == expected_byte_diff
import dpnp


def test_byte_bounds():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
low, high = dpnp.byte_bounds(a)
assert (high - low) == (a.size * a.itemsize)


def test_unusual_order_positive_stride():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
b = a.T
low, high = dpnp.byte_bounds(b)
assert (high - low) == (b.size * b.itemsize)


def test_unusual_order_negative_stride():
a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared")
values = dpnp.arange(12, dtype="int64")
for i in range(3):
a[i, :] = values[i * 4 : (i + 1) * 4]
b = a.T[::-1]
low, high = dpnp.byte_bounds(b)
assert (high - low) == (b.size * b.itemsize)


def test_strided():
a = dpnp.zeros(12, dtype=dpnp.int64, usm_type="shared")
a[:] = dpnp.arange(12, dtype="int64")
b = a[::2]
low, high = dpnp.byte_bounds(b)
expected_byte_diff = b.size * 2 * b.itemsize - b.itemsize
assert (high - low) == expected_byte_diff
Loading
Loading