summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarren Weckesser <warren.weckesser@gmail.com>2019-10-23 03:49:44 -0400
committerWarren Weckesser <warren.weckesser@gmail.com>2019-10-23 04:19:24 -0400
commit20a2f8b5e953beca5d76960cbe130ebc96bd8668 (patch)
treed2459269da2acf669a20f56a1d5f525917719cb1
parent2a488fe76a0f732dc418d03b452caace161673da (diff)
downloadnumpy-20a2f8b5e953beca5d76960cbe130ebc96bd8668.tar.gz
MAINT: doc: Remove doc/newdtype_example/
This example of creating a custom dtype has had only cosmetic changes (e.g. fix whitespace, add `from __future__ ...`) since 2008, and it hasn't been touched at all since early 2016. It was never updated for Python 3. The example is not well docmented, and it is not referred to anywhere else in the documentation, so it isn't really serving a useful purpose in the doc directory. If someone is looking for an example of creating a custom dtype, we can direct them to numpy/numpy/core/src/umath/_rational_tests.c.src, which, as part of the test suite, is actively maintained. Closes gh-9282.
-rw-r--r--doc/newdtype_example/example.py18
-rw-r--r--doc/newdtype_example/floatint.c152
-rw-r--r--doc/newdtype_example/floatint/__init__.py1
-rw-r--r--doc/newdtype_example/setup.py13
4 files changed, 0 insertions, 184 deletions
diff --git a/doc/newdtype_example/example.py b/doc/newdtype_example/example.py
deleted file mode 100644
index 6be9caa75..000000000
--- a/doc/newdtype_example/example.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from __future__ import division, absolute_import, print_function
-
-import floatint.floatint as ff
-import numpy as np
-
-# Setting using array is hard because
-# The parser doesn't stop at tuples always
-# So, the setitem code will be called with scalars on the
-# wrong shaped array.
-# But we can get a view as an ndarray of the given type:
-g = np.array([1, 2, 3, 4, 5, 6, 7, 8]).view(ff.floatint_type)
-
-# Now, the elements will be the scalar type associated
-# with the ndarray.
-print(g[0])
-print(type(g[1]))
-
-# Now, you need to register ufuncs and more arrfuncs to do useful things...
diff --git a/doc/newdtype_example/floatint.c b/doc/newdtype_example/floatint.c
deleted file mode 100644
index 0cc198388..000000000
--- a/doc/newdtype_example/floatint.c
+++ /dev/null
@@ -1,152 +0,0 @@
-
-#include "Python.h"
-#include "structmember.h" /* for offset of macro if needed */
-#include "numpy/arrayobject.h"
-
-
-/* Use a Python float as the canonical type being added
-*/
-
-typedef struct _floatint {
- PyObject_HEAD
- npy_int32 first;
- npy_int32 last;
-} PyFloatIntObject;
-
-static PyTypeObject PyFloatInt_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "floatint.floatint", /*tp_name*/
- sizeof(PyFloatIntObject), /*tp_basicsize*/
-};
-
-static PyArray_ArrFuncs _PyFloatInt_Funcs;
-
-#define _ALIGN(type) offsetof(struct {char c; type v;},v)
-
-/* The scalar-type */
-
-static PyArray_Descr _PyFloatInt_Dtype = {
- PyObject_HEAD_INIT(NULL)
- &PyFloatInt_Type,
- 'f',
- '0',
- '=',
- 0,
- 0,
- sizeof(double),
- _ALIGN(double),
- NULL,
- NULL,
- NULL,
- &_PyFloatInt_Funcs
-};
-
-static void
-twoint_copyswap(void *dst, void *src, int swap, void *arr)
-{
- if (src != NULL) {
- memcpy(dst, src, sizeof(double));
- }
-
- if (swap) {
- register char *a, *b, c;
- a = (char *)dst;
- b = a + 7;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b = c;
- }
-}
-
-static PyObject *
-twoint_getitem(char *ip, PyArrayObject *ap) {
- npy_int32 a[2];
-
- if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {
- a[0] = *((npy_int32 *)ip);
- a[1] = *((npy_int32 *)ip + 1);
- }
- else {
- ap->descr->f->copyswap(a, ip, !PyArray_ISNOTSWAPPED(ap), ap);
- }
- return Py_BuildValue("(ii)", a[0], a[1]);
-}
-
-static int
-twoint_setitem(PyObject *op, char *ov, PyArrayObject *ap) {
- npy_int32 a[2];
-
- if (!PyTuple_Check(op)) {
- PyErr_SetString(PyExc_TypeError, "must be a tuple");
- return -1;
- }
- if (!PyArg_ParseTuple(op, "ii", a, a+1)) return -1;
-
- if (ap == NULL || PyArray_ISBEHAVED(ap)) {
- memcpy(ov, a, sizeof(double));
- }
- else {
- ap->descr->f->copyswap(ov, a, !PyArray_ISNOTSWAPPED(ap), ap);
- }
- return 0;
-}
-
-static PyArray_Descr * _register_dtype(void)
-{
- int userval;
- PyArray_InitArrFuncs(&_PyFloatInt_Funcs);
- /* Add copyswap,
- nonzero, getitem, setitem*/
- _PyFloatInt_Funcs.copyswap = twoint_copyswap;
- _PyFloatInt_Funcs.getitem = (PyArray_GetItemFunc *)twoint_getitem;
- _PyFloatInt_Funcs.setitem = (PyArray_SetItemFunc *)twoint_setitem;
- _PyFloatInt_Dtype.ob_type = &PyArrayDescr_Type;
-
- userval = PyArray_RegisterDataType(&_PyFloatInt_Dtype);
- return PyArray_DescrFromType(userval);
-}
-
-
-/* Initialization function for the module (*must* be called init<name>) */
-
-PyMODINIT_FUNC initfloatint(void) {
- PyObject *m, *d;
- PyArray_Descr *dtype;
-
- /* Create the module and add the functions */
- m = Py_InitModule("floatint", NULL);
-
- /* Import the array objects */
- import_array();
-
-
- /* Initialize the new float type */
-
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
-
- if (PyType_Ready(&PyFloat_Type) < 0) return;
- PyFloatInt_Type.tp_base = &PyFloat_Type;
- /* This is only needed because we are sub-typing the
- Float type and must pre-set some function pointers
- to get PyType_Ready to fill in the rest.
- */
- PyFloatInt_Type.tp_alloc = PyType_GenericAlloc;
- PyFloatInt_Type.tp_new = PyFloat_Type.tp_new;
- PyFloatInt_Type.tp_dealloc = PyFloat_Type.tp_dealloc;
- PyFloatInt_Type.tp_free = PyObject_Del;
- if (PyType_Ready(&PyFloatInt_Type) < 0) return;
- /* End specific code */
-
-
- dtype = _register_dtype();
- Py_XINCREF(dtype);
- if (dtype != NULL) {
- PyDict_SetItemString(d, "floatint_type", (PyObject *)dtype);
- }
- Py_INCREF(&PyFloatInt_Type);
- PyDict_SetItemString(d, "floatint", (PyObject *)&PyFloatInt_Type);
- return;
-}
diff --git a/doc/newdtype_example/floatint/__init__.py b/doc/newdtype_example/floatint/__init__.py
deleted file mode 100644
index 1d0f69b67..000000000
--- a/doc/newdtype_example/floatint/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import division, absolute_import, print_function
diff --git a/doc/newdtype_example/setup.py b/doc/newdtype_example/setup.py
deleted file mode 100644
index d7ab040a1..000000000
--- a/doc/newdtype_example/setup.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from __future__ import division, print_function
-
-from numpy.distutils.core import setup
-
-def configuration(parent_package = '', top_path=None):
- from numpy.distutils.misc_util import Configuration
- config = Configuration('floatint', parent_package, top_path)
-
- config.add_extension('floatint',
- sources = ['floatint.c'])
- return config
-
-setup(configuration=configuration)