2 from eigen_ref
import (
5 copyRowVectorFromConstRef,
6 copyVectorFromConstRef,
18 print(
"print matrix:")
20 print(
"calling fill():")
22 assert np.array_equal(mat, np.full(mat.shape, 1.0))
26 fill(mat[:3, :2], 1.0)
28 assert np.array_equal(mat[:3, :2], np.ones((3, 2)))
34 print(
"[asRef(int, int)]")
38 print(
"make second reference:")
42 assert np.array_equal(A_ref, A_ref2)
45 assert np.array_equal(A_ref, A_ref2)
49 data = np.array([[0, 0.2, 0.3, 0.4], [0, 1, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]])
51 data_strided = data[:, 0]
54 assert np.all(data_strided == data_strided_copy)
56 data_strided_copy = copyRowVectorFromConstRef(data_strided)
57 assert np.all(data_strided == data_strided_copy)
63 assert np.array_equal(ref, mat), f
"ref=\n{ref}\nmat=\n{mat}"
64 assert not (ref.flags.owndata)
65 assert ref.flags.writeable
71 assert np.array_equal(const_ref, mat), f
"ref=\n{const_ref}\nmat=\n{mat}"
72 assert not (const_ref.flags.writeable)
73 assert not (const_ref.flags.owndata)
77 print(
"set mat data to arange()")
79 mat[:, :] = np.arange(rows * cols).reshape(rows, cols)
81 for i, rowsize, colsize
in ([0, 3, 2], [1, 1, 2], [0, 3, 1]):
82 print(f
"taking block [{i}:{rowsize + i}, {0}:{colsize}]")
83 B =
getBlock(mat, i, 0, rowsize, colsize)
84 B = B.reshape(rowsize, colsize)
85 lhs = mat[i : rowsize + i, :colsize]
86 assert np.array_equal(lhs, B), f
"got lhs\n{lhs}\nrhs B=\n{B}"
89 rhs = np.ones((rowsize, colsize))
90 assert np.array_equal(mat[i : rowsize + i, :colsize], rhs)
98 mat_copy[:3, :2] = np.arange(6).reshape(3, 2)
100 assert np.array_equal(mat, mat_copy)
102 class ModifyBlockImpl(modify_block):
105 mat[:, :] = np.arange(n * m).reshape(n, m)
107 modify = ModifyBlockImpl()
109 Jref = np.zeros((10, 10))
110 Jref[:2, :3] = np.arange(6).reshape(2, 3)
112 assert np.array_equal(Jref, modify.J)
114 hasref = has_ref_member()
115 A = np.ones((3, 3)) / 2
116 hasref.Jref[:, :] = A
117 J_true = np.zeros((4, 4))
120 assert np.array_equal(hasref.J, J_true)
133 if __name__ ==
"__main__":
137 mat = np.ones((rows, cols), order=
"F")