summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scipy/base/arrayprint.py4
-rw-r--r--scipy/base/numeric.py2
-rw-r--r--scipy/base/polynomial.py2
-rw-r--r--scipy/base/src/arraytypes.inc.src30
-rw-r--r--scipy/base/src/multiarraymodule.c36
-rw-r--r--scipy/corelib/blasdot/_dotblas.c11
6 files changed, 52 insertions, 33 deletions
diff --git a/scipy/base/arrayprint.py b/scipy/base/arrayprint.py
index 8ec43de0f..6124a1bc2 100644
--- a/scipy/base/arrayprint.py
+++ b/scipy/base/arrayprint.py
@@ -186,7 +186,7 @@ def array2string(a, max_line_width = None, precision = None,
style=repr):
if a.shape == ():
- x = a[()]
+ x = a.toscalar()
try:
lst = a._format(x)
except AttributeError:
@@ -216,7 +216,7 @@ def _formatArray(a, format_function, rank, max_line_len,
"""
if rank == 0:
- return str(a[()])
+ return str(a.toscalar())
if summary_insert and 2*edge_items < len(a):
leading_items, trailing_items, summary_insert1 = \
diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py
index b388ef140..f656b58a9 100644
--- a/scipy/base/numeric.py
+++ b/scipy/base/numeric.py
@@ -87,7 +87,7 @@ def convolve(a,v,mode='full'):
if (len(v) > len(a)):
a, v = v, a
mode = _mode_from_name(mode)
- return correlate(a,asarray(v)[::-1],mode)
+ return multiarray.correlate(a,asarray(v)[::-1],mode)
inner = multiarray.inner
diff --git a/scipy/base/polynomial.py b/scipy/base/polynomial.py
index 8e6881af0..98a1903a3 100644
--- a/scipy/base/polynomial.py
+++ b/scipy/base/polynomial.py
@@ -36,7 +36,7 @@ def _lstsq(*args):
__all__ = ['poly','roots','polyint','polyder','polyadd','polysub','polymul',
- 'polydiv','polyval','poly1d','poly1d','polyfit']
+ 'polydiv','polyval','poly1d','polyfit']
def poly(seq_of_zeros):
diff --git a/scipy/base/src/arraytypes.inc.src b/scipy/base/src/arraytypes.inc.src
index 66addc234..d9dc42b06 100644
--- a/scipy/base/src/arraytypes.inc.src
+++ b/scipy/base/src/arraytypes.inc.src
@@ -1389,25 +1389,37 @@ static int
/**end repeat**/
+static void
+BOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
+ void *ignore)
+{
+ register Bool tmp=FALSE;
+ register intp i;
+ for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
+ if ((*((Bool *)ip1) != 0) && (*((Bool *)ip2) != 0)) {
+ tmp = TRUE;
+ break;
+ }
+ }
+ *((Bool *)op) = tmp;
+}
/**begin repeat
-
-#name=BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE#
-#type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#
-#out= Bool, intp, uintp, intp, uintp, intp, uintp, intp, uintp, longlong, ulonglong, float, double, longdouble#
+#name=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#
+#out= long, ulong, long, ulong, long, ulong, long, ulong, longlong, ulonglong, float, double, longdouble#
*/
-
static void
@name@_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
void *ignore)
{
- @out@ tmp=(@out@)0.0;
- int i;
+ register @out@ tmp=(@out@)0;
+ register intp i;
for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
tmp += (@out@)(*((@type@ *)ip1)) * \
(@out@)(*((@type@ *)ip2));
- }
- *((@out@ *)op) = tmp;
+ }
+ *((@type@ *)op) = (@type@) tmp;
}
/**end repeat**/
diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c
index 087e5bf46..a87d0e39f 100644
--- a/scipy/base/src/multiarraymodule.c
+++ b/scipy/base/src/multiarraymodule.c
@@ -1751,7 +1751,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2)
prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);
prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);
subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);
-
+
ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
typenum, NULL, NULL, 0, 0,
(PyObject *)
@@ -1910,7 +1910,6 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2)
ip1 += is1r;
}
if (PyErr_Occurred()) goto fail;
-
Py_DECREF(ap1);
@@ -1983,12 +1982,14 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
{
PyArrayObject *ap1, *ap2, *ret;
intp length;
- int i, n1, n2, n, n_left, n_right;
+ intp i, n1, n2, n, n_left, n_right;
int typenum;
- int is1, is2, os;
+ intp is1, is2, os;
char *ip1, *ip2, *op;
PyArray_DotFunc *dot;
PyArray_Typecode typec = {0,0,0};
+ double prior1, prior2;
+ PyTypeObject *subtype=NULL;
typenum = PyArray_ObjectType(op1, 0);
typenum = PyArray_ObjectType(op2, typenum);
@@ -1998,12 +1999,12 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
ap1 = (PyArrayObject *)PyArray_FromAny(op1, &typec, 1, 1,
DEFAULT_FLAGS);
if (ap1 == NULL) return NULL;
- ap2 = (PyArrayObject *)PyArray_FromAny(op1, &typec, 1, 1,
+ ap2 = (PyArrayObject *)PyArray_FromAny(op2, &typec, 1, 1,
DEFAULT_FLAGS);
if (ap2 == NULL) goto fail;
- n1 = ap1->dimensions[ap1->nd-1];
- n2 = ap2->dimensions[ap2->nd-1];
+ n1 = ap1->dimensions[0];
+ n2 = ap2->dimensions[0];
if (n1 < n2) {
ret = ap1; ap1 = ap2; ap2 = ret;
@@ -2017,7 +2018,7 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
n_left = n_right = 0;
break;
case 1:
- n_left = (int)(n/2);
+ n_left = (intp)(n/2);
n_right = n-n_left-1;
break;
case 2:
@@ -2030,22 +2031,29 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode)
"mode must be 0, 1, or 2");
goto fail;
}
+
+ /* Need to choose an output array that can hold a sum
+ -- use priority to determine which subtype.
+ */
+ prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);
+ prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);
+ subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);
- ret = (PyArrayObject *)PyArray_New(ap1->ob_type, 1,
+ ret = (PyArrayObject *)PyArray_New(subtype, 1,
&length, typenum,
- NULL, NULL, 0, 0,
- (PyObject *)ap1);
+ NULL, NULL, 0, 0,
+ (PyObject *)
+ (prior2 > prior1 ? ap2 : ap1));
if (ret == NULL) goto fail;
-
dot = ret->descr->dotfunc;
if (dot == NULL) {
PyErr_SetString(PyExc_ValueError,
- "function not available for this type");
+ "function not available for this data type");
goto fail;
}
- is1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1];
+ is1 = ap1->strides[0]; is2 = ap2->strides[0];
op = ret->data; os = ret->itemsize;
ip1 = ap1->data; ip2 = ap2->data+n_left*is2;
diff --git a/scipy/corelib/blasdot/_dotblas.c b/scipy/corelib/blasdot/_dotblas.c
index 6b77dc319..b1e689c56 100644
--- a/scipy/corelib/blasdot/_dotblas.c
+++ b/scipy/corelib/blasdot/_dotblas.c
@@ -127,7 +127,6 @@ dotblas_restoredot(PyObject *dummy, PyObject *args)
static char doc_matrixproduct[] = "matrixproduct(a,b)\nReturns the dot product of a and b for arrays of floating point types.\nLike the generic scipy equivalent the product sum is over\nthe last dimension of a and the second-to-last dimension of b.\nNB: The first argument is not conjugated.";
-
static PyObject *
dotblas_matrixproduct(PyObject *dummy, PyObject *args)
{
@@ -159,7 +158,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)
/* This function doesn't handle other types */
if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&
typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {
- return PyArray_MatrixProduct(op1, op2);
+ return PyArray_Return((PyArrayObject *)PyArray_MatrixProduct(op1, op2));
}
ret = NULL;
@@ -185,7 +184,7 @@ dotblas_matrixproduct(PyObject *dummy, PyObject *args)
(PyObject *)ap2);
Py_DECREF(ap1);
Py_DECREF(ap2);
- return (PyObject *)ret;
+ return PyArray_Return(ret);
}
if (ap1->nd == 0 || ap2->nd == 0) {
@@ -408,7 +407,7 @@ dotblas_innerproduct(PyObject *dummy, PyObject *args)
/* This function doesn't handle other types */
if ((typenum != PyArray_DOUBLE && typenum != PyArray_CDOUBLE &&
typenum != PyArray_FLOAT && typenum != PyArray_CFLOAT)) {
- return PyArray_InnerProduct(op1, op2);
+ return PyArray_Return((PyArrayObject *)PyArray_InnerProduct(op1, op2));
}
ret = NULL;
@@ -434,7 +433,7 @@ dotblas_innerproduct(PyObject *dummy, PyObject *args)
(PyObject *)ap2);
Py_DECREF(ap1);
Py_DECREF(ap2);
- return (PyObject *)ret;
+ return PyArray_Return(ret);
}
if (ap1->nd == 0 || ap2->nd == 0) {
@@ -679,7 +678,7 @@ static PyObject *dotblas_vdot(PyObject *dummy, PyObject *args) {
(PyObject *)ap2);
Py_DECREF(ap1);
Py_DECREF(ap2);
- return (PyObject *)ret;
+ return PyArray_Return(ret);
}
if (ap2->dimensions[0] != ap1->dimensions[ap1->nd-1]) {