Skip to content

Commit 8a12e41

Browse files
Merge branch 'master' into gold/2021
2 parents 897bddd + a44926b commit 8a12e41

File tree

5 files changed

+212
-341
lines changed

5 files changed

+212
-341
lines changed

dpnp/dpnp_array.py

Lines changed: 161 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,15 @@ def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True):
373373

374374
# 'base',
375375
# 'byteswap',
376-
# 'choose',
376+
377+
def choose(input, choices, out=None, mode='raise'):
378+
"""
379+
Construct an array from an index array and a set of arrays to choose from.
380+
381+
"""
382+
383+
return dpnp.choose(input, choices, out, mode)
384+
377385
# 'clip',
378386
# 'compress',
379387

@@ -408,7 +416,19 @@ def conjugate(self):
408416
# 'cumprod',
409417
# 'cumsum',
410418
# 'data',
411-
# 'diagonal',
419+
420+
def diagonal(input, offset=0, axis1=0, axis2=1):
421+
"""
422+
Return specified diagonals.
423+
424+
See Also
425+
--------
426+
:obj:`dpnp.diagonal`
427+
428+
"""
429+
430+
return dpnp.diagonal(input, offset, axis1, axis2)
431+
412432
# 'dot',
413433

414434
@property
@@ -420,7 +440,32 @@ def dtype(self):
420440

421441
# 'dump',
422442
# 'dumps',
423-
# 'fill',
443+
444+
def fill(self, value):
445+
"""
446+
Fill the array with a scalar value.
447+
448+
Parameters
449+
----------
450+
value : scalar
451+
All elements of `a` will be assigned this value.
452+
453+
Examples
454+
--------
455+
>>> a = np.array([1, 2])
456+
>>> a.fill(0)
457+
>>> a
458+
array([0, 0])
459+
>>> a = np.empty(2)
460+
>>> a.fill(1)
461+
>>> a
462+
array([1., 1.])
463+
464+
"""
465+
466+
for i in range(self.size):
467+
self.flat[i] = value
468+
424469
# 'flags',
425470

426471
@property
@@ -465,7 +510,40 @@ def flatten(self, order='C'):
465510

466511
# 'getfield',
467512
# 'imag',
468-
# 'item',
513+
514+
def item(self, id=None):
515+
"""
516+
Copy an element of an array to a standard Python scalar and return it.
517+
518+
For full documentation refer to :obj:`numpy.ndarray.item`.
519+
520+
Examples
521+
--------
522+
>>> np.random.seed(123)
523+
>>> x = np.random.randint(9, size=(3, 3))
524+
>>> x
525+
array([[2, 2, 6],
526+
[1, 3, 6],
527+
[1, 0, 1]])
528+
>>> x.item(3)
529+
1
530+
>>> x.item(7)
531+
0
532+
>>> x.item((0, 1))
533+
2
534+
>>> x.item((2, 2))
535+
1
536+
537+
"""
538+
539+
if id is None:
540+
if self.size != 1:
541+
raise ValueError("DPNP dparray::item(): can only convert an array of size 1 to a Python scalar")
542+
else:
543+
id = 0
544+
545+
return self.flat[id]
546+
469547
# 'itemset',
470548

471549
@property
@@ -514,9 +592,50 @@ def ndim(self):
514592
# 'ravel',
515593
# 'real',
516594
# 'repeat',
517-
# 'reshape',
595+
596+
def reshape(self, d0, *dn, order=b'C'):
597+
"""
598+
Returns an array containing the same data with a new shape.
599+
600+
Refer to `dpnp.reshape` for full documentation.
601+
602+
.. seealso::
603+
:meth:`numpy.ndarray.reshape`
604+
605+
Notes
606+
-----
607+
Unlike the free function `dpnp.reshape`, this method on `ndarray` allows
608+
the elements of the shape parameter to be passed in as separate arguments.
609+
For example, ``a.reshape(10, 11)`` is equivalent to
610+
``a.reshape((10, 11))``.
611+
612+
"""
613+
614+
if dn:
615+
if not isinstance(d0, int):
616+
msg_tmpl = "'{}' object cannot be interpreted as an integer"
617+
raise TypeError(msg_tmpl.format(type(d0).__name__))
618+
shape = [d0, *dn]
619+
else:
620+
shape = d0
621+
622+
shape_tup = dpnp.dpnp_utils._object_to_tuple(shape)
623+
624+
return dpnp.reshape(self, shape_tup)
625+
518626
# 'resize',
519-
# 'round',
627+
628+
def round(self, decimals=0, out=None):
629+
"""
630+
Return array with each element rounded to the given number of decimals.
631+
632+
.. seealso::
633+
:obj:`dpnp.around` for full documentation.
634+
635+
"""
636+
637+
return dpnp.around(self, decimals, out)
638+
520639
# 'searchsorted',
521640
# 'setfield',
522641
# 'setflags',
@@ -561,7 +680,17 @@ def size(self):
561680
return self._array_obj.size
562681

563682
# 'sort',
564-
# 'squeeze',
683+
684+
def squeeze(self, axis=None):
685+
"""
686+
Remove single-dimensional entries from the shape of an array.
687+
688+
.. seealso::
689+
:obj:`dpnp.squeeze` for full documentation
690+
691+
"""
692+
693+
return dpnp.squeeze(self, axis)
565694

566695
def std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
567696
""" Returns the variance of the array elements, along given axis.
@@ -580,15 +709,37 @@ def strides(self):
580709

581710
return self._array_obj.strides
582711

583-
# 'sum',
712+
def sum(self, axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True):
713+
"""
714+
Returns the sum along a given axis.
715+
716+
.. seealso::
717+
:obj:`dpnp.sum` for full documentation,
718+
:meth:`dpnp.dparray.sum`
719+
720+
"""
721+
722+
return dpnp.sum(self, axis, dtype, out, keepdims, initial, where)
723+
584724
# 'swapaxes',
585725
# 'take',
586726
# 'tobytes',
587727
# 'tofile',
588728
# 'tolist',
589729
# 'tostring',
590730
# 'trace',
591-
# 'transpose',
731+
732+
def transpose(self, *axes):
733+
"""
734+
Returns a view of the array with axes permuted.
735+
736+
.. seealso::
737+
:obj:`dpnp.transpose` for full documentation,
738+
:meth:`numpy.ndarray.reshape`
739+
740+
"""
741+
742+
return dpnp.transpose(self, axes)
743+
592744
# 'var',
593745
# 'view'
594-

scripts/azure-pipelines.yml

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -53,60 +53,60 @@ jobs:
5353
vmImage: 'ubuntu-20.04'
5454
steps:
5555
- bash: |
56-
echo ========================= Conda ENV =================================
56+
echo ============================================ Conda ENV =============================================
5757
conda create -q -y -n CondaCodeCov python=3.8 conda-build conda-verify \
58-
numpy=1.20.1 cython pytest \
59-
pycodestyle autopep8 \
60-
cython pytest pytest-cov
58+
numpy cython pytest pytest-cov pycodestyle autopep8 \
59+
dpctl mkl-devel-dpcpp tbb-devel dpcpp_linux-64 cmake=3.19 \
60+
-c dppy/label/dev -c intel -c conda-forge
6161
. /usr/share/miniconda/etc/profile.d/conda.sh
6262
conda activate CondaCodeCov
63-
echo ========================= CI ENV ====================================
64-
. ./scripts/set_ci_env.sh
65-
echo ========================= build DPNP ================================
66-
./0.build.sh
67-
echo ========================= run code coverage =========================
63+
echo ============================================ build DPNP ============================================
64+
python setup.py build_clib
65+
CC=dpcpp python setup.py build_ext --inplace
66+
echo ============================================ run code coverage =====================================
67+
export OCL_ICD_FILENAMES=libintelocl.so
6868
pytest --cov-report xml:coverage.xml --cov-report term-missing --cov=dpnp
6969
export CODECOV_TOKEN="1158b545-b00a-4a84-a6f9-2bc2c4265d8b"
7070
bash <(curl -s https://codecov.io/bash) -f coverage.xml
7171
72-
- job: ubuntu2004
73-
displayName: Ubuntu 20.04
74-
pool:
75-
vmImage: 'ubuntu-20.04'
76-
strategy:
77-
matrix:
78-
Python37:
79-
python.version: '3.7'
80-
Python38:
81-
python.version: '3.8'
82-
Python39:
83-
python.version: '3.9'
84-
steps:
85-
- task: UsePythonVersion@0
86-
inputs:
87-
versionSpec: '$(python.version)'
88-
displayName: 'Use Python $(python.version)'
89-
- bash: |
90-
#echo ========================= Conda ENV ===========================
91-
#conda config --env --add channels conda-forge
92-
#echo ========================= update Conda ENV ===========================
93-
#conda update -y --prefix /usr/share/miniconda anaconda
94-
#echo ========================= 1 update Conda ENV ===========================
95-
#conda update -y libgcc-ng=9.3 libstdcxx-ng=9.3
96-
echo ========================= create Conda ENV ===========================
97-
conda create -q -y -n dpnp$(python.version) python=$(python.version) libgcc-ng=9.3 libstdcxx-ng=9.3
98-
. /usr/share/miniconda/etc/profile.d/conda.sh
99-
conda activate dpnp$(python.version)
100-
101-
echo ========================= install OneAPI =================================
102-
# . ./scripts/install_cmake_lin.sh
103-
./scripts/install_system_deps.sh # no intel python
104-
./scripts/install_python_deps.sh # numpy, conda-build and etc.
105-
echo ========================= build DPNP ==========================
106-
./0.build.sh
107-
echo ========================= run tests ======================================
108-
. ./0.env.sh
109-
pytest -s
72+
#- job: ubuntu2004
73+
# displayName: Ubuntu 20.04
74+
# pool:
75+
# vmImage: 'ubuntu-20.04'
76+
# strategy:
77+
# matrix:
78+
# Python37:
79+
# python.version: '3.7'
80+
# Python38:
81+
# python.version: '3.8'
82+
# Python39:
83+
# python.version: '3.9'
84+
# steps:
85+
# - task: UsePythonVersion@0
86+
# inputs:
87+
# versionSpec: '$(python.version)'
88+
# displayName: 'Use Python $(python.version)'
89+
# - bash: |
90+
# #echo ========================= Conda ENV ===========================
91+
# #conda config --env --add channels conda-forge
92+
# #echo ========================= update Conda ENV ===========================
93+
# #conda update -y --prefix /usr/share/miniconda anaconda
94+
# #echo ========================= 1 update Conda ENV ===========================
95+
# #conda update -y libgcc-ng=9.3 libstdcxx-ng=9.3
96+
# echo ========================= create Conda ENV ===========================
97+
# conda create -q -y -n dpnp$(python.version) python=$(python.version) libgcc-ng=9.3 libstdcxx-ng=9.3
98+
# . /usr/share/miniconda/etc/profile.d/conda.sh
99+
# conda activate dpnp$(python.version)
100+
#
101+
# echo ========================= install OneAPI =================================
102+
# # . ./scripts/install_cmake_lin.sh
103+
# ./scripts/install_system_deps.sh # no intel python
104+
# ./scripts/install_python_deps.sh # numpy, conda-build and etc.
105+
# echo ========================= build DPNP ==========================
106+
# ./0.build.sh
107+
# echo ========================= run tests ======================================
108+
# . ./0.env.sh
109+
# pytest -s
110110

111111
- job: conda_build_ubuntu2004
112112
displayName: conda-build Ubuntu 20.04

0 commit comments

Comments
 (0)