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

IntelPython / dpnp / 16126000227

07 Jul 2025 07:24PM UTC coverage: 22.684% (-49.4%) from 72.051%
16126000227

Pull #2519

github

web-flow
Merge bd753a3a3 into 624f14f20
Pull Request #2519: tmp changes

889 of 9756 branches covered (9.11%)

Branch coverage included in aggregate %.

6317 of 22011 relevant lines covered (28.7%)

35.96 hits per line

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

61.06
/dpnp/dpnp_array.py
1
# -*- coding: utf-8 -*-
2
# *****************************************************************************
3
# Copyright (c) 2016-2025, 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
import dpctl.tensor as dpt
1✔
28
from dpctl.tensor._numpy_helper import AxisError
1✔
29

30
import dpnp
1✔
31

32

33
def _get_unwrapped_index_key(key):
1✔
34
    """
35
    Get an unwrapped index key.
36

37
    Return a key where each nested instance of DPNP array is unwrapped into USM ndarray
38
    for further processing in DPCTL advanced indexing functions.
39

40
    """
41

42
    if isinstance(key, tuple):
1✔
43
        if any(isinstance(x, dpnp_array) for x in key):
1✔
44
            # create a new tuple from the input key with unwrapped DPNP arrays
45
            return tuple(
1✔
46
                x.get_array() if isinstance(x, dpnp_array) else x for x in key
47
            )
48
    elif isinstance(key, dpnp_array):
1!
49
        return key.get_array()
×
50
    return key
1✔
51

52

53
class dpnp_array:
1✔
54
    """
55
    Multi-dimensional array object.
56

57
    This is a wrapper around dpctl.tensor.usm_ndarray that provides
58
    methods to be compliant with original NumPy.
59

60
    """
61

62
    def __init__(
1✔
63
        self,
64
        shape,
65
        dtype=None,
66
        buffer=None,
67
        offset=0,
68
        strides=None,
69
        order="C",
70
        device=None,
71
        usm_type="device",
72
        sycl_queue=None,
73
    ):
74
        if order is None:
1!
75
            order = "C"
×
76

77
        if buffer is not None:
1!
78
            buffer = dpnp.get_usm_ndarray(buffer)
×
79

80
            if dtype is None:
×
81
                dtype = buffer.dtype
×
82
        else:
83
            buffer = usm_type
1✔
84

85
        sycl_queue_normalized = dpnp.get_normalized_queue_device(
1✔
86
            device=device, sycl_queue=sycl_queue
87
        )
88

89
        self._array_obj = dpt.usm_ndarray(
1✔
90
            shape,
91
            dtype=dtype,
92
            strides=strides,
93
            buffer=buffer,
94
            offset=offset,
95
            order=order,
96
            buffer_ctor_kwargs={"queue": sycl_queue_normalized},
97
            array_namespace=dpnp,
98
        )
99

100
    @property
1✔
101
    def __sycl_usm_array_interface__(self):
1✔
102
        return self._array_obj.__sycl_usm_array_interface__
1✔
103

104
    def get_array(self):
1✔
105
        """Get usm_ndarray object."""
106
        return self._array_obj
1✔
107

108
    @property
1✔
109
    def T(self):
1✔
110
        """View of the transposed array."""
111
        return self.transpose()
×
112

113
    @property
1✔
114
    def mT(self):
1✔
115
        """
116
        View of the matrix transposed array.
117

118
        The matrix transpose is the transpose of the last two dimensions, even
119
        if the array is of higher dimension.
120

121
        Raises
122
        ------
123
        ValueError
124
            If the array is of dimension less than 2.
125

126
        Examples
127
        --------
128
        >>> import dpnp as np
129
        >>> a = np.array([[1, 2], [3, 4]])
130
        >>> a
131
        array([[1, 2],
132
               [3, 4]])
133
        >>> a.mT
134
        array([[1, 3],
135
               [2, 4]])
136

137
        >>> a = np.arange(8).reshape((2, 2, 2))
138
        >>> a
139
        array([[[0, 1],
140
                [2, 3]],
141
               [[4, 5],
142
                [6, 7]]])
143
        >>> a.mT
144
        array([[[0, 2],
145
                [1, 3]],
146
               [[4, 6],
147
                [5, 7]]])
148

149
        """
150

151
        if self.ndim < 2:
×
152
            raise ValueError("matrix transpose with ndim < 2 is undefined")
×
153

154
        return dpnp_array._create_from_usm_ndarray(self._array_obj.mT)
×
155

156
    @property
1✔
157
    def sycl_queue(self):
1✔
158
        return self._array_obj.sycl_queue
1✔
159

160
    @property
1✔
161
    def sycl_device(self):
1✔
162
        return self._array_obj.sycl_device
1✔
163

164
    @property
1✔
165
    def sycl_context(self):
1✔
166
        return self._array_obj.sycl_context
×
167

168
    @property
1✔
169
    def device(self):
1✔
170
        return self._array_obj.device
×
171

172
    @property
1✔
173
    def usm_type(self):
1✔
174
        return self._array_obj.usm_type
1✔
175

176
    def __abs__(self):
1✔
177
        r"""Return ``\|self\|``."""
178
        return dpnp.abs(self)
×
179

180
    def __add__(self, other):
1✔
181
        """Return ``self+value``."""
182
        return dpnp.add(self, other)
1✔
183

184
    def __and__(self, other):
1✔
185
        """Return ``self&value``."""
186
        return dpnp.bitwise_and(self, other)
×
187

188
    def __array__(self, dtype=None, /, *, copy=None):
1✔
189
        raise TypeError(
×
190
            "Implicit conversion to a NumPy array is not allowed. "
191
            "Please use `.asnumpy()` to construct a NumPy array explicitly."
192
        )
193

194
    # '__array_finalize__',
195
    # '__array_function__',
196
    # '__array_interface__',
197
    # '__array_prepare__',
198
    # '__array_priority__',
199
    # '__array_struct__',
200

201
    __array_ufunc__ = None
1✔
202

203
    # '__array_wrap__',
204

205
    def __array_namespace__(self, /, *, api_version=None):
1✔
206
        """
207
        Returns array namespace, member functions of which implement data API.
208

209
        Parameters
210
        ----------
211
        api_version : str, optional
212
            Request namespace compliant with given version of array API. If
213
            ``None``, namespace for the most recent supported version is
214
            returned.
215
            Default: ``None``.
216

217
        Returns
218
        -------
219
        out : any
220
            An object representing the array API namespace. It should have
221
            every top-level function defined in the specification as
222
            an attribute. It may contain other public names as well, but it is
223
            recommended to only include those names that are part of the
224
            specification.
225

226
        """
227

228
        return self._array_obj.__array_namespace__(api_version=api_version)
×
229

230
    def __bool__(self):
1✔
231
        """``True`` if self else ``False``."""
232
        return self._array_obj.__bool__()
1✔
233

234
    # '__class__',
235
    # `__class_getitem__`,
236

237
    def __complex__(self):
1✔
238
        return self._array_obj.__complex__()
×
239

240
    # '__contains__',
241

242
    def __copy__(self):
1✔
243
        """
244
        Used if :func:`copy.copy` is called on an array. Returns a copy of the array.
245

246
        Equivalent to ``a.copy(order="K")``.
247

248
        """
249
        return self.copy(order="K")
×
250

251
    # '__deepcopy__',
252
    # '__delattr__',
253
    # '__delitem__',
254
    # '__dir__',
255
    # '__divmod__',
256
    # '__doc__',
257

258
    def __dlpack__(
1✔
259
        self, *, stream=None, max_version=None, dl_device=None, copy=None
260
    ):
261
        """
262
        Produces DLPack capsule.
263

264
        Parameters
265
        ----------
266
        stream : {:class:`dpctl.SyclQueue`, None}, optional
267
            Execution queue to synchronize with. If ``None``, synchronization
268
            is not performed.
269
            Default: ``None``.
270
        max_version {tuple of ints, None}, optional
271
            The maximum DLPack version the consumer (caller of ``__dlpack__``)
272
            supports. As ``__dlpack__`` may not always return a DLPack capsule
273
            with version `max_version`, the consumer must verify the version
274
            even if this argument is passed.
275
            Default: ``None``.
276
        dl_device {tuple, None}, optional:
277
            The device the returned DLPack capsule will be placed on. The
278
            device must be a 2-tuple matching the format of
279
            ``__dlpack_device__`` method, an integer enumerator representing
280
            the device type followed by an integer representing the index of
281
            the device.
282
            Default: ``None``.
283
        copy {bool, None}, optional:
284
            Boolean indicating whether or not to copy the input.
285

286
            * If `copy` is ``True``, the input will always be copied.
287
            * If ``False``, a ``BufferError`` will be raised if a copy is
288
              deemed necessary.
289
            * If ``None``, a copy will be made only if deemed necessary,
290
              otherwise, the existing memory buffer will be reused.
291

292
            Default: ``None``.
293

294
        Raises
295
        ------
296
        MemoryError:
297
            when host memory can not be allocated.
298
        DLPackCreationError:
299
            when array is allocated on a partitioned SYCL device, or with
300
            a non-default context.
301
        BufferError:
302
            when a copy is deemed necessary but `copy` is ``False`` or when
303
            the provided `dl_device` cannot be handled.
304

305
        """
306

307
        return self._array_obj.__dlpack__(
×
308
            stream=stream,
309
            max_version=max_version,
310
            dl_device=dl_device,
311
            copy=copy,
312
        )
313

314
    def __dlpack_device__(self):
1✔
315
        """
316
        Gives a tuple (``device_type``, ``device_id``) corresponding to
317
        ``DLDevice`` entry in ``DLTensor`` in DLPack protocol.
318

319
        The tuple describes the non-partitioned device where the array has been
320
        allocated, or the non-partitioned parent device of the allocation
321
        device.
322

323
        Raises
324
        ------
325
        DLPackCreationError:
326
            when the ``device_id`` could not be determined.
327

328
        """
329

330
        return self._array_obj.__dlpack_device__()
×
331

332
    def __eq__(self, other):
1✔
333
        """Return ``self==value``."""
334
        return dpnp.equal(self, other)
1✔
335

336
    def __float__(self):
1✔
337
        return self._array_obj.__float__()
×
338

339
    def __floordiv__(self, other):
1✔
340
        """Return ``self//value``."""
341
        return dpnp.floor_divide(self, other)
×
342

343
    # '__format__',
344

345
    def __ge__(self, other):
1✔
346
        """Return ``self>=value``."""
347
        return dpnp.greater_equal(self, other)
×
348

349
    # '__getattribute__',
350

351
    def __getitem__(self, key):
1✔
352
        """Return ``self[key]``."""
353
        key = _get_unwrapped_index_key(key)
1✔
354

355
        item = self._array_obj.__getitem__(key)
1✔
356
        return dpnp_array._create_from_usm_ndarray(item)
1✔
357

358
    # '__getstate__',
359

360
    def __gt__(self, other):
1✔
361
        """Return ``self>value``."""
362
        return dpnp.greater(self, other)
×
363

364
    # '__hash__',
365

366
    def __iadd__(self, other):
1✔
367
        """Return ``self+=value``."""
368
        dpnp.add(self, other, out=self)
×
369
        return self
×
370

371
    def __iand__(self, other):
1✔
372
        """Return ``self&=value``."""
373
        dpnp.bitwise_and(self, other, out=self)
×
374
        return self
×
375

376
    def __ifloordiv__(self, other):
1✔
377
        """Return ``self//=value``."""
378
        dpnp.floor_divide(self, other, out=self)
×
379
        return self
×
380

381
    def __ilshift__(self, other):
1✔
382
        """Return ``self<<=value``."""
383
        dpnp.left_shift(self, other, out=self)
×
384
        return self
×
385

386
    def __imatmul__(self, other):
1✔
387
        """Return ``self@=value``."""
388

389
        """
1✔
390
        Unlike `matmul(a, b, out=a)` we ensure that the result is not broadcast
391
        if the result without `out` would have less dimensions than `a`.
392
        Since the signature of matmul is '(n?,k),(k,m?)->(n?,m?)' this is the
393
        case exactly when the second operand has both core dimensions.
394
        We have to enforce this check by passing the correct `axes=`.
395
        """
396
        if self.ndim == 1:
1✔
397
            axes = [(-1,), (-2, -1), (-1,)]
1✔
398
        else:
399
            axes = [(-2, -1), (-2, -1), (-2, -1)]
1✔
400

401
        try:
1✔
402
            dpnp.matmul(self, other, out=self, dtype=self.dtype, axes=axes)
1✔
403
        except AxisError:
1✔
404
            # AxisError should indicate that the axes argument didn't work out
405
            # which should mean the second operand not being 2 dimensional.
406
            raise ValueError(
1✔
407
                "inplace matrix multiplication requires the first operand to "
408
                "have at least one and the second at least two dimensions."
409
            )
410
        return self
1✔
411

412
    def __imod__(self, other):
1✔
413
        """Return ``self%=value``."""
414
        dpnp.remainder(self, other, out=self)
×
415
        return self
×
416

417
    def __imul__(self, other):
1✔
418
        """Return ``self*=value``."""
419
        dpnp.multiply(self, other, out=self)
×
420
        return self
×
421

422
    def __index__(self):
1✔
423
        return self._array_obj.__index__()
1✔
424

425
    # '__init__',
426
    # '__init_subclass__',
427

428
    def __int__(self):
1✔
429
        return self._array_obj.__int__()
×
430

431
    def __invert__(self):
1✔
432
        """Return ``~self``."""
433
        return dpnp.invert(self)
×
434

435
    def __ior__(self, other):
1✔
436
        """Return ``self|=value``."""
437
        dpnp.bitwise_or(self, other, out=self)
×
438
        return self
×
439

440
    def __ipow__(self, other):
1✔
441
        """Return ``self**=value``."""
442
        dpnp.power(self, other, out=self)
×
443
        return self
×
444

445
    def __irshift__(self, other):
1✔
446
        """Return ``self>>=value``."""
447
        dpnp.right_shift(self, other, out=self)
×
448
        return self
×
449

450
    def __isub__(self, other):
1✔
451
        """Return ``self-=value``."""
452
        dpnp.subtract(self, other, out=self)
1✔
453
        return self
1✔
454

455
    def __iter__(self):
1✔
456
        """Return ``iter(self)``."""
457
        if self.ndim == 0:
×
458
            raise TypeError("iteration over a 0-d array")
×
459
        return (self[i] for i in range(self.shape[0]))
×
460

461
    def __itruediv__(self, other):
1✔
462
        """Return ``self/=value``."""
463
        dpnp.true_divide(self, other, out=self)
×
464
        return self
×
465

466
    def __ixor__(self, other):
1✔
467
        """Return ``self^=value``."""
468
        dpnp.bitwise_xor(self, other, out=self)
×
469
        return self
×
470

471
    def __le__(self, other):
1✔
472
        """Return ``self<=value``."""
473
        return dpnp.less_equal(self, other)
×
474

475
    def __len__(self):
1✔
476
        """Return ``len(self)``."""
477
        return self._array_obj.__len__()
×
478

479
    def __lshift__(self, other):
1✔
480
        """Return ``self<<value``."""
481
        return dpnp.left_shift(self, other)
×
482

483
    def __lt__(self, other):
1✔
484
        """Return ``self<value``."""
485
        return dpnp.less(self, other)
1✔
486

487
    def __matmul__(self, other):
1✔
488
        """Return ``self@value``."""
489
        return dpnp.matmul(self, other)
1✔
490

491
    def __mod__(self, other):
1✔
492
        """Return ``self%value``."""
493
        return dpnp.remainder(self, other)
×
494

495
    def __mul__(self, other):
1✔
496
        """Return ``self*value``."""
497
        return dpnp.multiply(self, other)
1✔
498

499
    def __ne__(self, other):
1✔
500
        """Return ``self!=value``."""
501
        return dpnp.not_equal(self, other)
×
502

503
    def __neg__(self):
1✔
504
        """Return ``-self``."""
505
        return dpnp.negative(self)
×
506

507
    # '__new__',
508

509
    def __or__(self, other):
1✔
510
        """Return ``self|value``."""
511
        return dpnp.bitwise_or(self, other)
×
512

513
    def __pos__(self):
1✔
514
        """Return ``+self``."""
515
        return dpnp.positive(self)
×
516

517
    def __pow__(self, other):
1✔
518
        """Return ``self**value``."""
519
        return dpnp.power(self, other)
×
520

521
    def __radd__(self, other):
1✔
522
        """Return ``value+self``."""
523
        return dpnp.add(other, self)
×
524

525
    def __rand__(self, other):
1✔
526
        """Return ``value&self``."""
527
        return dpnp.bitwise_and(other, self)
×
528

529
    # '__rdivmod__',
530
    # '__reduce__',
531
    # '__reduce_ex__',
532

533
    def __repr__(self):
1✔
534
        """Return ``repr(self)``."""
535
        return dpt.usm_ndarray_repr(self._array_obj, prefix="array")
×
536

537
    def __rfloordiv__(self, other):
1✔
538
        """Return ``value//self``."""
539
        return dpnp.floor_divide(self, other)
×
540

541
    def __rlshift__(self, other):
1✔
542
        """Return ``value<<self``."""
543
        return dpnp.left_shift(other, self)
×
544

545
    def __rmatmul__(self, other):
1✔
546
        """Return ``value@self``."""
547
        return dpnp.matmul(other, self)
×
548

549
    def __rmod__(self, other):
1✔
550
        """Return ``value%self``."""
551
        return dpnp.remainder(other, self)
×
552

553
    def __rmul__(self, other):
1✔
554
        """Return ``value*self``."""
555
        return dpnp.multiply(other, self)
×
556

557
    def __ror__(self, other):
1✔
558
        """Return ``value|self``."""
559
        return dpnp.bitwise_or(other, self)
×
560

561
    def __rpow__(self, other):
1✔
562
        """Return ``value**self``."""
563
        return dpnp.power(other, self)
×
564

565
    def __rrshift__(self, other):
1✔
566
        """Return ``value>>self``."""
567
        return dpnp.right_shift(other, self)
×
568

569
    def __rshift__(self, other):
1✔
570
        """Return ``self>>value``."""
571
        return dpnp.right_shift(self, other)
×
572

573
    def __rsub__(self, other):
1✔
574
        """Return ``value-self``."""
575
        return dpnp.subtract(other, self)
×
576

577
    def __rtruediv__(self, other):
1✔
578
        """Return ``value/self``."""
579
        return dpnp.true_divide(other, self)
×
580

581
    def __rxor__(self, other):
1✔
582
        """Return ``value^self``."""
583
        return dpnp.bitwise_xor(other, self)
×
584

585
    # '__setattr__',
586

587
    def __setitem__(self, key, val):
1✔
588
        """Set ``self[key]`` to value."""
589
        key = _get_unwrapped_index_key(key)
1✔
590

591
        if isinstance(val, dpnp_array):
1✔
592
            val = val.get_array()
1✔
593

594
        self._array_obj.__setitem__(key, val)
1✔
595

596
    # '__setstate__',
597
    # '__sizeof__',
598

599
    __slots__ = ("_array_obj",)
1✔
600

601
    def __str__(self):
1✔
602
        """Return ``str(self)``."""
603
        return self._array_obj.__str__()
×
604

605
    def __sub__(self, other):
1✔
606
        """Return ``self-value``."""
607
        return dpnp.subtract(self, other)
×
608

609
    # '__subclasshook__',
610

611
    def __truediv__(self, other):
1✔
612
        """Return ``self/value``."""
613
        return dpnp.true_divide(self, other)
×
614

615
    @property
1✔
616
    def __usm_ndarray__(self):
1✔
617
        """
618
        Property to support `__usm_ndarray__` protocol.
619

620
        It assumes to return :class:`dpctl.tensor.usm_ndarray` instance
621
        corresponding to the content of the object.
622

623
        This property is intended to speed-up conversion from
624
        :class:`dpnp.ndarray` to :class:`dpctl.tensor.usm_ndarray` passed
625
        into  `dpctl.tensor.asarray` function. The input object that implements
626
        `__usm_ndarray__` protocol is recognized as owner of USM allocation
627
        that is managed by a smart pointer, and asynchronous deallocation
628
        will not involve GIL.
629

630
        """
631

632
        return self._array_obj
×
633

634
    def __xor__(self, other):
1✔
635
        """Return ``self^value``."""
636
        return dpnp.bitwise_xor(self, other)
×
637

638
    @staticmethod
1✔
639
    def _create_from_usm_ndarray(usm_ary: dpt.usm_ndarray):
1✔
640
        if not isinstance(usm_ary, dpt.usm_ndarray):
1!
641
            raise TypeError(
×
642
                f"Expected dpctl.tensor.usm_ndarray, got {type(usm_ary)}"
643
            )
644
        res = dpnp_array.__new__(dpnp_array)
1✔
645
        res._array_obj = usm_ary
1✔
646
        res._array_obj._set_namespace(dpnp)
1✔
647
        return res
1✔
648

649
    def all(self, axis=None, out=None, keepdims=False, *, where=True):
1✔
650
        """
651
        Returns True if all elements evaluate to True.
652

653
        Refer to :obj:`dpnp.all` for full documentation.
654

655
        See Also
656
        --------
657
        :obj:`dpnp.all` : equivalent function
658

659
        """
660

661
        return dpnp.all(
×
662
            self, axis=axis, out=out, keepdims=keepdims, where=where
663
        )
664

665
    def any(self, axis=None, out=None, keepdims=False, *, where=True):
1✔
666
        """
667
        Returns True if any of the elements of `a` evaluate to True.
668

669
        Refer to :obj:`dpnp.any` for full documentation.
670

671
        See Also
672
        --------
673
        :obj:`dpnp.any` : equivalent function
674

675
        """
676

677
        return dpnp.any(
×
678
            self, axis=axis, out=out, keepdims=keepdims, where=where
679
        )
680

681
    def argmax(self, axis=None, out=None, *, keepdims=False):
1✔
682
        """
683
        Returns array of indices of the maximum values along the given axis.
684

685
        Refer to :obj:`dpnp.argmax` for full documentation.
686

687
        """
688

689
        return dpnp.argmax(self, axis=axis, out=out, keepdims=keepdims)
×
690

691
    def argmin(self, axis=None, out=None, *, keepdims=False):
1✔
692
        """
693
        Return array of indices to the minimum values along the given axis.
694

695
        Refer to :obj:`dpnp.argmin` for full documentation.
696

697
        """
698

699
        return dpnp.argmin(self, axis=axis, out=out, keepdims=keepdims)
×
700

701
    # 'argpartition',
702

703
    def argsort(
1✔
704
        self, axis=-1, kind=None, order=None, *, descending=False, stable=None
705
    ):
706
        """
707
        Return an ndarray of indices that sort the array along the specified axis.
708

709
        Refer to :obj:`dpnp.argsort` for full documentation.
710

711
        Parameters
712
        ----------
713
        axis : {None, int}, optional
714
            Axis along which to sort. If ``None``, the array is flattened
715
            before sorting. The default is ``-1``, which sorts along the last
716
            axis.
717
            Default: ``-1``.
718
        kind : {None, "stable", "mergesort", "radixsort"}, optional
719
            Sorting algorithm. The default is ``None``, which uses parallel
720
            merge-sort or parallel radix-sort algorithms depending on the array
721
            data type.
722
            Default: ``None``.
723
        descending : bool, optional
724
            Sort order. If ``True``, the array must be sorted in descending
725
            order (by value). If ``False``, the array must be sorted in
726
            ascending order (by value).
727
            Default: ``False``.
728
        stable : {None, bool}, optional
729
            Sort stability. If ``True``, the returned array will maintain the
730
            relative order of `a` values which compare as equal. The same
731
            behavior applies when set to ``False`` or ``None``.
732
            Internally, this option selects ``kind="stable"``.
733
            Default: ``None``.
734

735
        See Also
736
        --------
737
        :obj:`dpnp.sort` : Return a sorted copy of an array.
738
        :obj:`dpnp.argsort` : Return the indices that would sort an array.
739
        :obj:`dpnp.lexsort` : Indirect stable sort on multiple keys.
740
        :obj:`dpnp.searchsorted` : Find elements in a sorted array.
741
        :obj:`dpnp.partition` : Partial sort.
742

743
        Examples
744
        --------
745
        >>> import dpnp as np
746
        >>> a = np.array([3, 1, 2])
747
        >>> a.argsort()
748
        array([1, 2, 0])
749

750
        >>> a = np.array([[0, 3], [2, 2]])
751
        >>> a.argsort(axis=0)
752
        array([[0, 1],
753
               [1, 0]])
754

755
        """
756

757
        return dpnp.argsort(
×
758
            self, axis, kind, order, descending=descending, stable=stable
759
        )
760

761
    def asnumpy(self):
1✔
762
        """
763
        Copy content of the array into :class:`numpy.ndarray` instance of
764
        the same shape and data type.
765

766
        Returns
767
        -------
768
        out : numpy.ndarray
769
            An instance of :class:`numpy.ndarray` populated with the array
770
            content.
771

772
        """
773

774
        return dpt.asnumpy(self._array_obj)
1✔
775

776
    def astype(
1✔
777
        self,
778
        dtype,
779
        order="K",
780
        casting="unsafe",
781
        subok=True,
782
        copy=True,
783
        device=None,
784
    ):
785
        """
786
        Copy the array with data type casting.
787

788
        Refer to :obj:`dpnp.astype` for full documentation.
789

790
        Parameters
791
        ----------
792
        dtype : {None, str, dtype object}
793
            Target data type.
794
        order : {None, "C", "F", "A", "K"}, optional
795
            Row-major (C-style) or column-major (Fortran-style) order.
796
            When `order` is ``"A"``, it uses ``"F"`` if `a` is column-major and
797
            uses ``"C"`` otherwise. And when `order` is ``"K"``, it keeps
798
            strides as closely as possible.
799

800
            Default: ``"K"``.
801
        casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional
802
            Controls what kind of data casting may occur. Defaults to
803
            ``"unsafe"`` for backwards compatibility.
804

805
                - "no" means the data types should not be cast at all.
806
                - "equiv" means only byte-order changes are allowed.
807
                - "safe" means only casts which can preserve values are allowed.
808
                - "same_kind" means only safe casts or casts within a kind,
809
                  like float64 to float32, are allowed.
810
                - "unsafe" means any data conversions may be done.
811

812
            Default: ``"unsafe"``.
813
        copy : bool, optional
814
            Specifies whether to copy an array when the specified dtype matches
815
            the data type of that array. If ``True``, a newly allocated array
816
            must always be returned. If ``False`` and the specified dtype
817
            matches the data type of that array, the self array must be returned;
818
            otherwise, a newly allocated array must be returned.
819

820
            Default: ``True``.
821
        device : {None, string, SyclDevice, SyclQueue, Device}, optional
822
            An array API concept of device where the output array is created.
823
            `device` can be ``None``, a oneAPI filter selector string,
824
            an instance of :class:`dpctl.SyclDevice` corresponding to
825
            a non-partitioned SYCL device, an instance of
826
            :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object
827
            returned by :attr:`dpnp.ndarray.device`.
828
            If the value is ``None``, returned array is created on the same
829
            device as that array.
830

831
            Default: ``None``.
832

833
        Returns
834
        -------
835
        out : dpnp.ndarray
836
            An array having the specified data type.
837

838
        Limitations
839
        -----------
840
        Parameter `subok` is supported with default value.
841
        Otherwise ``NotImplementedError`` exception will be raised.
842

843
        Examples
844
        --------
845
        >>> import dpnp as np
846
        >>> x = np.array([1, 2, 2.5]); x
847
        array([1. , 2. , 2.5])
848

849
        >>> x.astype(int)
850
        array([1, 2, 2])
851

852
        """
853

854
        if subok is not True:
1!
855
            raise NotImplementedError(
×
856
                f"subok={subok} is currently not supported"
857
            )
858

859
        return dpnp.astype(
1✔
860
            self, dtype, order=order, casting=casting, copy=copy, device=device
861
        )
862

863
    # 'base',
864
    # 'byteswap',
865

866
    def choose(self, /, choices, out=None, mode="wrap"):
1✔
867
        """
868
        Use an array as index array to construct a new array from a set of choices.
869

870
        Refer to :obj:`dpnp.choose` for full documentation.
871

872
        """
873

874
        return dpnp.choose(self, choices, out, mode)
×
875

876
    def clip(self, min=None, max=None, out=None, **kwargs):
1✔
877
        """
878
        Clip (limit) the values in an array.
879

880
        Refer to :obj:`dpnp.clip` for full documentation.
881

882
        """
883

884
        return dpnp.clip(self, min, max, out=out, **kwargs)
×
885

886
    def compress(self, condition, axis=None, out=None):
1✔
887
        """
888
        Select slices of an array along a given axis.
889

890
        Refer to :obj:`dpnp.compress` for full documentation.
891
        """
892

893
        return dpnp.compress(condition, self, axis=axis, out=out)
×
894

895
    def conj(self):
1✔
896
        """
897
        Complex-conjugate all elements.
898

899
        Refer to :obj:`dpnp.conjugate` for full documentation.
900

901
        """
902

903
        if not dpnp.issubdtype(self.dtype, dpnp.complexfloating):
×
904
            return self
×
905
        else:
906
            return dpnp.conjugate(self)
×
907

908
    def conjugate(self):
1✔
909
        """
910
        Return the complex conjugate, element-wise.
911

912
        Refer to :obj:`dpnp.conjugate` for full documentation.
913

914
        """
915

916
        if not dpnp.issubdtype(self.dtype, dpnp.complexfloating):
×
917
            return self
×
918
        else:
919
            return dpnp.conjugate(self)
×
920

921
    def copy(self, order="C", device=None, usm_type=None, sycl_queue=None):
1✔
922
        """
923
        Return a copy of the array.
924

925
        Refer to :obj:`dpnp.copy` for full documentation.
926

927
        Parameters
928
        ----------
929
        order : {None, "C", "F", "A", "K"}, optional
930
            Memory layout of the newly output array.
931
            Default: ``"C"``.
932
        device : {None, string, SyclDevice, SyclQueue, Device}, optional
933
            An array API concept of device where the output array is created.
934
            `device` can be ``None``, a oneAPI filter selector string,
935
            an instance of :class:`dpctl.SyclDevice` corresponding to
936
            a non-partitioned SYCL device, an instance of
937
            :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object
938
            returned by :attr:`dpnp.ndarray.device`.
939

940
            Default: ``None``.
941
        usm_type : {None, "device", "shared", "host"}, optional
942
            The type of SYCL USM allocation for the output array.
943
            Default: ``None``.
944
        sycl_queue : {None, SyclQueue}, optional
945
            A SYCL queue to use for output array allocation and copying. The
946
            `sycl_queue` can be passed as ``None`` (the default), which means
947
            to get the SYCL queue from `device` keyword if present or to use
948
            a default queue.
949
            Default: ``None``.
950

951
        Returns
952
        -------
953
        out : dpnp.ndarray
954
            A copy of the array.
955

956
        See also
957
        --------
958
        :obj:`dpnp.copy` : Similar function with different default behavior
959
        :obj:`dpnp.copyto` : Copies values from one array to another.
960

961
        Notes
962
        -----
963
        This function is the preferred method for creating an array copy.
964
        The function :func:`dpnp.copy` is similar, but it defaults to using
965
        order ``"K"``.
966

967
        Examples
968
        --------
969
        >>> import dpnp as np
970
        >>> x = np.array([[1, 2, 3], [4, 5, 6]], order='F')
971
        >>> y = x.copy()
972
        >>> x.fill(0)
973

974
        >>> x
975
        array([[0, 0, 0],
976
               [0, 0, 0]])
977

978
        >>> y
979
        array([[1, 2, 3],
980
               [4, 5, 6]])
981

982
        >>> y.flags['C_CONTIGUOUS']
983
        True
984

985
        """
986

987
        return dpnp.copy(
×
988
            self,
989
            order=order,
990
            device=device,
991
            usm_type=usm_type,
992
            sycl_queue=sycl_queue,
993
        )
994

995
    # 'ctypes',
996

997
    def cumprod(self, axis=None, dtype=None, out=None):
1✔
998
        """
999
        Return the cumulative product of the elements along the given axis.
1000

1001
        Refer to :obj:`dpnp.cumprod` for full documentation.
1002

1003
        """
1004

1005
        return dpnp.cumprod(self, axis=axis, dtype=dtype, out=out)
×
1006

1007
    def cumsum(self, axis=None, dtype=None, out=None):
1✔
1008
        """
1009
        Return the cumulative sum of the elements along the given axis.
1010

1011
        Refer to :obj:`dpnp.cumsum` for full documentation.
1012

1013
        """
1014

1015
        return dpnp.cumsum(self, axis=axis, dtype=dtype, out=out)
×
1016

1017
    # 'data',
1018

1019
    def diagonal(self, offset=0, axis1=0, axis2=1):
1✔
1020
        """
1021
        Return specified diagonals.
1022

1023
        Refer to :obj:`dpnp.diagonal` for full documentation.
1024

1025
        See Also
1026
        --------
1027
        :obj:`dpnp.diagonal` : Equivalent function.
1028

1029
        Examples
1030
        --------
1031
        >>> import dpnp as np
1032
        >>> a = np.arange(4).reshape(2, 2)
1033
        >>> a.diagonal()
1034
        array([0, 3])
1035

1036
        """
1037

1038
        return dpnp.diagonal(self, offset=offset, axis1=axis1, axis2=axis2)
×
1039

1040
    def dot(self, b, out=None):
1✔
1041
        """
1042
        Dot product of two arrays.
1043

1044
        Refer to :obj:`dpnp.dot` for full documentation.
1045

1046
        Examples
1047
        --------
1048
        >>> import dpnp as np
1049
        >>> a = np.eye(2)
1050
        >>> b = np.ones((2, 2)) * 2
1051
        >>> a.dot(b)
1052
        array([[2., 2.],
1053
               [2., 2.]])
1054

1055
        This array method can be conveniently chained:
1056

1057
        >>> a.dot(b).dot(b)
1058
        array([[8., 8.],
1059
               [8., 8.]])
1060
        """
1061

1062
        return dpnp.dot(self, b, out)
1✔
1063

1064
    @property
1✔
1065
    def dtype(self):
1✔
1066
        """Returns NumPy's dtype corresponding to the type of the array elements."""
1067

1068
        return self._array_obj.dtype
1✔
1069

1070
    # 'dump',
1071
    # 'dumps',
1072

1073
    def fill(self, value):
1✔
1074
        """
1075
        Fill the array with a scalar value.
1076

1077
        For full documentation refer to :obj:`numpy.ndarray.fill`.
1078

1079
        Parameters
1080
        ----------
1081
        value : {dpnp.ndarray, usm_ndarray, scalar}
1082
            All elements of `a` will be assigned this value.
1083

1084
        Examples
1085
        --------
1086
        >>> import dpnp as np
1087
        >>> a = np.array([1, 2])
1088
        >>> a.fill(0)
1089
        >>> a
1090
        array([0, 0])
1091
        >>> a = np.empty(2)
1092
        >>> a.fill(1)
1093
        >>> a
1094
        array([1.,  1.])
1095

1096
        """
1097

1098
        # lazy import avoids circular imports
1099
        from .dpnp_algo.dpnp_fill import dpnp_fill
1✔
1100

1101
        dpnp_fill(self, value)
1✔
1102

1103
    @property
1✔
1104
    def flags(self):
1✔
1105
        """Return information about the memory layout of the array."""
1106

1107
        return self._array_obj.flags
1✔
1108

1109
    @property
1✔
1110
    def flat(self):
1✔
1111
        """Return a flat iterator, or set a flattened version of self to value."""
1112

1113
        return dpnp.flatiter(self)
×
1114

1115
    def flatten(self, order="C"):
1✔
1116
        """
1117
        Return a copy of the array collapsed into one dimension.
1118

1119
        For full documentation refer to :obj:`numpy.ndarray.flatten`.
1120

1121
        Parameters
1122
        ----------
1123
        order : {"C", "F"}, optional
1124
            Read the elements using this index order, and place the elements
1125
            into the reshaped array using this index order.
1126

1127
                - ``"C"`` means to read / write the elements using C-like index
1128
                  order, with the last axis index changing fastest, back to the
1129
                  first axis index changing slowest.
1130
                - ``"F"`` means to read / write the elements using Fortran-like
1131
                  index order, with the first index changing fastest, and the
1132
                  last index changing slowest.
1133

1134
            Default: ``"C"``.
1135

1136
        Returns
1137
        -------
1138
        out : dpnp.ndarray
1139
            A copy of the input array, flattened to one dimension.
1140

1141
        See Also
1142
        --------
1143
        :obj:`dpnp.ravel` : Return a flattened array.
1144
        :obj:`dpnp.flat` : A 1-D flat iterator over the array.
1145

1146
        Examples
1147
        --------
1148
        >>> import dpnp as np
1149
        >>> a = np.array([[1, 2], [3, 4]])
1150
        >>> a.flatten()
1151
        array([1, 2, 3, 4])
1152
        >>> a.flatten("F")
1153
        array([1, 3, 2, 4])
1154

1155
        """
1156

1157
        return self.reshape(-1, order=order, copy=True)
×
1158

1159
    # 'getfield',
1160

1161
    @property
1✔
1162
    def imag(self):
1✔
1163
        """
1164
        The imaginary part of the array.
1165

1166
        For full documentation refer to :obj:`numpy.ndarray.imag`.
1167

1168
        Examples
1169
        --------
1170
        >>> import dpnp as np
1171
        >>> x = np.sqrt(np.array([1+0j, 0+1j]))
1172
        >>> x.imag
1173
        array([0.        , 0.70710677])
1174

1175
        """
1176
        return dpnp_array._create_from_usm_ndarray(
×
1177
            dpnp.get_usm_ndarray(self).imag
1178
        )
1179

1180
    @imag.setter
1✔
1181
    def imag(self, value):
1✔
1182
        """
1183
        Set the imaginary part of the array.
1184

1185
        For full documentation refer to :obj:`numpy.ndarray.imag`.
1186

1187
        Examples
1188
        --------
1189
        >>> import dpnp as np
1190
        >>> a = np.array([1+2j, 3+4j, 5+6j])
1191
        >>> a.imag = 9
1192
        >>> a
1193
        array([1.+9.j, 3.+9.j, 5.+9.j])
1194

1195
        """
1196
        if dpnp.issubdtype(self.dtype, dpnp.complexfloating):
×
1197
            dpnp.copyto(self._array_obj.imag, value)
×
1198
        else:
1199
            raise TypeError("array does not have imaginary part to set")
×
1200

1201
    def item(self, *args):
1✔
1202
        """
1203
        Copy an element of an array to a standard Python scalar and return it.
1204

1205
        For full documentation refer to :obj:`numpy.ndarray.item`.
1206

1207
        Parameters
1208
        ----------
1209
        *args : {none, int, tuple of ints}
1210
            - none: in this case, the method only works for arrays with
1211
              one element (``a.size == 1``), which element is copied into a
1212
              standard Python scalar object and returned.
1213
            - int: this argument is interpreted as a flat index into the array,
1214
              specifying which element to copy and return.
1215
            - tuple of ints: functions as does a single int argument, except
1216
              that the argument is interpreted as an nd-index into the array.
1217

1218
        Returns
1219
        -------
1220
        out : Standard Python scalar object
1221
            A copy of the specified element of the array as a suitable Python scalar.
1222

1223
        Examples
1224
        --------
1225
        >>> import dpnp as np
1226
        >>> np.random.seed(123)
1227
        >>> x = np.random.randint(9, size=(3, 3))
1228
        >>> x
1229
        array([[0, 0, 7],
1230
               [6, 6, 6],
1231
               [0, 7, 1]])
1232
        >>> x.item(3)
1233
        6
1234
        >>> x.item(7)
1235
        7
1236
        >>> x.item((0, 1))
1237
        0
1238
        >>> x.item((2, 2))
1239
        1
1240

1241
        >>> x = np.array(5)
1242
        >>> x.item()
1243
        5
1244

1245
        """
1246

1247
        # TODO: implement a more efficient way to avoid copying to host
1248
        # for large arrays using `asnumpy()`
1249
        return self.asnumpy().item(*args)
×
1250

1251
    @property
1✔
1252
    def itemsize(self):
1✔
1253
        """Size of one array element in bytes."""
1254

1255
        return self._array_obj.itemsize
×
1256

1257
    def max(
1✔
1258
        self,
1259
        axis=None,
1260
        out=None,
1261
        keepdims=False,
1262
        initial=None,
1263
        where=True,
1264
    ):
1265
        """
1266
        Return the maximum along an axis.
1267

1268
        Refer to :obj:`dpnp.max` for full documentation.
1269

1270
        """
1271

1272
        return dpnp.max(
×
1273
            self,
1274
            axis=axis,
1275
            out=out,
1276
            keepdims=keepdims,
1277
            initial=initial,
1278
            where=where,
1279
        )
1280

1281
    def mean(
1✔
1282
        self, axis=None, dtype=None, out=None, keepdims=False, *, where=True
1283
    ):
1284
        """
1285
        Returns the average of the array elements.
1286

1287
        Refer to :obj:`dpnp.mean` for full documentation.
1288

1289
        """
1290

1291
        return dpnp.mean(self, axis, dtype, out, keepdims, where=where)
×
1292

1293
    def min(
1✔
1294
        self,
1295
        axis=None,
1296
        out=None,
1297
        keepdims=False,
1298
        initial=None,
1299
        where=True,
1300
    ):
1301
        """
1302
        Return the minimum along a given axis.
1303

1304
        Refer to :obj:`dpnp.min` for full documentation.
1305

1306
        """
1307

1308
        return dpnp.min(
×
1309
            self,
1310
            axis=axis,
1311
            out=out,
1312
            keepdims=keepdims,
1313
            initial=initial,
1314
            where=where,
1315
        )
1316

1317
    @property
1✔
1318
    def nbytes(self):
1✔
1319
        """Total bytes consumed by the elements of the array."""
1320

1321
        return self._array_obj.nbytes
×
1322

1323
    @property
1✔
1324
    def ndim(self):
1✔
1325
        """
1326
        Return the number of dimensions of an array.
1327

1328
        For full documentation refer to :obj:`numpy.ndarray.ndim`.
1329

1330
        Returns
1331
        -------
1332
        number_of_dimensions : int
1333
            The number of dimensions in `a`.
1334

1335
        See Also
1336
        --------
1337
        :obj:`dpnp.ndim` : Equivalent method for any array-like input.
1338
        :obj:`dpnp.shape` : Return the shape of an array.
1339
        :obj:`dpnp.ndarray.shape` : Return the shape of an array.
1340

1341
        Examples
1342
        --------
1343
        >>> import dpnp as np
1344
        >>> x = np.array([1, 2, 3])
1345
        >>> x.ndim
1346
        1
1347
        >>> y = np.zeros((2, 3, 4))
1348
        >>> y.ndim
1349
        3
1350

1351
        """
1352

1353
        return self._array_obj.ndim
1✔
1354

1355
    def nonzero(self):
1✔
1356
        """
1357
        Return the indices of the elements that are non-zero.
1358

1359
        Refer to :obj:`dpnp.nonzero` for full documentation.
1360

1361
        """
1362

1363
        return dpnp.nonzero(self)
×
1364

1365
    def partition(self, kth, axis=-1, kind="introselect", order=None):
1✔
1366
        """
1367
        Return a partitioned copy of an array.
1368

1369
        Rearranges the elements in the array in such a way that the value of
1370
        the element in `kth` position is in the position it would be in
1371
        a sorted array.
1372

1373
        All elements smaller than the `kth` element are moved before this
1374
        element and all equal or greater are moved behind it. The ordering
1375
        of the elements in the two partitions is undefined.
1376

1377
        Refer to `dpnp.partition` for full documentation.
1378

1379
        See Also
1380
        --------
1381
        :obj:`dpnp.partition` : Return a partitioned copy of an array.
1382

1383
        Examples
1384
        --------
1385
        >>> import dpnp as np
1386
        >>> a = np.array([3, 4, 2, 1])
1387
        >>> a.partition(3)
1388
        >>> a
1389
        array([1, 2, 3, 4])
1390

1391
        """
1392

1393
        self._array_obj = dpnp.partition(
×
1394
            self, kth, axis=axis, kind=kind, order=order
1395
        ).get_array()
1396

1397
    def prod(
1✔
1398
        self,
1399
        axis=None,
1400
        dtype=None,
1401
        out=None,
1402
        keepdims=False,
1403
        initial=None,
1404
        where=True,
1405
    ):
1406
        """
1407
        Returns the prod along a given axis.
1408

1409
        Refer to :obj:`dpnp.prod` for full documentation.
1410

1411
        """
1412

1413
        return dpnp.prod(
×
1414
            self,
1415
            axis=axis,
1416
            dtype=dtype,
1417
            out=out,
1418
            keepdims=keepdims,
1419
            initial=initial,
1420
            where=where,
1421
        )
1422

1423
    def put(self, indices, vals, /, *, axis=None, mode="wrap"):
1✔
1424
        """
1425
        Puts values of an array into another array along a given axis.
1426

1427
        Refer to :obj:`dpnp.put` for full documentation.
1428

1429
        """
1430

1431
        return dpnp.put(self, indices, vals, axis=axis, mode=mode)
×
1432

1433
    def ravel(self, order="C"):
1✔
1434
        """
1435
        Return a contiguous flattened array.
1436

1437
        Refer to :obj:`dpnp.ravel` for full documentation.
1438

1439
        """
1440

1441
        return dpnp.ravel(self, order=order)
1✔
1442

1443
    @property
1✔
1444
    def real(self):
1✔
1445
        """
1446
        The real part of the array.
1447

1448
        For full documentation refer to :obj:`numpy.ndarray.real`.
1449

1450
        Examples
1451
        --------
1452
        >>> import dpnp as np
1453
        >>> x = np.sqrt(np.array([1+0j, 0+1j]))
1454
        >>> x.real
1455
        array([1.        , 0.70710677])
1456

1457
        """
1458

1459
        if dpnp.issubdtype(self.dtype, dpnp.complexfloating):
×
1460
            return dpnp_array._create_from_usm_ndarray(
×
1461
                dpnp.get_usm_ndarray(self).real
1462
            )
1463
        return self
×
1464

1465
    @real.setter
1✔
1466
    def real(self, value):
1✔
1467
        """
1468
        Set the real part of the array.
1469

1470
        For full documentation refer to :obj:`numpy.ndarray.real`.
1471

1472
        Examples
1473
        --------
1474
        >>> import dpnp as np
1475
        >>> a = np.array([1+2j, 3+4j, 5+6j])
1476
        >>> a.real = 9
1477
        >>> a
1478
        array([9.+2.j, 9.+4.j, 9.+6.j])
1479

1480
        """
1481

1482
        dpnp.copyto(self._array_obj.real, value)
×
1483

1484
    def repeat(self, repeats, axis=None):
1✔
1485
        """
1486
        Repeat elements of an array.
1487

1488
        Refer to :obj:`dpnp.repeat` for full documentation.
1489

1490
        """
1491

1492
        return dpnp.repeat(self, repeats, axis=axis)
×
1493

1494
    def reshape(self, *shape, order="C", copy=None):
1✔
1495
        """
1496
        Returns an array containing the same data with a new shape.
1497

1498
        Refer to :obj:`dpnp.reshape` for full documentation.
1499

1500
        Returns
1501
        -------
1502
        y : dpnp.ndarray
1503
            This will be a new view object if possible;
1504
            otherwise, it will be a copy.
1505

1506
        See Also
1507
        --------
1508
        :obj:`dpnp.reshape` : Equivalent function.
1509

1510
        Notes
1511
        -----
1512
        Unlike the free function `dpnp.reshape`, this method on `ndarray` allows
1513
        the elements of the shape parameter to be passed in as separate arguments.
1514
        For example, ``a.reshape(10, 11)`` is equivalent to
1515
        ``a.reshape((10, 11))``.
1516

1517
        """
1518

1519
        if len(shape) == 1:
1✔
1520
            shape = shape[0]
1✔
1521
        return dpnp.reshape(self, shape, order=order, copy=copy)
1✔
1522

1523
    # 'resize',
1524

1525
    def round(self, decimals=0, out=None):
1✔
1526
        """
1527
        Return array with each element rounded to the given number of decimals.
1528

1529
        Refer to :obj:`dpnp.round` for full documentation.
1530

1531
        """
1532

1533
        return dpnp.around(self, decimals, out)
×
1534

1535
    def searchsorted(self, v, side="left", sorter=None):
1✔
1536
        """
1537
        Find indices where elements of `v` should be inserted in `a`
1538
        to maintain order.
1539

1540
        Refer to :obj:`dpnp.searchsorted` for full documentation
1541

1542
        """
1543

1544
        return dpnp.searchsorted(self, v, side=side, sorter=sorter)
×
1545

1546
    # 'setfield',
1547
    # 'setflags',
1548

1549
    @property
1✔
1550
    def shape(self):
1✔
1551
        """
1552
        Tuple of array dimensions.
1553

1554
        The shape property is usually used to get the current shape of an array,
1555
        but may also be used to reshape the array in-place by assigning a tuple
1556
        of array dimensions to it. Unlike :obj:`dpnp.reshape`, only non-negative
1557
        values are supported to be set as new shape. Reshaping an array in-place
1558
        will fail if a copy is required.
1559

1560
        For full documentation refer to :obj:`numpy.ndarray.shape`.
1561

1562
        Note
1563
        ----
1564
        Using :obj:`dpnp.ndarray.reshape` or :obj:`dpnp.reshape` is the
1565
        preferred approach to set new shape of an array.
1566

1567
        See Also
1568
        --------
1569
        :obj:`dpnp.shape` : Equivalent getter function.
1570
        :obj:`dpnp.reshape` : Function similar to setting `shape`.
1571
        :obj:`dpnp.ndarray.reshape` : Method similar to setting `shape`.
1572

1573
        Examples
1574
        --------
1575
        >>> import dpnp as np
1576
        >>> x = np.array([1, 2, 3, 4])
1577
        >>> x.shape
1578
        (4,)
1579
        >>> y = np.zeros((2, 3, 4))
1580
        >>> y.shape
1581
        (2, 3, 4)
1582

1583
        >>> y.shape = (3, 8)
1584
        >>> y
1585
        array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
1586
               [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
1587
               [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
1588
        >>> y.shape = (3, 6)
1589
        ...
1590
        TypeError: Can not reshape array of size 24 into (3, 6)
1591

1592
        """
1593

1594
        return self._array_obj.shape
1✔
1595

1596
    @shape.setter
1✔
1597
    def shape(self, newshape):
1✔
1598
        """
1599
        Set new lengths of axes.
1600

1601
        Modifies array instance in-place by changing its metadata about the
1602
        shape and the strides of the array, or raises `AttributeError`
1603
        exception if in-place change is not possible.
1604

1605
        Whether the array can be reshape in-place depends on its strides. Use
1606
        :obj:`dpnp.reshape` function which always succeeds to reshape the array
1607
        by performing a copy if necessary.
1608

1609
        For full documentation refer to :obj:`numpy.ndarray.shape`.
1610

1611
        Parameters
1612
        ----------
1613
        newshape : {tuple, int}
1614
            New shape. Only non-negative values are supported. The new shape
1615
            may not lead to the change in the number of elements in the array.
1616

1617
        """
1618

1619
        self._array_obj.shape = newshape
×
1620

1621
    @property
1✔
1622
    def size(self):
1✔
1623
        """
1624
        Number of elements in the array.
1625

1626
        Returns
1627
        -------
1628
        element_count : int
1629
            Number of elements in the array.
1630

1631
        See Also
1632
        --------
1633
        :obj:`dpnp.size` : Return the number of elements along a given axis.
1634
        :obj:`dpnp.shape` : Return the shape of an array.
1635
        :obj:`dpnp.ndarray.shape` : Return the shape of an array.
1636

1637
        Examples
1638
        --------
1639
        >>> import dpnp as np
1640
        >>> x = np.zeros((3, 5, 2), dtype=np.complex64)
1641
        >>> x.size
1642
        30
1643

1644
        """
1645

1646
        return self._array_obj.size
1✔
1647

1648
    def sort(
1✔
1649
        self, axis=-1, kind=None, order=None, *, descending=False, stable=None
1650
    ):
1651
        """
1652
        Sort an array in-place.
1653

1654
        Refer to :obj:`dpnp.sort` for full documentation.
1655

1656
        Parameters
1657
        ----------
1658
        axis : int, optional
1659
            Axis along which to sort. The default is ``-1``, which sorts along
1660
            the last axis.
1661
            Default: ``-1``.
1662
        kind : {None, "stable", "mergesort", "radixsort"}, optional
1663
            Sorting algorithm. The default is ``None``, which uses parallel
1664
            merge-sort or parallel radix-sort algorithms depending on the array
1665
            data type.
1666
            Default: ``None``.
1667
        descending : bool, optional
1668
            Sort order. If ``True``, the array must be sorted in descending
1669
            order (by value). If ``False``, the array must be sorted in
1670
            ascending order (by value).
1671
            Default: ``False``.
1672
        stable : {None, bool}, optional
1673
            Sort stability. If ``True``, the returned array will maintain the
1674
            relative order of `a` values which compare as equal. The same
1675
            behavior applies when set to ``False`` or ``None``.
1676
            Internally, this option selects ``kind="stable"``.
1677
            Default: ``None``.
1678

1679
        See Also
1680
        --------
1681
        :obj:`dpnp.sort` : Return a sorted copy of an array.
1682
        :obj:`dpnp.argsort` : Return the indices that would sort an array.
1683
        :obj:`dpnp.lexsort` : Indirect stable sort on multiple keys.
1684
        :obj:`dpnp.searchsorted` : Find elements in a sorted array.
1685
        :obj:`dpnp.partition` : Partial sort.
1686

1687
        Note
1688
        ----
1689
        `axis` in :obj:`dpnp.sort` could be integer or ``None``. If ``None``,
1690
        the array is flattened before sorting. However, `axis` in
1691
        :obj:`dpnp.ndarray.sort` can only be integer since it sorts an array
1692
        in-place.
1693

1694
        Examples
1695
        --------
1696
        >>> import dpnp as np
1697
        >>> a = np.array([[1, 4], [3, 1]])
1698
        >>> a.sort(axis=1)
1699
        >>> a
1700
        array([[1, 4],
1701
              [1, 3]])
1702
        >>> a.sort(axis=0)
1703
        >>> a
1704
        array([[1, 1],
1705
              [3, 4]])
1706

1707
        """
1708

1709
        if axis is None:
×
1710
            raise TypeError(
×
1711
                "'NoneType' object cannot be interpreted as an integer"
1712
            )
1713
        self[...] = dpnp.sort(
×
1714
            self,
1715
            axis=axis,
1716
            kind=kind,
1717
            order=order,
1718
            descending=descending,
1719
            stable=stable,
1720
        )
1721

1722
    def squeeze(self, axis=None):
1✔
1723
        """
1724
        Remove single-dimensional entries from the shape of an array.
1725

1726
        Refer to :obj:`dpnp.squeeze` for full documentation
1727

1728
        """
1729

1730
        return dpnp.squeeze(self, axis)
×
1731

1732
    def std(
1✔
1733
        self,
1734
        axis=None,
1735
        dtype=None,
1736
        out=None,
1737
        ddof=0,
1738
        keepdims=False,
1739
        *,
1740
        where=True,
1741
        mean=None,
1742
        correction=None,
1743
    ):
1744
        """
1745
        Returns the standard deviation of the array elements, along given axis.
1746

1747
        Refer to :obj:`dpnp.std` for full documentation.
1748

1749
        """
1750

1751
        return dpnp.std(
×
1752
            self,
1753
            axis,
1754
            dtype,
1755
            out,
1756
            ddof,
1757
            keepdims,
1758
            where=where,
1759
            mean=mean,
1760
            correction=correction,
1761
        )
1762

1763
    @property
1✔
1764
    def strides(self):
1✔
1765
        """
1766
        Returns memory displacement in array elements, upon unit
1767
        change of respective index.
1768

1769
        For example, for strides ``(s1, s2, s3)`` and multi-index
1770
        ``(i1, i2, i3)`` position of the respective element relative
1771
        to zero multi-index element is ``s1*s1 + s2*i2 + s3*i3``.
1772

1773
        """
1774

1775
        return self._array_obj.strides
1✔
1776

1777
    def sum(
1✔
1778
        self,
1779
        axis=None,
1780
        dtype=None,
1781
        out=None,
1782
        keepdims=False,
1783
        initial=None,
1784
        where=True,
1785
    ):
1786
        """
1787
        Returns the sum along a given axis.
1788

1789
        Refer to :obj:`dpnp.sum` for full documentation.
1790

1791
        """
1792

1793
        return dpnp.sum(
×
1794
            self,
1795
            axis=axis,
1796
            dtype=dtype,
1797
            out=out,
1798
            keepdims=keepdims,
1799
            initial=initial,
1800
            where=where,
1801
        )
1802

1803
    def swapaxes(self, axis1, axis2):
1✔
1804
        """
1805
        Interchange two axes of an array.
1806

1807
        Refer to :obj:`dpnp.swapaxes` for full documentation.
1808

1809
        """
1810

1811
        return dpnp.swapaxes(self, axis1=axis1, axis2=axis2)
×
1812

1813
    def take(self, indices, axis=None, out=None, mode="wrap"):
1✔
1814
        """
1815
        Take elements from an array along an axis.
1816

1817
        Refer to :obj:`dpnp.take` for full documentation.
1818

1819
        """
1820

1821
        return dpnp.take(self, indices, axis=axis, out=out, mode=mode)
×
1822

1823
    def to_device(self, device, /, *, stream=None):
1✔
1824
        """
1825
        Transfers this array to specified target device.
1826

1827
        Parameters
1828
        ----------
1829
        device : {None, string, SyclDevice, SyclQueue, Device}, optional
1830
            An array API concept of device where the output array is created.
1831
            `device` can be ``None``, a oneAPI filter selector string,
1832
            an instance of :class:`dpctl.SyclDevice` corresponding to
1833
            a non-partitioned SYCL device, an instance of
1834
            :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object
1835
            returned by :attr:`dpnp.ndarray.device`.
1836
        stream : {SyclQueue, None}, optional
1837
            Execution queue to synchronize with. If ``None``, synchronization
1838
            is not performed.
1839
            Default: ``None``.
1840

1841
        Returns
1842
        -------
1843
        out : dpnp.ndarray
1844
            A view if data copy is not required, and a copy otherwise.
1845
            If copying is required, it is done by copying from the original
1846
            allocation device to the host, followed by copying from host
1847
            to the target device.
1848

1849
        Examples
1850
        --------
1851
        >>> import dpnp as np, dpctl
1852
        >>> x = np.full(100, 2, dtype=np.int64)
1853
        >>> q_prof = dpctl.SyclQueue(x.sycl_device, property="enable_profiling")
1854
        >>> # return a view with profile-enabled queue
1855
        >>> y = x.to_device(q_prof)
1856
        >>> timer = dpctl.SyclTimer()
1857
        >>> with timer(q_prof):
1858
        ...     z = y * y
1859
        >>> print(timer.dt)
1860

1861
        """
1862

1863
        usm_res = self._array_obj.to_device(device, stream=stream)
×
1864
        return dpnp_array._create_from_usm_ndarray(usm_res)
×
1865

1866
    # 'tobytes',
1867
    # 'tofile',
1868
    # 'tolist',
1869

1870
    def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None):
1✔
1871
        """
1872
        Return the sum along diagonals of the array.
1873

1874
        Refer to :obj:`dpnp.trace` for full documentation.
1875

1876
        """
1877

1878
        return dpnp.trace(
×
1879
            self, offset=offset, axis1=axis1, axis2=axis2, dtype=dtype, out=out
1880
        )
1881

1882
    def transpose(self, *axes):
1✔
1883
        """
1884
        Returns a view of the array with axes transposed.
1885

1886
        For full documentation refer to :obj:`numpy.ndarray.transpose`.
1887

1888
        Parameters
1889
        ----------
1890
        axes : None, tuple or list of ints, n ints, optional
1891
            * ``None`` or no argument: reverses the order of the axes.
1892
            * ``tuple or list of ints``: `i` in the `j`-th place in the
1893
              tuple/list means that the array’s `i`-th axis becomes the
1894
              transposed array’s `j`-th axis.
1895
            * ``n ints``: same as an n-tuple/n-list of the same integers (this
1896
              form is intended simply as a “convenience” alternative to the
1897
              tuple form).
1898

1899
        Returns
1900
        -------
1901
        out : dpnp.ndarray
1902
            View of the array with its axes suitably permuted.
1903

1904
        See Also
1905
        --------
1906
        :obj:`dpnp.transpose` : Equivalent function.
1907
        :obj:`dpnp.ndarray.ndarray.T` : Array property returning the array transposed.
1908
        :obj:`dpnp.ndarray.reshape` : Give a new shape to an array without changing its data.
1909

1910
        Examples
1911
        --------
1912
        >>> import dpnp as np
1913
        >>> a = np.array([[1, 2], [3, 4]])
1914
        >>> a
1915
        array([[1, 2],
1916
               [3, 4]])
1917
        >>> a.transpose()
1918
        array([[1, 3],
1919
               [2, 4]])
1920
        >>> a.transpose((1, 0))
1921
        array([[1, 3],
1922
               [2, 4]])
1923

1924
        >>> a = np.array([1, 2, 3, 4])
1925
        >>> a
1926
        array([1, 2, 3, 4])
1927
        >>> a.transpose()
1928
        array([1, 2, 3, 4])
1929

1930
        """
1931

1932
        ndim = self.ndim
1✔
1933
        if ndim < 2:
1✔
1934
            return self
1✔
1935

1936
        axes_len = len(axes)
1✔
1937
        if axes_len == 1 and isinstance(axes[0], (tuple, list)):
1!
1938
            axes = axes[0]
×
1939

1940
        if ndim == 2 and axes_len == 0:
1!
1941
            usm_res = self._array_obj.T
×
1942
        else:
1943
            if len(axes) == 0 or axes[0] is None:
1!
1944
                # self.transpose().shape == self.shape[::-1]
1945
                # self.transpose(None).shape == self.shape[::-1]
1946
                axes = tuple((ndim - x - 1) for x in range(ndim))
×
1947

1948
            usm_res = dpt.permute_dims(self._array_obj, axes)
1✔
1949
        return dpnp_array._create_from_usm_ndarray(usm_res)
1✔
1950

1951
    def var(
1✔
1952
        self,
1953
        axis=None,
1954
        dtype=None,
1955
        out=None,
1956
        ddof=0,
1957
        keepdims=False,
1958
        *,
1959
        where=True,
1960
        mean=None,
1961
        correction=None,
1962
    ):
1963
        """
1964
        Returns the variance of the array elements, along given axis.
1965

1966
        Refer to :obj:`dpnp.var` for full documentation.
1967

1968
        """
1969

1970
        return dpnp.var(
×
1971
            self,
1972
            axis,
1973
            dtype,
1974
            out,
1975
            ddof,
1976
            keepdims,
1977
            where=where,
1978
            mean=mean,
1979
            correction=correction,
1980
        )
1981

1982

1983
# 'view'
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

© 2026 Coveralls, Inc