File: t_Object_pickle.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (25 lines) | stat: -rwxr-xr-x 666 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
#! /usr/bin/env python

import openturns as ot
import pickle
from io import BytesIO

obj_list = []
obj_list.append(ot.NumericalPoint([1.6, -8.7]))
obj_list.append(ot.NumericalSample([[4.6, -3.7], [8.4, 6.3]]))
obj_list.append(ot.Description(['x', 'y', 'z']))
obj_list.append(ot.Indices([1, 2, 4]))
obj_list.append(ot.Matrix([[1, 2], [3, 4]]))
obj_list.append(ot.NumericalMathFunction(['x1', 'x2'], ['y1'], ['y1=x1+x2']))

src = BytesIO()

for i in range(len(obj_list)):
    pickle.dump(obj_list[i], src)

src.seek(0)

for i in range(len(obj_list)):
    obj = pickle.load(src)
    print(('object: ' + str(obj)))
    print(('same: ' + str(obj_list[i] == obj) + '\n'))