@@ -1945,8 +1945,7 @@ def repeat(a, repeats, axis=None):
1945
1945
1946
1946
def require (a , dtype = None , requirements = None , * , like = None ):
1947
1947
"""
1948
- Return a :class:`dpnp.ndarray` of the provided type that satisfies
1949
- requirements.
1948
+ Return an dpnp.ndarray of the provided type that satisfies requirements.
1950
1949
1951
1950
This function is useful to be sure that an array with the correct flags
1952
1951
is returned for passing to compiled code (perhaps through ctypes).
@@ -1957,9 +1956,11 @@ def require(a, dtype=None, requirements=None, *, like=None):
1957
1956
----------
1958
1957
a : array_like
1959
1958
The object to be converted to a type-and-requirement-satisfying array.
1960
- dtype : {None, data-type}, optional
1961
- The required data-type. If ``None`` preserve the current dtype.
1962
- requirements : {None, str, sequence of str}, optional
1959
+ dtype : data-type, optional
1960
+ The required data-type. If None preserve the current dtype. If your
1961
+ application requires the data to be in native byteorder, include
1962
+ a byteorder specification as a part of the dtype specification.
1963
+ requirements : {str, sequence of str}, , optional
1963
1964
The requirements list can be any of the following:
1964
1965
1965
1966
* 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
@@ -1979,7 +1980,7 @@ def require(a, dtype=None, requirements=None, *, like=None):
1979
1980
See Also
1980
1981
--------
1981
1982
:obj:`dpnp.asarray` : Convert input to an ndarray.
1982
- :obj:`dpnp.asanyarray` : Convert to an ndarray, but pass through
1983
+ :obj:`dpnp.asanyarray ` : Convert to an ndarray, but pass through
1983
1984
ndarray subclasses.
1984
1985
:obj:`dpnp.ascontiguousarray` : Convert input to a contiguous array.
1985
1986
:obj:`dpnp.asfortranarray` : Convert input to an ndarray with
@@ -1995,7 +1996,7 @@ def require(a, dtype=None, requirements=None, *, like=None):
1995
1996
Examples
1996
1997
--------
1997
1998
>>> import dpnp as np
1998
- >>> x = np.arange(6).reshape(2, 3)
1999
+ >>> x = np.arange(6).reshape(2,3)
1999
2000
>>> x.flags
2000
2001
C_CONTIGUOUS : True
2001
2002
F_CONTIGUOUS : False
@@ -2023,7 +2024,14 @@ def require(a, dtype=None, requirements=None, *, like=None):
2023
2024
if not requirements :
2024
2025
return dpnp .asanyarray (a , dtype = dtype )
2025
2026
2026
- requirements = {possible_flags [x .upper ()] for x in requirements }
2027
+ try :
2028
+ requirements = {possible_flags [x .upper ()] for x in requirements }
2029
+ except KeyError as exc :
2030
+ incorrect_flag = (set (requirements ) - set (possible_flags .keys ())).pop ()
2031
+ raise ValueError (
2032
+ f"Incorrect flag { incorrect_flag } in requirements"
2033
+ ) from exc
2034
+
2027
2035
order = "A"
2028
2036
if requirements .issuperset ({"C" , "F" }):
2029
2037
raise ValueError ("Cannot specify both 'C' and 'F' order" )
0 commit comments