File: common_routines.py

package info (click to toggle)
python-scipy 0.3.2-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,572 kB
  • ctags: 20,326
  • sloc: ansic: 87,138; fortran: 51,876; python: 47,747; cpp: 2,134; objc: 384; makefile: 175; sh: 83
file content (26 lines) | stat: -rw-r--r-- 836 bytes parent folder | download
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

from scipy_base import *
from scipy_base.fastumath import *

def myasarray(a):
    if type(a) in [type(1.0),type(1L),type(1),type(1j)]:
        return asarray([a])
    elif type(a) is ArrayType and len(a)==1:
        # Takes care of mapping array(number) to array([number])
        return asarray([a[0]])
    else:
        return asarray(a)

def check_func(thefunc, x0, args, numinputs, output_shape=None):
    args = (x0[:numinputs],) + args
    res = myasarray(apply(thefunc,args))
    if (output_shape != None) and (res.shape != output_shape):
        if (output_shape[0] != 1):
            if len(output_shape) > 1:
                if output_shape[1] == 1:
                    return res.shape
            raise TypeError, "There is a mismatch between the input and output shape of %s." % thefunc.func_name
    return res.shape