MCPcopy Create free account
hub / github.com/numpy/numpy / array_view

Function array_view

numpy/core/src/multiarray/methods.c:237–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237static PyObject *
238array_view(PyArrayObject *self,
239 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
240{
241 PyObject *out_dtype = NULL;
242 PyObject *out_type = NULL;
243 PyArray_Descr *dtype = NULL;
244 NPY_PREPARE_ARGPARSER;
245
246 if (npy_parse_arguments("view", args, len_args, kwnames,
247 "|dtype", NULL, &out_dtype,
248 "|type", NULL, &out_type,
249 NULL, NULL, NULL) < 0) {
250 return NULL;
251 }
252
253 /* If user specified a positional argument, guess whether it
254 represents a type or a dtype for backward compatibility. */
255 if (out_dtype) {
256 /* type specified? */
257 if (PyType_Check(out_dtype) &&
258 PyType_IsSubtype((PyTypeObject *)out_dtype,
259 &PyArray_Type)) {
260 if (out_type) {
261 PyErr_SetString(PyExc_ValueError,
262 "Cannot specify output type twice.");
263 return NULL;
264 }
265 out_type = out_dtype;
266 out_dtype = NULL;
267 }
268 }
269
270 if ((out_type) && (!PyType_Check(out_type) ||
271 !PyType_IsSubtype((PyTypeObject *)out_type,
272 &PyArray_Type))) {
273 PyErr_SetString(PyExc_ValueError,
274 "Type must be a sub-type of ndarray type");
275 return NULL;
276 }
277
278 if ((out_dtype) &&
279 (PyArray_DescrConverter(out_dtype, &dtype) == NPY_FAIL)) {
280 return NULL;
281 }
282
283 return PyArray_View(self, dtype, (PyTypeObject*)out_type);
284}
285
286static PyObject *
287array_argmax(PyArrayObject *self,

Callers

nothing calls this directly

Calls 2

PyArray_DescrConverterFunction · 0.85
PyArray_ViewFunction · 0.85

Tested by

no test coverage detected