David M. Cooke wrote:
On Thu, Aug 16, 2007 at 04:39:02PM -1000, Eric Firing wrote:
As far as I can see there is no way of using svn diff to deal with
this automatically, so in the attached revision I have manually removed
chunks resulting solely from whitespace.
Is there a better way to handle this problem? A better way to make diffs?
Or any possibility of routinely cleaning the junk out of the svn source
files? (Yes, I know--what is junk to me probably results from what others
consider good behavior of the editor.)
'svn diff -x -b' might work better (-b gets passed to diff, which makes
it ignore space changes). Or svn diff -x -w to ignore all whitespace.
Me, I hate trailing ws too (I've got Emacs set up so that gets
highlighted as red, which makes me angry :). The hard tabs in C code is
keeping with the style used in the C Python sources (Emacs even has a
'python' C style -- do "C-c . python").
David,
Thank you. I had tried something like that a while ago without success,
and now I know why: the '-w' has to be quoted to keep it out of the
clutches of the shell, so it is "svn diff -x '-w'". The result is
attached. Much better.
As for hard tabs in C Python sources--it is still a bad idea even if the
BDFL himself does it--very bad for Python, not quite as bad for C, but
still bad. Too fragile, too dependent on editor configuration, and in
numpy, not done consistently--it's a complete mishmash of tabs and
spaces. OK, enough of that.
Eric
Index: numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- numpy/core/include/numpy/ndarrayobject.h (revision 3967)
+++ numpy/core/include/numpy/ndarrayobject.h (working copy)
@@ -1049,6 +1049,8 @@
typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min,
void *max, void *out);
+typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in,
+ void *values, npy_intp nv);
typedef struct {
npy_intp *ptr;
@@ -1126,6 +1128,7 @@
int *cancastto;
PyArray_FastClipFunc *fastclip;
+ PyArray_FastPutmaskFunc *fastputmask;
} PyArray_ArrFuncs;
#define NPY_ITEM_REFCOUNT 0x01 /* The item must be reference counted
Index: numpy/core/src/multiarraymodule.c
===================================================================
--- numpy/core/src/multiarraymodule.c (revision 3967)
+++ numpy/core/src/multiarraymodule.c (working copy)
@@ -4065,6 +4065,7 @@
static PyObject *
PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0)
{
+ PyArray_FastPutmaskFunc *func;
PyArrayObject *mask, *values;
int i, chunk, ni, max_item, nv, tmp;
char *src, *dest;
@@ -4114,12 +4115,11 @@
Py_INCREF(Py_None);
return Py_None;
}
- if (nv > 0) {
if (PyDataType_REFCHK(self->descr)) {
for(i=0; i<ni; i++) {
- src = values->data + chunk * (i % nv);
tmp = ((Bool *)(mask->data))[i];
if (tmp) {
+ src = values->data + chunk * (i % nv);
PyArray_Item_INCREF(src, self->descr);
PyArray_Item_XDECREF(dest+i*chunk,
self->descr);
memmove(dest + i * chunk, src, chunk);
@@ -4127,13 +4127,20 @@
}
}
else {
+ func = self->descr->f->fastputmask;
+ if (func == NULL) {
for(i=0; i<ni; i++) {
+ tmp = ((Bool *)(mask->data))[i];
+ if (tmp) {
src = values->data + chunk * (i % nv);
- tmp = ((Bool *)(mask->data))[i];
- if (tmp) memmove(dest + i * chunk, src, chunk);
+ memmove(dest + i * chunk, src, chunk);
}
}
}
+ else {
+ func(dest, mask->data, ni, values->data, nv);
+ }
+ }
Py_XDECREF(values);
Py_XDECREF(mask);
Index: numpy/core/src/arraytypes.inc.src
===================================================================
--- numpy/core/src/arraytypes.inc.src (revision 3967)
+++ numpy/core/src/arraytypes.inc.src (working copy)
@@ -2100,6 +2100,42 @@
#define OBJECT_fastclip NULL
+/************************
+ * Fast putmask functions
+ *************************/
+
+/**begin repeat
+#name=BOOL,BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG,
ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE,CFLOAT, CDOUBLE, CLONGDOUBLE#
+#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong,
ulonglong, float, double, longdouble,cfloat, cdouble, clongdouble#
+*/
+static void
[EMAIL PROTECTED]@_fastputmask(@type@ *in, Bool *mask, intp ni, @type@ *vals,
intp nv)
+{
+ register npy_intp i;
+ @type@ s_val;
+
+ if (nv == 1) {
+ s_val = *vals;
+ for (i = 0; i < ni; i++) {
+ if (mask[i]) {
+ in[i] = s_val;
+ }
+ }
+ }
+ else {
+ for (i = 0; i < ni; i++) {
+ if (mask[i]) {
+ in[i] = vals[i%nv];
+ }
+ }
+ }
+ return;
+}
+/**end repeat**/
+
+#define OBJECT_fastputmask NULL
+
+
#define _ALIGN(type) offsetof(struct {char c; type v;},v)
/* Disable harmless compiler warning "4116: unnamed type definition in
@@ -2164,7 +2200,8 @@
(PyArray_ScalarKindFunc*)NULL,
NULL,
NULL,
- (PyArray_FastClipFunc *)NULL
+ (PyArray_FastClipFunc *)NULL,
+ (PyArray_FastPutmaskFunc *)NULL
};
static PyArray_Descr @[EMAIL PROTECTED] = {
@@ -2241,7 +2278,8 @@
(PyArray_ScalarKindFunc*)NULL,
NULL,
NULL,
- (PyArray_FastClipFunc*)@[EMAIL PROTECTED]
+ (PyArray_FastClipFunc*)@[EMAIL PROTECTED],
+ (PyArray_FastPutmaskFunc*)@[EMAIL PROTECTED]
};
static PyArray_Descr @[EMAIL PROTECTED] = {
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion