File: t_FileMemoizeFunction_std.py

package info (click to toggle)
persalys 13.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 71,916 kB
  • sloc: xml: 496,859; cpp: 53,848; python: 3,435; sh: 332; makefile: 131; ansic: 14
file content (27 lines) | stat: -rwxr-xr-x 793 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
#! /usr/bin/env python

import openturns as ot
import persalys
import os

g = ot.SymbolicFunction(["x1", "x2"], ["x1+x2", "3*(x1+x2)", "x1*x2"])
f = persalys.FileMemoizeFunction(g, "in_fm.csv", "out_fm.csv")
for i in range(5):
    f([1, 2])
    f([10 + i, 20 + i])
print("f.in", f.getCacheInput())
print("f.out", f.getCacheOutput())
print("f.hits", f.getCacheHits())
print("f.calls", f.getCallsNumber())
g2 = ot.SymbolicFunction(["x1", "x2"], ["?"] * 3)
f2 = persalys.FileMemoizeFunction(g2, "in_fm.csv", "out_fm.csv")
for i in range(5):
    f2([1, 2])
    f2([10 + i, 20 + i])
print("f2.in", f2.getCacheInput())
print("f2.out", f2.getCacheOutput())
print("f2.hits", f2.getCacheHits())
print("f2.calls", f2.getCallsNumber())

os.remove(f.getCacheInputFile())
os.remove(f.getCacheOutputFile())