1
- # cython: language_level=3
2
- # distutils: language = c++
3
1
# -*- coding: utf-8 -*-
4
2
# *****************************************************************************
5
3
# Copyright (c) 2016-2023, Intel Corporation
@@ -575,7 +573,7 @@ def copy(a, order="K", subok=False):
575
573
return array (a , order = order , subok = subok , copy = True )
576
574
577
575
578
- def diag (x1 , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
576
+ def diag (v , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
579
577
"""
580
578
Extract a diagonal or construct a diagonal array.
581
579
@@ -588,9 +586,8 @@ def diag(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
588
586
589
587
Limitations
590
588
-----------
591
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
592
589
Parameter `k` is only supported as integer data type.
593
- Otherwise the function will be executed sequentially on CPU .
590
+ Otherwise ``TypeError`` exception will be raised .
594
591
595
592
See Also
596
593
--------
@@ -623,56 +620,44 @@ def diag(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
623
620
624
621
"""
625
622
626
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
627
- pass
628
- elif not isinstance (k , int ):
629
- pass
623
+ if not isinstance (k , int ):
624
+ raise TypeError ("An integer is required, but got {}" .format (type (k )))
630
625
else :
631
- _usm_type = x1 .usm_type if usm_type is None else usm_type
632
- _sycl_queue = dpnp .get_normalized_queue_device (
633
- x1 , sycl_queue = sycl_queue , device = device
634
- )
635
- x1 = (
636
- x1 .to_device (_sycl_queue .sycl_device )
637
- if x1 .sycl_queue != _sycl_queue
638
- else x1
626
+ v = dpnp .asarray (
627
+ v , device = device , usm_type = usm_type , sycl_queue = sycl_queue
639
628
)
640
629
641
630
init0 = max (0 , - k )
642
631
init1 = max (0 , k )
643
- if x1 .ndim == 1 :
644
- size = x1 .shape [0 ] + abs (k )
632
+ if v .ndim == 1 :
633
+ size = v .shape [0 ] + abs (k )
645
634
m = dpnp .zeros (
646
635
(size , size ),
647
- dtype = x1 .dtype ,
648
- usm_type = _usm_type ,
649
- sycl_queue = _sycl_queue ,
636
+ dtype = v .dtype ,
637
+ usm_type = v . usm_type ,
638
+ sycl_queue = v . sycl_queue ,
650
639
)
651
- for i in range (x1 .shape [0 ]):
652
- m [(init0 + i ), init1 + i ] = x1 [i ]
640
+ for i in range (v .shape [0 ]):
641
+ m [(init0 + i ), init1 + i ] = v [i ]
653
642
return m
654
- elif x1 .ndim == 2 :
655
- size = min (
656
- x1 .shape [0 ], x1 .shape [0 ] + k , x1 .shape [1 ], x1 .shape [1 ] - k
657
- )
643
+ elif v .ndim == 2 :
644
+ size = min (v .shape [0 ], v .shape [0 ] + k , v .shape [1 ], v .shape [1 ] - k )
658
645
if size < 0 :
659
646
size = 0
660
647
m = dpnp .zeros (
661
648
(size ,),
662
- dtype = x1 .dtype ,
663
- usm_type = _usm_type ,
664
- sycl_queue = _sycl_queue ,
649
+ dtype = v .dtype ,
650
+ usm_type = v . usm_type ,
651
+ sycl_queue = v . sycl_queue ,
665
652
)
666
653
for i in range (size ):
667
- m [i ] = x1 [(init0 + i ), init1 + i ]
654
+ m [i ] = v [(init0 + i ), init1 + i ]
668
655
return m
669
656
else :
670
657
raise ValueError ("Input must be a 1-D or 2-D array." )
671
658
672
- return call_origin (numpy .diag , x1 , k )
673
659
674
-
675
- def diagflat (x1 , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
660
+ def diagflat (v , / , k = 0 , * , device = None , usm_type = None , sycl_queue = None ):
676
661
"""
677
662
Create a two-dimensional array with the flattened input as a diagonal.
678
663
@@ -691,9 +676,8 @@ def diagflat(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
691
676
692
677
Limitations
693
678
-----------
694
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
695
679
Parameter `k` is only supported as integer data type.
696
- Otherwise the function will be executed sequentially on CPU .
680
+ Otherwise ``TypeError`` exception will be raised .
697
681
698
682
Examples
699
683
--------
@@ -713,19 +697,15 @@ def diagflat(x1, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
713
697
[0, 0, 0, 0, 0]])
714
698
715
699
"""
716
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
717
- pass
718
- elif not isinstance (k , int ):
719
- pass
700
+
701
+ if not isinstance (k , int ):
702
+ raise TypeError ("An integer is required, but got {}" .format (type (k )))
720
703
else :
721
- _usm_type = x1 .usm_type if usm_type is None else usm_type
722
- _sycl_queue = dpnp .get_normalized_queue_device (
723
- x1 , sycl_queue = sycl_queue , device = device
704
+ v = dpnp .asarray (
705
+ v , device = device , usm_type = usm_type , sycl_queue = sycl_queue
724
706
)
725
- v = dpnp .ravel (x1 )
726
- return dpnp .diag (v , k , usm_type = _usm_type , sycl_queue = _sycl_queue )
727
-
728
- return call_origin (numpy .diagflat , x1 , k )
707
+ v = dpnp .ravel (v )
708
+ return dpnp .diag (v , k , usm_type = v .usm_type , sycl_queue = v .sycl_queue )
729
709
730
710
731
711
def empty (
@@ -1024,6 +1004,7 @@ def full(
1024
1004
[10, 10, 10, 10]
1025
1005
1026
1006
"""
1007
+
1027
1008
if like is not None :
1028
1009
pass
1029
1010
elif order not in ("C" , "c" , "F" , "f" , None ):
@@ -1824,8 +1805,8 @@ def vander(
1824
1805
1825
1806
Limitations
1826
1807
-----------
1827
- Parameter `x1` is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray` .
1828
- Otherwise the function will be executed sequentially on CPU .
1808
+ Parameter `N`, if it is not ``None``, is only supported as integer data type .
1809
+ Otherwise ``TypeError`` exception will be raised .
1829
1810
1830
1811
Examples
1831
1812
--------
@@ -1852,44 +1833,34 @@ def vander(
1852
1833
[ 1, 5, 25, 125]])
1853
1834
"""
1854
1835
1855
- if not isinstance (x1 , (dpnp .ndarray , dpt .usm_ndarray )):
1856
- pass
1857
- elif N is not None and not isinstance (N , int ):
1858
- pass
1836
+ x1 = dpnp .asarray (
1837
+ x1 , device = device , usm_type = usm_type , sycl_queue = sycl_queue
1838
+ )
1839
+
1840
+ if N is not None and not isinstance (N , int ):
1841
+ raise TypeError ("An integer is required, but got {}" .format (type (N )))
1859
1842
elif x1 .ndim != 1 :
1860
1843
raise ValueError ("x1 must be a one-dimensional array or sequence." )
1861
1844
else :
1862
1845
if N is None :
1863
1846
N = x1 .size
1864
1847
1865
1848
_dtype = int if x1 .dtype == bool else x1 .dtype
1866
- _usm_type = x1 .usm_type if usm_type is None else usm_type
1867
- _sycl_queue = dpnp .get_normalized_queue_device (
1868
- x1 , sycl_queue = sycl_queue , device = device
1869
- )
1870
- x1 = (
1871
- x1 .to_device (_sycl_queue .sycl_device )
1872
- if x1 .sycl_queue != _sycl_queue
1873
- else x1
1874
- )
1875
-
1876
1849
m = empty (
1877
1850
(x1 .size , N ),
1878
1851
dtype = _dtype ,
1879
- usm_type = _usm_type ,
1880
- sycl_queue = _sycl_queue ,
1852
+ usm_type = x1 . usm_type ,
1853
+ sycl_queue = x1 . sycl_queue ,
1881
1854
)
1882
1855
tmp = m [:, ::- 1 ] if not increasing else m
1883
1856
dpnp .power (
1884
1857
x1 .reshape (- 1 , 1 ),
1885
- dpnp .arange (N , dtype = _dtype , sycl_queue = _sycl_queue ),
1858
+ dpnp .arange (N , dtype = _dtype , sycl_queue = x1 . sycl_queue ),
1886
1859
out = tmp ,
1887
1860
)
1888
1861
1889
1862
return m
1890
1863
1891
- return call_origin (numpy .vander , x1 , N = N , increasing = increasing )
1892
-
1893
1864
1894
1865
def zeros (
1895
1866
shape ,
0 commit comments