Skip to content

Commit

Permalink
Fixed autocasting tests to casting tests.. Inplace casting is not sup…
Browse files Browse the repository at this point in the history
…ported.
  • Loading branch information
teoliphant committed Nov 18, 2005
1 parent 4f869af commit d9b3850
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions scipy/base/matrix.py
@@ -1,5 +1,5 @@

__all__ = ['matrix', 'bmat', 'mat']
__all__ = ['matrix', 'bmat', 'mat', 'asmatrix']

import numeric as N
from numeric import ArrayType, concatenate, integer, multiply, power
Expand Down Expand Up @@ -44,6 +44,12 @@ def _convert_from_string(data):
newdata.append(newrow)
return newdata

def asmatrix(data, dtype=None):
""" Returns 'data' as a matrix. Unlike matrix(), no copy is performed
if 'data' is already a matrix or array. Equivalent to:
matrix(data, copy=False)
"""
return matrix(data, dtype=dtype, copy=False)

class matrix(N.ndarray):
__array_priority__ = 10.0
Expand Down Expand Up @@ -75,16 +81,16 @@ def __new__(self, data, dtype=None, copy=True):
elif ndim == 1:
shape = (1,shape[0])

fortran = False;
if (ndim == 2) and arr.flags['FORTRAN']:
fortran = False
if (ndim == 2) and arr.flags.fortran:
fortran = True

if not (fortran or arr.flags['CONTIGUOUS']):
if not (fortran or arr.flags.contiguous):
arr = arr.copy()

ret = N.ndarray.__new__(matrix, shape, arr.dtype, buffer=arr,
fortran=fortran,
swap=arr.flags['S'])
swap=arr.flags.swapped)
return ret

def __array_finalize__(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions scipy/base/tests/test_matrix.py
Expand Up @@ -83,14 +83,14 @@ def test_basic(self):

mB = mA.copy()
O = ones((10,10), float64) * 0.1
mB += O
mB = mB + O
assert mB.dtype == float64
assert all(mA != mB)
assert all(mB == mA+0.1)

mC = mA.copy()
O = ones((10,10), complex128)
mC *= O
mC = mC * O
assert mC.dtype == complex128
assert all(mA != mB)

Expand Down

0 comments on commit d9b3850

Please sign in to comment.