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 74 75 76
|
#! /usr/bin/env python
import os
import openturns as ot
ot.TESTPREAMBLE()
class FUNC(ot.OpenTURNSPythonFunction):
def __init__(self):
ot.OpenTURNSPythonFunction.__init__(self, 2, 1)
self.setInputDescription(["R", "S"])
self.setOutputDescription(["T"])
def _exec(self, X):
return [X[0] + X[1]]
F = FUNC()
# Instance creation
f1 = ot.Function(F)
def mul(X):
return [X[0] * X[1] * X[2]]
f2 = ot.PythonFunction(3, 1, mul)
st = ot.Study()
fileName = "PyNMF.xml"
st.setStorageManager(ot.XMLStorageManager(fileName))
st.add("f1", f1)
st.add("f2", f2)
st.save()
print("saved f1=", f1)
print("saved f2=", f2)
f1 = ot.Function()
f2 = ot.Function()
st = ot.Study()
st.setStorageManager(ot.XMLStorageManager(fileName))
st.load()
st.fillObject("f1", f1)
st.fillObject("f2", f2)
print("loaded f1=", f1)
print("loaded f2=", f2)
inPt = ot.Point(2, 2.0)
outPt = f1(inPt)
print(repr(outPt))
outPt = f1((10.0, 11.0))
print(repr(outPt))
inSample = ot.Sample(10, 2)
for i in range(10):
inSample[i] = ot.Point((i, i))
print(repr(inSample))
outSample = f1(inSample)
print(repr(outSample))
outSample = f1(((100.0, 100.0), (101.0, 101.0), (102.0, 102.0)))
print(repr(outSample))
os.remove(fileName)
|