numpy  2.0.0
src/multiarray/convert.c File Reference
#include <Python.h>
#include "structmember.h"
#include <npy_config.h>
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "npy_pycompat.h"
#include "arrayobject.h"
#include "ctors.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

int fallocate (int fd, int mode, off_t offset, off_t len)
static int npy_fallocate (npy_intp nbytes, FILE *fp)
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

int fallocate ( int  fd,
int  mode,
off_t  offset,
off_t  len 
)

Referenced by npy_fallocate().

static int npy_fallocate ( npy_intp  nbytes,
FILE *  fp 
) [static]
allocate nbytes of diskspace for file fp this allows the filesystem to make smarter allocation decisions and gives a fast exit on not enough free space returns -1 and raises exception on no space, ignores all other errors
unknown behavior on non-linux so don't try it we don't want explicit zeroing to happen

References fallocate(), NPY_BEGIN_ALLOW_THREADS, NPY_END_ALLOW_THREADS, npy_ftell, and NPY_INTP_FMT.

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
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
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
Try long long before unsigned long long
Long long failed, try unsigned long long
Long long succeeded
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
The dtype of the destination is used when converting from the pyobject, so that for example a tuple gets recognized as a struct scalar of the required type.

References NPY_LONGLONG, NPY_ULONGLONG, and PyArray_DescrFromType().

NPY_NO_EXPORT PyObject* PyArray_NewCopy ( PyArrayObject obj,
NPY_ORDER  order 
)
Copy an array.

Referenced by _bad_strides(), and cblas_matrixproduct().

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
For zero-width data types there's nothing to write
text data
standard writing
use format string
write separator for all but last one
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
2016-09-19, 1.12
Only warn once per array
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