File: t_IndicesCollection_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 (57 lines) | stat: -rwxr-xr-x 1,057 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python

import openturns as ot

# Default constructor
flat1 = ot.IndicesCollection()
print("flat1=", flat1)

# Constructor with Collection<Indices>
coll2 = []
ind1 = ot.Indices(1)
ind4 = ot.Indices(4)
ind4.fill(8)
ind3 = ot.Indices(3)
ind3.fill(3)
coll2.append(ind1)
coll2.append(ind4)
coll2.append(ind3)
flat2 = ot.IndicesCollection(coll2)
print("flat2=", flat2)

# Copy constructor
flat3 = ot.IndicesCollection(flat2)
print("flat3=", flat3)

# Strided
coll4 = []
coll4.append(ind4)
coll4.append(ind4)
coll4.append(ind4)
strided1 = ot.IndicesCollection(coll4)
print("strided1=", strided1)

# Constructor with dimensions and values
full = ot.Indices(16)
full.fill()
strided2 = ot.IndicesCollection(8, 2, full)
print("strided2=", strided2)

# slicing
print("strided2[2] = ", strided2[2])
strided2[2] = [1, 3]
print("strided2 = ", strided2)
try:
    strided2[2] = [1, 2, 3]
    print("Should throw")
except TypeError:
    pass

# loop
for x in strided2:
    print(x)

try:
    ot.IndicesCollection([["zou"]])
except Exception:
    print("ok")