numpy 2.0.0
src/multiarray/convert.c File Reference
#include <Python.h>
#include "structmember.h"
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "npy_config.h"
#include "numpy/npy_3kcompat.h"
#include "arrayobject.h"
#include "mapping.h"
#include "lowlevel_strided_loops.h"
#include "convert.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API
#define _MULTIARRAYMODULE
#define NPY_NO_PREFIX

Functions

static PyObject * recursive_tolist (PyArrayObject *self, char *dataptr, int startdim)
NPY_NO_EXPORT PyObject * PyArray_ToList (PyArrayObject *self)
NPY_NO_EXPORT int PyArray_ToFile (PyArrayObject *self, FILE *fp, char *sep, char *format)
NPY_NO_EXPORT PyObject * PyArray_ToString (PyArrayObject *self, NPY_ORDER order)
NPY_NO_EXPORT int PyArray_FillWithScalar (PyArrayObject *arr, PyObject *obj)
NPY_NO_EXPORT int PyArray_FillWithZero (PyArrayObject *a)
NPY_NO_EXPORT PyObject * PyArray_NewCopy (PyArrayObject *m1, NPY_ORDER order)
NPY_NO_EXPORT PyObject * PyArray_View (PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)

Define Documentation

#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API
#define NPY_NO_PREFIX
#define PY_SSIZE_T_CLEAN

Function Documentation

NPY_NO_EXPORT int PyArray_FillWithScalar ( PyArrayObject arr,
PyObject *  obj 
)
NPY_NO_EXPORT int PyArray_FillWithZero ( PyArrayObject a)
Fills an array with zeros.
Returns 0 on success, -1 on failure.

A zero-sized array needs no zeroing
If it's possible to do a simple memset, do so
Use an iterator to go through all the data
Because buffering is disabled in the iterator, the inner loop strides will be the same throughout the iteration loop. Thus, we can pass them to this function to take advantage of contiguous strides, etc.
By setting the src_dtype to NULL, we get a function which sets the destination to zeros.

NPY_NO_EXPORT PyObject* PyArray_NewCopy ( PyArrayObject m1,
NPY_ORDER  order 
)
Copy an array.
NPY_NO_EXPORT int PyArray_ToFile ( PyArrayObject self,
FILE *  fp,
char *  sep,
char *  format 
)
XXX: FIXME --- add ordering argument to
Allow Fortran ordering on write This will need the addition of a Fortran-order iterator.
To File

binary data
text data
standard writing
use format string
write separator for all but last one

References PyArrayIterObject_tag::dataptr, PyArrayIterObject_tag::index, INTP_FMT, NPY_BEGIN_ALLOW_THREADS, NPY_BEGIN_THREADS, NPY_BEGIN_THREADS_DEF, NPY_END_ALLOW_THREADS, NPY_END_THREADS, NPY_LIST_PICKLE, PyArray_ISCONTIGUOUS, PyArray_ITER_NEXT, PyArray_IterNew(), PyArray_SIZE, PyDataType_FLAGCHK, and PyArrayIterObject_tag::size.

NPY_NO_EXPORT PyObject* PyArray_ToList ( PyArrayObject self)
To List
NPY_NO_EXPORT PyObject* PyArray_ToString ( PyArrayObject self,
NPY_ORDER  order 
)

if (PyArray_TYPE(self) == PyArray_OBJECT) {
PyErr_SetString(PyExc_ValueError, "a string for the data" "in an object array is not appropriate"); return NULL; }
iterators are always in C-order

Referenced by array_byteswap(), and array_reduce().

NPY_NO_EXPORT PyObject* PyArray_View ( PyArrayObject self,
PyArray_Descr type,
PyTypeObject *  pytype 
)
View
steals a reference to type -- accepts NULL
static PyObject* recursive_tolist ( PyArrayObject self,
char *  dataptr,
int  startdim 
) [static]
Converts a subarray of 'self' into lists, with starting data pointer 'dataptr' and from dimension 'startdim' to the last dimension of 'self'.
Returns a new reference.

Base case

References PyArray_DESCR, PyArray_DIM, PyArray_NDIM, and PyArray_STRIDE.