~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to python/src/NumericalMathFunction.i

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-05-10 17:27:55 UTC
  • mfrom: (1.1.4 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100510172755-cb5ynskknqqi5rhp
Tags: 0.13.2-2ubuntu1
* Merge with Debian testing. No changes left.
* ubuntu_fix-python-2.6.patch: fix detection of python 2.6 libs, to not use
  LOCALMODLIBS. This pulls a dependency on SSL and makes the package FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// SWIG file NumericalMathFunction.i
2
2
// Author : $LastChangedBy: dutka $
3
 
// Date : $LastChangedDate: 2008-10-15 17:56:07 +0200 (mer. 15 oct. 2008) $
4
 
// Id : $Id: NumericalMathFunction.i 972 2008-10-15 15:56:07Z dutka $
 
3
// Date : $LastChangedDate: 2010-01-27 14:00:03 +0100 (mer. 27 janv. 2010) $
 
4
// Id : $Id: NumericalMathFunction.i 1452 2010-01-27 13:00:03Z dutka $
5
5
 
6
6
%{
7
7
#include "NumericalMathFunction.hxx"
8
8
#include "PythonNumericalMathEvaluationImplementation.hxx"
 
9
 
 
10
namespace OpenTURNS { 
 
11
 
 
12
  template <>
 
13
  struct traitsPythonType<OpenTURNS::Base::Func::NumericalMathFunction>
 
14
  {
 
15
    typedef _PyObject_ Type;
 
16
  };
 
17
 
 
18
  template <>
 
19
  inline
 
20
  OpenTURNS::Base::Func::NumericalMathFunction
 
21
  convert<_PyObject_,OpenTURNS::Base::Func::NumericalMathFunction>(PyObject * pyObj)
 
22
  {
 
23
   if (!PyCallable_Check( pyObj )) {
 
24
     throw OT::Base::Common::InvalidArgumentException(HERE) << "Argument is not a callable object (function or class)";
 
25
   }
 
26
 
 
27
   return OpenTURNS::Base::Func::NumericalMathFunction(new OpenTURNS::Base::Func::NumericalMathFunctionImplementation(new OpenTURNS::Base::Func::PythonNumericalMathEvaluationImplementation(pyObj) ) );
 
28
 
 
29
  }
 
30
 
 
31
} /* namespace OpenTURNS */
 
32
 
9
33
%}
10
34
 
11
35
%pythoncode %{
17
41
    self.p = p
18
42
    pass
19
43
 
20
 
  def getInputNumericalPointDimension(self) :
 
44
  def getInputDimension(self) :
21
45
    return self.n
22
46
 
23
 
  def getOutputNumericalPointDimension(self) :
 
47
  def getOutputDimension(self) :
24
48
    return self.p
25
49
 
26
50
  def __call__(self, X) :
 
51
    import types
27
52
    Y = None
28
 
    import types
29
 
    if ( type(X) not in (types.TupleType, types.ListType) ): 
 
53
    if ( type(X) not in (types.TupleType, types.ListType) ):
30
54
      raise TypeError("Expect sequence argument like a list or a tuple")
31
 
    if (len(X) != self.n): 
32
 
      raise TypeError("Expect sequence argument of length %d. Got %d" % (self.n, len(X)) )
33
 
 
34
 
    Y = self.f(X)
35
 
 
36
 
    if ( type(Y) not in (types.TupleType, types.ListType) ): 
37
 
      raise TypeError("Expect sequence argument like a list or a tuple as f's return value. Check f method")
38
 
    if (len(Y) != self.p): 
39
 
      raise TypeError("Expect sequence argument of length %d. Got %d. Check f method" % (self.p, len(Y)) )
40
 
 
41
 
    return Y
 
55
    if ( len(X) == 0 ):
 
56
      raise TypeError("Expect sequence argument of length > 0")
 
57
    if ( type(X[0]) not in (types.TupleType, types.ListType) ):
 
58
      Y = self.f(X)
 
59
      if ( type(Y) not in (types.TupleType, types.ListType) ): 
 
60
        raise TypeError("Expect sequence argument like a list or a tuple as f's return value. Check f method")
 
61
      if (len(Y) != self.p): 
 
62
        raise TypeError("Expect sequence argument of length %d. Got %d. Check f method" % (self.p, len(Y)) )
 
63
      return Y
 
64
#    else:
 
65
#      Y = self.fsample(X)
 
66
#      if ( type(Y) not in (types.TupleType, types.ListType) ): 
 
67
#        raise TypeError("Expect sequence argument like a list or a tuple as f's return value. Check fsample method")
 
68
#      if (len(Y) != len(X)): 
 
69
#        raise TypeError("Expect sequence argument of length %d. Got %d. Check fsample method" % (len(X), len(Y)) )
 
70
#      for i in range(len(X)):
 
71
#        if ( len(Y[i]) != self.p ):
 
72
#          raise TypeError("Expect sequence argument of length %d at position %d. Got %d. Check fsample method" % (self.p, i, len(Y[i])) )
 
73
      return Y
42
74
 
43
75
  def f(self, X) :
44
76
    return X
45
77
 
 
78
#  def fsample(self, X) :
 
79
#    Y = list()
 
80
#    for i in range(len(X)):
 
81
#      Y.append(self.f(X[i]))
 
82
#    return Y
 
83
 
46
84
%}
47
85
 
48
86
%template(NumericalMathFunctionImplementationTypedInterfaceObject)           OpenTURNS::Base::Common::TypedInterfaceObject<OpenTURNS::Base::Func::NumericalMathFunctionImplementation>;
56
94
 
57
95
NumericalMathFunction(PyObject * pyObj)
58
96
{
59
 
 if (!PyCallable_Check( pyObj )) {
60
 
   throw OT::Base::Common::InvalidArgumentException(HERE) << "Argument is not a callable object (function or class)";
61
 
 }
62
 
 
63
 
 return new OpenTURNS::Base::Func::NumericalMathFunction(new OpenTURNS::Base::Func::NumericalMathFunctionImplementation(new OpenTURNS::Base::Func::PythonNumericalMathEvaluationImplementation(pyObj) ) );
64
 
}
65
 
 
 
97
 return new OpenTURNS::Base::Func::NumericalMathFunction( OpenTURNS::convert<OpenTURNS::_PyObject_,OpenTURNS::Base::Func::NumericalMathFunction>(pyObj) );
 
98
}
 
99
 
 
100
OpenTURNS::Base::Type::NumericalPoint operator() (PyObject * pyObj) {
 
101
  return self->operator()( OpenTURNS::convert<OpenTURNS::_PySequence_, OpenTURNS::Base::Type::NumericalPoint>( pyObj ) );
 
102
}
66
103
}
67
104
 
68
105
}}}