1
- # cython: language_level=3
2
- # distutils: language = c++
3
1
# -*- coding: utf-8 -*-
4
2
# *****************************************************************************
5
3
# Copyright (c) 2016-2023, Intel Corporation
@@ -581,7 +579,7 @@ def copy(a, order="K", subok=False):
581
579
return array (a , order = order , subok = subok , copy = True )
582
580
583
581
584
- def diag (x1 , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
582
+ def diag (v , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
585
583
"""
586
584
Extract a diagonal or construct a diagonal array.
587
585
@@ -594,9 +592,8 @@ def diag(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
594
592
595
593
Limitations
596
594
-----------
597
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
598
595
Parameter `k` is only supported as integer data type.
599
- Otherwise the function will be executed sequentially on CPU .
596
+ Otherwise ``TypeError`` exception will be raised .
600
597
601
598
See Also
602
599
--------
@@ -629,56 +626,44 @@ def diag(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
629
626
630
627
"""
631
628
632
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
633
- pass
634
- elif not isinstance (k , int ):
635
- pass
629
+ if not isinstance (k , int ):
630
+ raise TypeError ("An integer is required, but got {}" .format (type (k )))
636
631
else :
637
- _usm_type = x1 .usm_type if usm_type is None else usm_type
638
- _sycl_queue = dpnp .get_normalized_queue_device (
639
- x1 , sycl_queue = sycl_queue , device = device
640
- )
641
- x1 = (
642
- x1 .to_device (_sycl_queue .sycl_device )
643
- if x1 .sycl_queue != _sycl_queue
644
- else x1
632
+ v = dpnp .asarray (
633
+ v , device = device , usm_type = usm_type , sycl_queue = sycl_queue
645
634
)
646
635
647
636
init0 = max (0 , - k )
648
637
init1 = max (0 , k )
649
- if x1 .ndim == 1 :
650
- size = x1 .shape [0 ] + abs (k )
638
+ if v .ndim == 1 :
639
+ size = v .shape [0 ] + abs (k )
651
640
m = dpnp .zeros (
652
641
(size , size ),
653
- dtype = x1 .dtype ,
654
- usm_type = _usm_type ,
655
- sycl_queue = _sycl_queue ,
642
+ dtype = v .dtype ,
643
+ usm_type = v . usm_type ,
644
+ sycl_queue = v . sycl_queue ,
656
645
)
657
- for i in range (x1 .shape [0 ]):
658
- m [(init0 + i ), init1 + i ] = x1 [i ]
646
+ for i in range (v .shape [0 ]):
647
+ m [(init0 + i ), init1 + i ] = v [i ]
659
648
return m
660
- elif x1 .ndim == 2 :
661
- size = min (
662
- x1 .shape [0 ], x1 .shape [0 ] + k , x1 .shape [1 ], x1 .shape [1 ] - k
663
- )
649
+ elif v .ndim == 2 :
650
+ size = min (v .shape [0 ], v .shape [0 ] + k , v .shape [1 ], v .shape [1 ] - k )
664
651
if size < 0 :
665
652
size = 0
666
653
m = dpnp .zeros (
667
654
(size ,),
668
- dtype = x1 .dtype ,
669
- usm_type = _usm_type ,
670
- sycl_queue = _sycl_queue ,
655
+ dtype = v .dtype ,
656
+ usm_type = v . usm_type ,
657
+ sycl_queue = v . sycl_queue ,
671
658
)
672
659
for i in range (size ):
673
- m [i ] = x1 [(init0 + i ), init1 + i ]
660
+ m [i ] = v [(init0 + i ), init1 + i ]
674
661
return m
675
662
else :
676
663
raise ValueError ("Input must be a 1-D or 2-D array." )
677
664
678
- return call_origin (numpy .diag , x1 , k )
679
665
680
-
681
- def diagflat (x1 , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
666
+ def diagflat (v , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
682
667
"""
683
668
Create a two-dimensional array with the flattened input as a diagonal.
684
669
@@ -697,9 +682,8 @@ def diagflat(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
697
682
698
683
Limitations
699
684
-----------
700
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
701
685
Parameter `k` is only supported as integer data type.
702
- Otherwise the function will be executed sequentially on CPU .
686
+ Otherwise ``TypeError`` exception will be raised .
703
687
704
688
Examples
705
689
--------
@@ -719,19 +703,15 @@ def diagflat(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
719
703
[0, 0, 0, 0, 0]])
720
704
721
705
"""
722
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
723
- pass
724
- elif not isinstance (k , int ):
725
- pass
706
+
707
+ if not isinstance (k , int ):
708
+ raise TypeError ("An integer is required, but got {}" .format (type (k )))
726
709
else :
727
- _usm_type = x1 .usm_type if usm_type is None else usm_type
728
- _sycl_queue = dpnp .get_normalized_queue_device (
729
- x1 , sycl_queue = sycl_queue , device = device
710
+ v = dpnp .asarray (
711
+ v , device = device , usm_type = usm_type , sycl_queue = sycl_queue
730
712
)
731
- v = dpnp .ravel (x1 )
732
- return dpnp .diag (v , k , usm_type = _usm_type , sycl_queue = _sycl_queue )
733
-
734
- return call_origin (numpy .diagflat , x1 , k )
713
+ v = dpnp .ravel (v )
714
+ return dpnp .diag (v , k , usm_type = v .usm_type , sycl_queue = v .sycl_queue )
735
715
736
716
737
717
def empty (
@@ -1030,6 +1010,7 @@ def full(
1030
1010
[10, 10, 10, 10]
1031
1011
1032
1012
"""
1013
+
1033
1014
if like is not None :
1034
1015
pass
1035
1016
elif order not in ("C" , "c" , "F" , "f" , None ):
@@ -1871,8 +1852,8 @@ def vander(
1871
1852
1872
1853
Limitations
1873
1854
-----------
1874
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` .
1875
- Otherwise the function will be executed sequentially on CPU .
1855
+ Parameter `N`, if it is not ``None``, is only supported as integer data type .
1856
+ Otherwise ``TypeError`` exception will be raised .
1876
1857
1877
1858
Examples
1878
1859
--------
@@ -1899,44 +1880,34 @@ def vander(
1899
1880
[ 1, 5, 25, 125]])
1900
1881
"""
1901
1882
1902
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
1903
- pass
1904
- elif N is not None and not isinstance (N , int ):
1905
- pass
1883
+ x1 = dpnp .asarray (
1884
+ x1 , device = device , usm_type = usm_type , sycl_queue = sycl_queue
1885
+ )
1886
+
1887
+ if N is not None and not isinstance (N , int ):
1888
+ raise TypeError ("An integer is required, but got {}" .format (type (N )))
1906
1889
elif x1 .ndim != 1 :
1907
1890
raise ValueError ("x1 must be a one-dimensional array or sequence." )
1908
1891
else :
1909
1892
if N is None :
1910
1893
N = x1 .size
1911
1894
1912
1895
_dtype = int if x1 .dtype == bool else x1 .dtype
1913
- _usm_type = x1 .usm_type if usm_type is None else usm_type
1914
- _sycl_queue = dpnp .get_normalized_queue_device (
1915
- x1 , sycl_queue = sycl_queue , device = device
1916
- )
1917
- x1 = (
1918
- x1 .to_device (_sycl_queue .sycl_device )
1919
- if x1 .sycl_queue != _sycl_queue
1920
- else x1
1921
- )
1922
-
1923
1896
m = empty (
1924
1897
(x1 .size , N ),
1925
1898
dtype = _dtype ,
1926
- usm_type = _usm_type ,
1927
- sycl_queue = _sycl_queue ,
1899
+ usm_type = x1 . usm_type ,
1900
+ sycl_queue = x1 . sycl_queue ,
1928
1901
)
1929
1902
tmp = m [:, ::- 1 ] if not increasing else m
1930
1903
dpnp .power (
1931
1904
x1 .reshape (- 1 , 1 ),
1932
- dpnp .arange (N , dtype = _dtype , sycl_queue = _sycl_queue ),
1905
+ dpnp .arange (N , dtype = _dtype , sycl_queue = x1 . sycl_queue ),
1933
1906
out = tmp ,
1934
1907
)
1935
1908
1936
1909
return m
1937
1910
1938
- return call_origin (numpy .vander , x1 , N = N , increasing = increasing )
1939
-
1940
1911
1941
1912
def zeros (
1942
1913
shape ,
0 commit comments