File: t_ConstantFunction_std.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (35 lines) | stat: -rwxr-xr-x 713 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
27
28
29
30
31
32
33
34
35
#! /usr/bin/env python

import openturns as ot
import openturns.experimental as otexp
import openturns.testing as ott

ot.TESTPREAMBLE()

inputDimension = 2
constant = [1, 2, 3]

f = otexp.ConstantFunction(inputDimension, constant)

print(f)
print(repr(f))

assert f.getInputDimension() == inputDimension
assert f.getOutputDimension() == len(constant)
assert f == f

x = [5, 6]
y = f(x)
print(y)
ott.assert_almost_equal(y, constant)

dx = f.gradient(x)
ott.assert_almost_equal(dx, ot.Matrix(inputDimension, len(constant)))

dx2 = f.hessian(x)
ott.assert_almost_equal(dx2, ot.SymmetricTensor(inputDimension, len(constant)))

f02 = f.getMarginal([0, 2])
print(f02)
y02 = f02(x)
ott.assert_almost_equal(y02, [1, 3])