Michele De Stefano's C++ Utilities
matrix_usage.pycmd
1 // matrix_usage.pycmd
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 
8 /**
9  * \example matrix_usage.pycmd
10  *
11  * Shows the usage of the matrix_usage extension from the Python prompt.
12  */
13 
14 matrix.hpp functionalities usage example from the Python prompt:
15 
16 >>> import matrix_usage as mu
17 >>> M = mu.create_npy_array()
18 >>> M
19 array([[ 1.1, 4.4],
20  [ 2.2, 5.5],
21  [ 3.3, 6.6]])
22 >>> M.flags
23  C_CONTIGUOUS : False
24  F_CONTIGUOUS : True
25  OWNDATA : True
26  WRITEABLE : True
27  ALIGNED : True
28  UPDATEIFCOPY : False
29 >>> A = mu.create_npy_array_cplx()
30 >>> A
31 array([[ 1.1+1.1j, 2.2+2.2j],
32  [ 3.3+3.3j, 4.4+4.4j],
33  [ 5.5+5.5j, 6.6+6.6j]])
34 >>> B = mu.create_npy_array_row()
35 >>> B
36 array([[ 1.1, 2.2],
37  [ 3.3, 4.4],
38  [ 5.5, 6.6]])
39 >>> B.flags
40  C_CONTIGUOUS : True
41  F_CONTIGUOUS : False
42  OWNDATA : True
43  WRITEABLE : True
44  ALIGNED : True
45  UPDATEIFCOPY : False
46 >>> S = mu.create_npy_array_short()
47 >>> S
48 array([[-1, 2],
49  [-3, 4],
50  [ 5, -6]], dtype=int16)
51 >>> mu.get_matrix(B)
52 Matrix got:
53 [3,2]((1.1,2.2),(3.3,4.4),(5.5,6.6))
54 >>> mu.get_matrix2(B)
55 Matrix got:
56 [3,2]((1.1,2.2),(3.3,4.4),(5.5,6.6))
57 >>> mu.get_matrix2(M)
58 Matrix got:
59 [3,2]((1.1,4.4),(2.2,5.5),(3.3,6.6))
60 >>> mu.get_matrix(A)
61 matrix_usage.py:105: ComplexWarning: Casting complex values to real discards the imaginary part
62  return _matrix_usage.get_matrix(*args)
63 Matrix got:
64 [3,2]((1.1,2.2),(3.3,4.4),(5.5,6.6))
65 >>> mu.get_matrix3(A)
66 Matrix got:
67 [3,2](((1.1,0),(2.2,0)),((3.3,0),(4.4,0)),((5.5,0),(6.6,0)))
68 >>> A
69 array([[ 1.1+0.j, 2.2+0.j],
70  [ 3.3+0.j, 4.4+0.j],
71  [ 5.5+0.j, 6.6+0.j]])
72 >>> A = mu.create_npy_array_cplx()
73 >>> A
74 array([[ 1.1+1.1j, 2.2+2.2j],
75  [ 3.3+3.3j, 4.4+4.4j],
76  [ 5.5+5.5j, 6.6+6.6j]])
77 >>> mu.get_matrix3(A)
78 Matrix got:
79 [3,2](((1.1,1.1),(2.2,2.2)),((3.3,3.3),(4.4,4.4)),((5.5,5.5),(6.6,6.6)))
80 >>> mu.get_matrix4(B)
81 Matrix got:
82 [3,2]((,),(,),(,))
83 // The previous command tested the get function, with type cast to char
84 >>> C = mu.create_ublas_matrix_column_major()
85 >>> C
86 <Swig Object of type 'boost::numeric::ublas::matrix< double,boost::numeric::ublas::column_major > *' at 0x28e2180>
87 >>> mu.get_matrix_no_conversion(C)
88 Matrix got:
89 [3,2]((1.1,4.4),(2.2,5.5),(3.3,6.6))
90 >>> mu.destroy_ublas_matrix_column_major(C)