summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-03-16 16:16:18 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-03-16 16:16:18 +0000
commit4506c519cd88710615cb83810b7ddc96773985a4 (patch)
tree7c04acc708ce9aa24e9b76418ed7632277f4a86c /numpy/core/src
parent8c9cf9ac2a07e9ebb8dae51a264f708229770624 (diff)
downloadnumpy-4506c519cd88710615cb83810b7ddc96773985a4.tar.gz
Expose arrayscalar structure to make scalarmath and other extensions easier to write. Move bool scalar C-API to arrayscalars.h
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/arrayobject.c2
-rw-r--r--numpy/core/src/scalarmathmodule.c.src172
-rw-r--r--numpy/core/src/scalartypes.inc.src44
3 files changed, 160 insertions, 58 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 0060fd0fa..859a4d79e 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -790,7 +790,7 @@ PyArray_FromDims(int nd, int *d, int type)
*/
if (ret && (PyArray_DESCR(ret)->type_num != PyArray_OBJECT)) {
memset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));
- }
+ }
return ret;
}
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index ec210d42e..ef3cc1ac1 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -1,5 +1,7 @@
/* The purpose of this module is to add faster math for array scalars
- that does not go through the ufunc machinery
+ that does not go through the ufunc machinery
+
+ but still supports error-modes.
NOT FINISHED
*/
@@ -8,9 +10,152 @@
#include "numpy/ufuncobject.h"
+/**end repeat**/
+
+
/**begin repeat
-name=bool,
+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#
+**/
+
+static PyObject *
+@name@_add(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_subtract(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_multiply(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_divide(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_remainder(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_divmod(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_power(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_negative(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_copy(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_absolute(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_nonzero_number(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_invert(PyObject *a, PyObject *b)
+{
+}
+static PyObject *
+@name@_lshift(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_rshift(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_and(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_xor(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_or(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_int(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_long(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_float(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_oct(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_hex(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_floor_divide(PyObject *a, PyObject *b)
+{
+}
+
+static PyObject *
+@name@_true_divide(PyObject *a, PyObject *b)
+{
+}
+
+#if PY_VERSION_HEX >= 0x02050000
+static Py_ssize_t
+@name@_index(PyObject *a)
+{
+}
+#endif
+
+
+static PyObject*
+@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)
+{
+}
+/**end repeat**/
+
+
+
+
+/**begin repeat
+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#
**/
static PyNumberMethods @name@_as_number = {
(binaryfunc)@name@_add, /*nb_add*/
@@ -51,30 +196,17 @@ static PyNumberMethods @name@_as_number = {
(binaryfunc)@name@_true_divide, /*nb_true_divide*/
0, /*nb_inplace_floor_divide*/
0, /*nb_inplace_true_divide*/
-
+#if PY_VERSION_HEX >= 0x02050000
+ (lenfunc)@name@_index, /*nb_index*/
+#endif
};
-/**end repeat**/
-
-
-/**begin repeat
-
-**/
-
-static PyObject*
-@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)
-{
-}
-/**end repeat**/
-
-
-
static void
add_scalarmath(void)
{
/**begin repeat
-name=bool,
-NAME=Bool
+#name=byte,ubyte,short,ushort,int,uint,long,ulong,float,double,longdouble,cfloat,cdouble,clongdouble#
+#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#
**/
PyArr@NAME@Type_Type.tp_as_number = @name@_as_number;
PyArr@NAME@Type_Type.tp_richcompare = @name@_richcompare;
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index a7c2a48c5..fc253e420 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -1,33 +1,14 @@
/* -*- c -*- */
+#ifndef _MULTIARRAYMODULE
+#define _MULTIARRAYMODULE
+#endif
+#include "numpy/arrayscalars.h"
static int PyArrayScalar_Offset[PyArray_NTYPES+1];
-/* to be exposed in C-API */
-#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])
-#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])
-#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \
- return Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]), \
- (PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]
-#define PyArrayScalar_RETURN_FALSE \
- return Py_INCREF(PyArrayScalar_False), \
- PyArrayScalar_False
-#define PyArrayScalar_RETURN_TRUE \
- return Py_INCREF(PyArrayScalar_True), \
- PyArrayScalar_True
-/* end to be exposed in C-API */
#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])
-/**begin repeat
-#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#
-#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#
-*/
-typedef struct {
- PyObject_HEAD
- @type@ obval;
-} Py@name@ScalarObject;
-/**end repeat**/
-
-static PyBoolScalarObject _PyArrayScalar_BoolValues[] = {
+static PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {
{PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},
{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},
};
@@ -51,17 +32,6 @@ static PyTypeObject Py@NAME@ArrType_Type = {
/**end repeat**/
-#define PyStringScalarObject PyStringObject
-#define PyUnicodeScalarObject PyUnicodeObject
-
-typedef struct {
- PyObject_VAR_HEAD
- char *obval;
- PyArray_Descr *descr;
- int flags;
- PyObject *base;
-} PyVoidScalarObject;
-
/* no error checking is performed -- ctypeptr must be same type as scalar */
/* in case of flexible type, the data is not copied
into ctypeptr which is expected to be a pointer to pointer */
@@ -1658,9 +1628,9 @@ bool_arrtype_nonzero(PyObject *a)
/* Arithmetic methods -- only so we can override &, |, ^. */
static PyNumberMethods bool_arrtype_as_number = {
- 0, /* nb_add */
+ bool_arrtype_or, /* nb_add */
0, /* nb_subtract */
- 0, /* nb_multiply */
+ bool_arrtype_and, /* nb_multiply */
0, /* nb_divide */
0, /* nb_remainder */
0, /* nb_divmod */