Wenzel Jakob | 5708221 | 2015-09-04 23:42:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | from __future__ import print_function |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 3 | import sys |
| 4 | sys.path.append('.') |
| 5 | |
| 6 | from example import Matrix |
Wenzel Jakob | fab881c | 2015-10-18 17:04:24 +0200 | [diff] [blame] | 7 | |
| 8 | try: |
| 9 | import numpy as np |
| 10 | except ImportError: |
Jason Rhinelander | 7de9f6c | 2016-07-08 17:44:12 -0400 | [diff] [blame] | 11 | # NumPy missing: skip test |
| 12 | exit(99) |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 13 | |
| 14 | m = Matrix(5, 5) |
| 15 | |
| 16 | print(m[2, 3]) |
| 17 | m[2, 3] = 4 |
| 18 | print(m[2, 3]) |
| 19 | |
| 20 | m2 = np.array(m, copy=False) |
| 21 | print(m2) |
| 22 | print(m2[2, 3]) |
| 23 | m2[2, 3] = 5 |
| 24 | print(m[2, 3]) |
| 25 | |
| 26 | m3 = np.array([[1,2,3],[4,5,6]]).astype(np.float32) |
| 27 | print(m3) |
| 28 | m4 = Matrix(m3) |
| 29 | for i in range(m4.rows()): |
| 30 | for j in range(m4.cols()): |
| 31 | print(m4[i, j], end = ' ') |
| 32 | print() |
Jason Rhinelander | 3f58937 | 2016-08-07 13:05:26 -0400 | [diff] [blame] | 33 | |
| 34 | from example import ConstructorStats |
| 35 | cstats = ConstructorStats.get(Matrix) |
| 36 | print("Instances not destroyed:", cstats.alive()) |
| 37 | m = m4 = None |
| 38 | print("Instances not destroyed:", cstats.alive()) |
| 39 | m2 = None # m2 holds an m reference |
| 40 | print("Instances not destroyed:", cstats.alive()) |
| 41 | print("Constructor values:", cstats.values()) |
| 42 | print("Copy constructions:", cstats.copy_constructions) |
| 43 | #print("Move constructions:", cstats.move_constructions >= 0) # Don't invoke any |
| 44 | print("Copy assignments:", cstats.copy_assignments) |
| 45 | print("Move assignments:", cstats.move_assignments) |