summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric/compat.py
blob: ebc978fee045094310310a58e7f0a2ffe02a1a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Compatibility module containing deprecated names

__all__ = ['NewAxis',
           'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',
           'LittleEndian',
           'sarray', 'arrayrange', 'cross_correlate',
           'matrixmultiply', 'outerproduct', 'innerproduct',
           'cross_product', 'array_constructor',
           'DumpArray', 'LoadArray', 'multiarray', 'divide_safe',
           # from cPickle
           'dump', 'dumps'
          ]

import numpy.core.multiarray as multiarray
import numpy.core.umath as um
from numpy.core.numeric import array, correlate, outer, cross
from numpy.core.umath import sign, absolute, multiply
import sys

import types

from cPickle import dump, dumps

def sarray(a, dtype=None, copy=False):
    return array(a, dtype, copy)

mu = multiarray

#Use this to add a new axis to an array
#compatibility only
NewAxis = None

#deprecated
UFuncType = type(um.sin)
UfuncType = type(um.sin)
ArrayType = mu.ndarray
arraytype = mu.ndarray

LittleEndian = (sys.byteorder == 'little')

from numpy import deprecate 

# backward compatibility
arrayrange = deprecate(mu.arange, 'arrayrange', 'arange')
cross_correlate = deprecate(correlate, 'cross_correlate', 'correlate')
cross_product = deprecate(cross, 'cross_product', 'cross')
divide_safe = deprecate(um.divide, 'divide_safe', 'divide')

# deprecated names
matrixmultiply = deprecate(mu.dot, 'matrixmultiply', 'dot')
outerproduct = deprecate(outer, 'outerproduct', 'outer')
innerproduct = deprecate(mu.inner, 'innerproduct', 'inner')


def DumpArray(m, fp):
    m.dump(fp)

def LoadArray(fp):
    import cPickle
    return cPickle.load(fp)

def array_constructor(shape, typecode, thestr, Endian=LittleEndian):
    if typecode == "O":
        x = array(thestr, "O")
    else:
        x = mu.fromstring(thestr, typecode)
    x.shape = shape
    if LittleEndian != Endian:
        return x.byteswap(TRUE)
    else:
        return x