@@ -1980,8 +1980,66 @@ def var(
19801980 correction = correction ,
19811981 )
19821982
1983- def view (self , dtype = None ):
1984- """TBD"""
1983+ def view (self , dtype = None , * , type = None ):
1984+ """
1985+ New view of array with the same data.
1986+
1987+ For full documentation refer to :obj:`numpy.ndarray.view`.
1988+
1989+ Parameters
1990+ ----------
1991+ dtype : {None, str, dtype object}, optional
1992+ The desired data type of the returned view, e.g. :obj:`dpnp.float32`
1993+ or :obj:`dpnp.int16`. Omitting it results in the view having the
1994+ same data type.
1995+
1996+ Notes
1997+ -----
1998+ Passing ``None`` for `dtype` is different from omitting the parameter,
1999+ since the former invokes ``dtype(None)`` which is an alias for the
2000+ default floating point data type.
2001+
2002+ ``view(some_dtype)`` or ``view(dtype=some_dtype)`` constructs a view of
2003+ the array's memory with a different data type. This can cause a
2004+ reinterpretation of the bytes of memory.
2005+
2006+ Only the last axis has to be contiguous.
2007+
2008+ Limitations
2009+ -----------
2010+ Parameter `type` is supported only with default value ``None``.
2011+ Otherwise, the function raises ``NotImplementedError`` exception.
2012+
2013+ Examples
2014+ --------
2015+ >>> import dpnp as np
2016+ >>> x = np.ones((4,), dtype=np.float32)
2017+ >>> xv = x.view(dtype=np.int32)
2018+ >>> xv[:] = 0
2019+ >>> xv
2020+ array([0, 0, 0, 0], dtype=int32)
2021+
2022+ However, views that change dtype are totally fine for arrays with a
2023+ contiguous last axis, even if the rest of the axes are not C-contiguous:
2024+
2025+ >>> x = np.arange(2 * 3 * 4, dtype=np.int8).reshape(2, 3, 4)
2026+ >>> x.transpose(1, 0, 2).view(np.int16)
2027+ array([[[ 256, 770],
2028+ [3340, 3854]],
2029+ <BLANKLINE>
2030+ [[1284, 1798],
2031+ [4368, 4882]],
2032+ <BLANKLINE>
2033+ [[2312, 2826],
2034+ [5396, 5910]]], dtype=int16)
2035+
2036+ """
2037+
2038+ if type is not None :
2039+ raise NotImplementedError (
2040+ "Keyword argument `type` is supported only with "
2041+ f"default value ``None``, but got { type } ."
2042+ )
19852043
19862044 old_sh = self .shape
19872045 old_strides = self .strides
0 commit comments