summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2006-06-26 09:15:27 +0000
committerStefan van der Walt <stefan@sun.ac.za>2006-06-26 09:15:27 +0000
commitb2c84d9ad624f9adc3620a65c2d3c0353c03324d (patch)
tree965ea7dcb714c7d5ae23e126c81e32ae75df0a29 /numpy
parente70feca6cd7278a7bebc9a49f0cac3b2d071e0bc (diff)
downloadnumpy-b2c84d9ad624f9adc3620a65c2d3c0353c03324d.tar.gz
Revert previous change but add unit test to catch ticket #156.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/arrayobject.c30
-rw-r--r--numpy/core/tests/test_numeric.py34
2 files changed, 34 insertions, 30 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 39483f4f0..8d9da7567 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -6751,36 +6751,6 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
iswap = PyArray_ISBYTESWAPPED(mp);
oswap = PyArray_ISBYTESWAPPED(out);
-
- if (same && mpsize < PyArray_BUFSIZE) {
- PyArrayObject *mp2, *out2;
- if (!PyArray_ISCARRAY_RO(mp)) {
- mp2 = (PyArrayObject *)PyArray_NewCopy(mp,
- PyArray_CORDER);
- }
- else {
- mp2 = mp;
- Py_INCREF(mp2);
- }
- if (mp2 == NULL) return -1;
- if (!PyArray_ISCARRAY(out)) {
- out2 = (PyArrayObject *)PyArray_NewCopy(out,
- PyArray_CORDER);
- }
- else {
- out2 = out;
- Py_INCREF(out2);
- }
- if (out2 == NULL) { Py_DECREF(mp2); return -1;}
- if (iswap) byte_swap_vector(mp2->data, mpsize,
- PyArray_ITEMSIZE(mp2));
- castfunc(mp2->data, out2->data, mpsize, mp2, out2);
- if (oswap) byte_swap_vector(out2->data, mpsize,
- PyArray_ITEMSIZE(out2));
- Py_DECREF(out2);
- Py_DECREF(mp2);
- return 0;
- }
return _broadcast_cast(out, mp, castfunc, iswap, oswap);
}
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 9f6118f19..be5a3ab4d 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -3,6 +3,33 @@ from numpy.random import rand, randint
from numpy.testing import *
from numpy.core.multiarray import dot as dot_
+class Vec:
+ def __init__(self,sequence=None):
+ if sequence is None:
+ sequence=[]
+ self.array=array(sequence)
+ def __add__(self,other):
+ out=Vec()
+ out.array=self.array+other.array
+ return out
+ def __sub__(self,other):
+ out=Vec()
+ out.array=self.array-other.array
+ return out
+ def __mul__(self,other): # with scalar
+ out=Vec(self.array.copy())
+ out.array*=other
+ return out
+ def __rmul__(self,other):
+ return self*other
+ def __abs__(self):
+ out=Vec()
+ out.array=abs(self.array)
+ return out
+ def __repr__(self):
+ return "Vec("+repr(self.array.tolist())+")"
+ __str__=__repr__
+
class test_dot(NumpyTestCase):
def setUp(self):
self.A = rand(10,8)
@@ -103,6 +130,13 @@ class test_dot(NumpyTestCase):
assert (c1.shape == c2.shape)
assert_almost_equal(c1, c2, decimal=self.N)
+ def check_vecobject(self,level=2):
+ U_non_cont = transpose([[1.,1.],[1.,2.]])
+ U_cont = ascontiguousarray(U_non_cont)
+ x = array([Vec([1.,0.]),Vec([0.,1.])])
+ assert_almost_equal(dot(U_cont,x),
+ dot(U_non_cont,x))
+
class test_bool_scalar(NumpyTestCase):
def test_logical(self):