|
From: Sasha <nd...@ma...> - 2006-02-24 03:27:19
|
On 2/23/06, Francesc Altet <fa...@ca...> wrote:
> It's a bit late, but I want to support your proposal (most of it).
You are not late -- you are the first to reply! When you say "most of
it," is there anything in particular that you don't like?
> I've also come to the conclusion that scalars and rank-0 arrays should
> coexist. This is something that appears as a natural fact when you
> have to deal regularly with general algorithms for treat objects with
> different shapes. And I think you have put this very well.
Thanks for your kind words. If we agree to legitimize rank-0 arrays,
maybe we should start by removing conversion to scalars from ufuncs.=20
Currently:
>>> type(array(2)*2)
<type 'int32scalar'>
I believe it should result in a rank-0 array instead.
I've recently wrote ndarray round function and that code illustrates
the problem of implicite scalar conversion:
ret =3D PyNumber_Multiply((PyObject *)a, f);
if (ret=3D=3DNULL) {Py_DECREF(f); return NULL;}
if (PyArray_IsScalar(ret, Generic)) {
/* array scalars cannot be modified inplace */
PyObject *tmp;
tmp =3D PyObject_CallFunction(n_ops.rint, "O", ret)=
;
Py_DECREF(ret);
ret =3D PyObject_CallFunction(n_ops.divide, "OO",
tmp, f);
Py_DECREF(tmp);
} else {
PyObject_CallFunction(n_ops.rint, "OO", ret, ret);
PyObject_CallFunction(n_ops.divide, "OOO", ret,
f, ret);
}
|