[Numpy-svn] r5867 - branches/clean_math_config_chuck/numpy/core/src
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri Sep 26 23:35:44 EDT 2008
Author: charris
Date: 2008-09-26 22:35:33 -0500 (Fri, 26 Sep 2008)
New Revision: 5867
Modified:
branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src
Log:
Work in progress.
Modified: branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src 2008-09-26 04:38:40 UTC (rev 5866)
+++ branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src 2008-09-27 03:35:33 UTC (rev 5867)
@@ -441,7 +441,19 @@
*****************************************************************************
*/
+#define BINARY_LOOP\
+ char *ip1 = args[0], *ip2 = args[1], *op = args[2];\
+ intp is1 = steps[0], is2 = steps[1], os = steps[2];\
+ intp n = dimensions[0];\
+ intp i;\
+ for(i = 0; i < n; i++, ip1 += is1, ip2 += is2, op += os)
+#define UNARY_LOOP\
+ char *ip1 = args[0], *op = args[1];\
+ intp is1 = steps[0], os = steps[1];\
+ intp n = dimensions[0];\
+ intp i;\
+ for(i = 0; i < n; i++, ip1 += is1, op += os)
/*
*****************************************************************************
** BOOLEAN LOOPS **
@@ -449,81 +461,75 @@
*/
/**begin repeat
- * Boolean type
- *
- * #type = Bool#
- * #TYPE = BOOL#
- */
-
-
-/**begin repeat
- *
- * #kind = add, subtract, multiply, greater, greater_equal, less, less_equal,
- * equal, not_equal, logical_and, logical_or, bitwise_and, bitwise_or,
- * bitwise_xor#
- * #OP = ||, ^, &&, >, >=, <, <=, ==, !=, &&, ||, &, |, ^#
+ * #kind = equal, not_equal, greater, greater_equal, less, less_equal,
+ * logical_and, logical_or, logical_xor#
+ * #OP = ==, !=, >, >=, <, <=, &&, ||, ^#
**/
static void
BOOL_ at kind@(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i;
- intp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- Bool in1 = (*((Bool *)i1) != 0);
- Bool in2 = (*((Bool *)i2) != 0);
+ BINARY_LOOP {
+ Bool in1 = (*((Bool *)ip1) != 0);
+ Bool in2 = (*((Bool *)ip2) != 0);
*((Bool *)op)= in1 @OP@ in2;
}
}
/**end repeat**/
+/**begin repeat
+ * #kind = maximum, minimum#
+ * #OP = >, <#
+ **/
static void
-BOOL_ones_like(char **args, intp *dimensions, intp *steps, void *data)
+BOOL_ at kind@(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, os = steps[1], n = dimensions[0];
- char *op = args[1];
-
- for (i = 0; i < n; i++, op += os) {
- *((Bool *)op) = 1;
+ BINARY_LOOP {
+ Bool in1 = (*((Bool *)ip1) != 0);
+ Bool in2 = (*((Bool *)ip2) != 0);
+ *((Bool *)op) = (in1 @OP@ in2) ? in1 : in2;
}
}
+/**end repeat**/
+/**begin repeat
+ * #kind = absolute, logical_not#
+ * #OP = !=, ==#
+ **/
static void
-BOOL_absolute(char **args, intp *dimensions, intp *steps, void *func)
+BOOL_ at kind@(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, n;
- intp is1=steps[0], os=steps[1];
- char *i1=args[0], *op=args[1];
-
- n=dimensions[0];
-
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((Bool *)op) = *((Bool*)i1);
+ UNARY_LOOP {
+ Bool in1 = *(Bool *)ip1;
+ *((Bool *)op) = in1 @OP@ 0;
}
}
+/**end repeat**/
static void
-BOOL_logical_not(char **args, intp *dimensions, intp *steps, void *func)
+BOOL_ones_like(char **args, intp *dimensions, intp *steps, void *data)
{
- intp i;
- intp is1=steps[0],os=steps[1], n=dimensions[0];
- char *i1=args[0], *op=args[1];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((Bool *)op) = ! *((Bool *)i1);
+ UNARY_LOOP {
+ *((Bool *)op) = 1;
}
}
+#define BOOL_invert BOOL_logical_not
#define BOOL_negative BOOL_logical_not
+#define BOOL_add BOOL_logical_or
+#define BOOL_bitwise_and BOOL_logical_and
+#define BOOL_bitwise_or BOOL_logical_or
+#define BOOL_bitwise_xor BOOL_logical_xor
+#define BOOL_multiply BOOL_logical_and
+#define BOOL_subtract BOOL_logical_xor
/*
*****************************************************************************
- ** INTEGER LOOPS **
+ ** INTEGER LOOPS
*****************************************************************************
*/
/**begin repeat
- * base integer types.
* #type = byte, short, int, long, longlong#
* #TYPE = BYTE, SHORT, INT, LONG, LONGLONG#
* #ftype = float, float, double, double, double#
@@ -535,137 +541,115 @@
* # S = , U#
*/
-/**begin repeat2
- * Arithmetic
- * # kind = add, subtract, multiply, bitwise_and, bitwise_or, bitwise_xor
- * left_shift, right_shift#
- * # OP = +, -,*, &, |, ^, <<, >>#
- */
static void
- at S@@TYPE at _@kind@(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _square(char **args, intp *dimensions, intp *steps, void *data)
{
- register intp i;
- intp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- *((@s@@type@ *)op)=*((@s@@type@ *)i1) @OP@ *((@s@@type@ *)i2);
+ UNARY_LOOP {
+ const @s@@type@ in1 = *((@s@@type@ *)ip1);
+ *((@s@@type@ *)op) = in1*in1;
}
}
-/**end repeat2**/
-/**begin repeat2
- * #kind = greater, greater_equal, less, less_equal, equal, not_equal,
- * logical_and, logical_or#
- * #OP = >, >=, <, <=, ==, !=, &&, ||#
- */
static void
- at S@@TYPE at _@kind@(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _reciprocal(char **args, intp *dimensions, intp *steps, void *data)
{
- intp i;
- intp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- *((Bool *)op)=*((@s@@type@ *)i1) @OP@ *((@s@@type@ *)i2);
+ UNARY_LOOP {
+ const @s@@type@ in1 = *((@s@@type@ *)ip1);
+ *((@s@@type@ *)op) = 1.0/in1;
}
}
-/**end repeat2**/
static void
- at S@@TYPE at _true_divide(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _ones_like(char **args, intp *dimensions, intp *steps, void *data)
{
- register intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- if (*((@s@@type@ *)i2)==0) {
- generate_divbyzero_error();
- *((@otype@ *)op)=0;
- }
- else {
- *((@otype@ *)op)=
- (@otype@)((double)*((@s@@type@ *)i1) / (double)*((@s@@type@ *)i2));
- }
+ UNARY_LOOP {
+ *((@s@@type@ *)op) = 1;
}
}
static void
- at S@@TYPE at _square(char **args, intp *dimensions, intp *steps, void *data)
+ at S@@TYPE at _conjugate(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, is1 = steps[0], os = steps[1], n = dimensions[0];
- char *i1 = args[0], *op = args[1];
-
- for (i = 0; i < n; i++, i1 += is1, op += os) {
- @s@@type@ x = *((@s@@type@ *)i1);
- *((@s@@type@ *)op) = x*x;
+ UNARY_LOOP {
+ const @s@@type@ in1 = *((@s@@type@ *)ip1);
+ *((@s@@type@ *)op) = in1;
}
}
static void
- at S@@TYPE at _reciprocal(char **args, intp *dimensions, intp *steps, void *data)
+ at S@@TYPE at _negative(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, is1 = steps[0], os = steps[1], n = dimensions[0];
- char *i1 = args[0], *op = args[1];
-
- for (i = 0; i < n; i++, i1 += is1, op += os) {
- @s@@type@ x = *((@s@@type@ *)i1);
- *((@s@@type@ *)op) = 1.0/x;
+ UNARY_LOOP {
+ const @s@@type@ in1 = *((@s@@type@ *)ip1);
+ *((@s@@type@ *)op) = (@s@@type@)(-(@type@)in1);
}
}
static void
- at S@@TYPE at _ones_like(char **args, intp *dimensions, intp *steps, void *data)
+ at S@@TYPE at _logical_not(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, os = steps[1], n = dimensions[0];
- char *op = args[1];
-
- for (i = 0; i < n; i++, op += os) {
- *((@s@@type@ *)op) = 1;
+ UNARY_LOOP {
+ const @s@@type@ in1 = *((@s@@type@ *)ip1);
+ *((Bool *)op) = !in1;
}
}
+/**begin repeat2
+ * Arithmetic
+ * #kind = add, subtract, multiply, bitwise_and, bitwise_or, bitwise_xor
+ * left_shift, right_shift#
+ * #OP = +, -,*, &, |, ^, <<, >>#
+ */
static void
- at S@@TYPE at _power(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _@kind@(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, is1=steps[0],is2=steps[1];
- intp os=steps[2], n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- @ftype@ x, y;
-
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- x = (@ftype@)*((@s@@type@ *)i1);
- y = (@ftype@)*((@s@@type@ *)i2);
- *((@s@@type@ *)op) = (@s@@type@) pow(x,y);
+ BINARY_LOOP {
+ const @s@@type@ in1 = *(@s@@type@ *)ip1;
+ const @s@@type@ in2 = *(@s@@type@ *)ip2;
+ *((@s@@type@ *)op) = in1 @OP@ in2;
}
}
+/**end repeat2**/
+/**begin repeat2
+ * #kind = equal, not_equal, greater, greater_equal, less, less_equal,
+ * logical_and, logical_or#
+ * #OP = ==, !=, >, >=, <, <=, &&, ||#
+ */
static void
- at S@@TYPE at _conjugate(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _@kind@(char **args, intp *dimensions, intp *steps, void *func)
{
- register intp i, is1=steps[0], os=steps[1], n=dimensions[0];
- char *i1=args[0], *op=args[1];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((@s@@type@ *)op)=*((@s@@type@ *)i1);
+ BINARY_LOOP {
+ const @s@@type@ in1 = *(@s@@type@ *)ip1;
+ const @s@@type@ in2 = *(@s@@type@ *)ip2;
+ *((Bool *)op) = in1 @OP@ in2;
}
}
+/**end repeat2**/
static void
- at S@@TYPE at _negative(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _true_divide(char **args, intp *dimensions, intp *steps, void *func)
{
- register intp i;
- intp is1=steps[0],os=steps[1], n=dimensions[0];
- char *i1=args[0], *op=args[1];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((@s@@type@ *)op) = (@s@@type@)(-(@type@)*((@s@@type@ *)i1));
+ BINARY_LOOP {
+ const @s@@type@ in1 = *(@s@@type@ *)ip1;
+ const @s@@type@ in2 = *(@s@@type@ *)ip2;
+ if (in2 == 0) {
+ generate_divbyzero_error();
+ *((@otype@ *)op) = 0;
+ }
+ else {
+ *((@ftype@ *)op) = (@ftype@)in1 / (@ftype@)in2;
+ }
}
}
static void
- at S@@TYPE at _logical_not(char **args, intp *dimensions, intp *steps, void *func)
+ at S@@TYPE at _power(char **args, intp *dimensions, intp *steps, void *func)
{
- register intp i;
- intp is1=steps[0],os=steps[1], n=dimensions[0];
- char *i1=args[0], *op=args[1];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((Bool *)op) = ! *((@s@@type@ *)i1);
+ BINARY_LOOP {
+ const @ftype@ in1 = (@ftype@)*((@s@@type@ *)ip1);
+ const @ftype@ in2 = (@ftype@)*((@s@@type@ *)ip2);
+ *((@s@@type@ *)op) = (@s@@type@) pow(in1, in2);
}
}
@@ -674,27 +658,18 @@
static void
U at TYPE@_absolute(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, n;
- intp is1=steps[0], os=steps[1];
- char *i1=args[0], *op=args[1];
-
- n=dimensions[0];
-
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((u at type@ *)op) = *((u at type@*)i1);
+ UNARY_LOOP {
+ const u at type@ in1 = *((u at type@ *)ip1);
+ *((u at type@ *)op) = in1;
}
}
static void
@TYPE at _absolute(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, n;
- intp is1=steps[0], os=steps[1];
- char *i1=args[0], *op=args[1];
-
- n=dimensions[0];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((@type@ *)op) = *((@type@ *)i1) < 0 ? -*((@type@ *)i1) : *((@type@ *)i1);
+ UNARY_LOOP {
+ const @type@ in1 = *((@type@ *)ip1);
+ *((@type@ *)op) = (in1 > 0) ? in1 : -in1;
*((@type@ *)op) += 0; /* fixme clear sign-bit ? */
}
}
@@ -702,21 +677,18 @@
static void
@TYPE at _divide(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- @type@ x, y, tmp;
-
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- y = *((@type@ *)i2);
- if (y == 0) {
+ BINARY_LOOP {
+ const @type@ in1 = *(@type@ *)ip1;
+ const @type@ in2 = *(@type@ *)ip2;
+ if (in2 == 0) {
generate_divbyzero_error();
- *((@type@ *)op)=0;
+ *((@type@ *)op) = 0;
}
+ else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) {
+ *((@type@ *)op) = in1/in2 - 1;
+ }
else {
- x = *((@type@ *)i1);
- tmp = x / y;
- if (((x > 0) != (y > 0)) && (x % y != 0)) tmp--;
- *((@type@ *)op)= tmp;
+ *((@type@ *)op) = in1/in2;
}
}
}
@@ -724,15 +696,15 @@
static void
U at TYPE@_divide(char **args, intp *dimensions, intp *steps, void *func)
{
- intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0];
- char *i1=args[0], *i2=args[1], *op=args[2];
- for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) {
- if (*((u at type@ *)i2)==0) {
+ BINARY_LOOP {
+ const u at type@ in1 = *(u at type@ *)ip1;
+ const u at type@ in2 = *(u at type@ *)ip2;
+ if (in2 == 0) {
generate_divbyzero_error();
- *((u at type@ *)op)=0;
+ *((u at type@ *)op) = 0;
}
else {
- *((u at type@ *)op)= *((u at type@ *)i1) / *((u at type@ *)i2);
+ *((u at type@ *)op)= in1/in2;
}
}
}
@@ -1378,21 +1350,11 @@
}
/**end repeat**/
-static void
-BOOL_invert(char **args, intp *dimensions, intp *steps, void *func)
-{
- register intp i;
- intp is1=steps[0], os=steps[1], n=dimensions[0];
- char *i1=args[0], *op=args[1];
- for(i=0; i<n; i++, i1+=is1, op+=os) {
- *((Bool *)op) = (*((Bool *)i1) ? FALSE : TRUE);
- }
-}
/*logical_xor*/
/**begin repeat
- #TYPE=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#
- #typ=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#
+ #TYPE=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#
+ #typ=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#
*/
static void
@@ -1431,10 +1393,10 @@
/*max,min*/
/**begin repeat
- #TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#
- #OP= >*14, <*14#
- #typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#
- #kind= maximum*14, minimum*14#
+ #TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#
+ #OP= >*13, <*13#
+ #typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#
+ #kind= maximum*13, minimum*13#
*/
static void
@TYPE at _@kind@(char **args, intp *dimensions, intp *steps, void *func)
More information about the Numpy-svn
mailing list