example-buffers.py 1.08 KB
Newer Older
1
2
#!/usr/bin/env python
from __future__ import print_function
Wenzel Jakob's avatar
Wenzel Jakob committed
3
4
5
6
import sys
sys.path.append('.')

from example import Matrix
Wenzel Jakob's avatar
Wenzel Jakob committed
7
8
9
10

try:
    import numpy as np
except ImportError:
11
12
    # NumPy missing: skip test
    exit(99)
Wenzel Jakob's avatar
Wenzel Jakob committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

m = Matrix(5, 5)

print(m[2, 3])
m[2, 3] = 4
print(m[2, 3])

m2 = np.array(m, copy=False)
print(m2)
print(m2[2, 3])
m2[2, 3] = 5
print(m[2, 3])

m3 = np.array([[1,2,3],[4,5,6]]).astype(np.float32)
print(m3)
m4 = Matrix(m3)
for i in range(m4.rows()):
    for j in range(m4.cols()):
        print(m4[i, j], end = ' ')
    print()
33
34
35
36
37
38
39
40
41
42
43
44
45

from example import ConstructorStats
cstats = ConstructorStats.get(Matrix)
print("Instances not destroyed:", cstats.alive())
m = m4 = None
print("Instances not destroyed:", cstats.alive())
m2 = None # m2 holds an m reference
print("Instances not destroyed:", cstats.alive())
print("Constructor values:", cstats.values())
print("Copy constructions:", cstats.copy_constructions)
#print("Move constructions:", cstats.move_constructions >= 0) # Don't invoke any
print("Copy assignments:", cstats.copy_assignments)
print("Move assignments:", cstats.move_assignments)