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 "npy_pycompat.h"
#include "arrayobject.h"
#include "mapping.h"
#include "lowlevel_strided_loops.h"
#include "scalartypes.h"
#include "array_assign.h"
#include "convert.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

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_AssignZero (PyArrayObject *dst, PyArrayObject *wheremask)
NPY_NO_EXPORT int PyArray_AssignOne (PyArrayObject *dst, PyArrayObject *wheremask)
NPY_NO_EXPORT PyObject * PyArray_NewCopy (PyArrayObject *obj, NPY_ORDER order)
NPY_NO_EXPORT PyObject * PyArray_View (PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype)

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

NPY_NO_EXPORT int PyArray_AssignOne ( PyArrayObject dst,
PyArrayObject wheremask 
)
Fills an array with ones.
dst: The destination array. wheremask: If non-NULL, a boolean mask specifying where to set the values.
Returns 0 on success, -1 on failure.
Create a raw bool scalar with the value True

References Py_TYPE.

NPY_NO_EXPORT int PyArray_AssignZero ( PyArrayObject dst,
PyArrayObject wheremask 
)
Fills an array with zeros.
dst: The destination array. wheremask: If non-NULL, a boolean mask specifying where to set the values.
Returns 0 on success, -1 on failure.
Create a raw bool scalar with the value False

References NPY_UNSAFE_CASTING, PyArray_AssignArray(), and PyArray_NewLikeArray().

NPY_NO_EXPORT int PyArray_FillWithScalar ( PyArrayObject arr,
PyObject *  obj 
)
If 'arr' is an object array, copy the object as is unless 'obj' is a zero-dimensional array, in which case we copy the element in that array instead.
NumPy scalar
Python boolean
Python integer
Python float
Python complex
Use the value pointer we got if possible
TODO: switch to SAME_KIND casting
Otherwise convert to an array to do the assignment
NPY_NO_EXPORT PyObject* PyArray_NewCopy ( PyArrayObject obj,
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, NPY_BEGIN_ALLOW_THREADS, NPY_BEGIN_THREADS, NPY_BEGIN_THREADS_DEF, NPY_END_ALLOW_THREADS, NPY_END_THREADS, NPY_INTP_FMT, NPY_LIST_PICKLE, PyArray_DATA, PyArray_DESCR, PyArray_ISCONTIGUOUS, PyArray_ITER_NEXT, PyArray_IterNew(), PyArray_SIZE, PyDataType_FLAGCHK, and PyArrayIterObject_tag::size.

To List
NPY_NO_EXPORT PyObject* PyArray_ToString ( PyArrayObject self,
NPY_ORDER  order 
)
if (PyArray_TYPE(self) == NPY_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
NPY_NO_EXPORT PyObject* PyArray_View ( PyArrayObject self,
PyArray_Descr type,
PyTypeObject *  pytype 
)
View
steals a reference to type -- accepts NULL
Set the base object
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.