2 from pybind11_tests
import ConstructorStats
4 pytestmark = pytest.requires_eigen_and_numpy
6 with pytest.suppress(ImportError):
7 from pybind11_tests
import eigen
as m
10 ref = np.array([[ 0., 3, 0, 0, 0, 11],
11 [22, 0, 0, 0, 17, 11],
14 [ 0, 0, 14, 0, 8, 11]])
18 np.testing.assert_array_equal(mat, ref)
44 ref2 = np.array([[0., 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]])
45 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2), ref2)
46 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2), ref2)
47 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, 1]), ref2[:, [1]])
48 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[0, :]), ref2[[0], :])
49 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)])
50 np.testing.assert_array_equal(
51 m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :])
53 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2), ref2)
54 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2), ref2)
55 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, 1]), ref2[:, [1]])
56 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[0, :]), ref2[[0], :])
57 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)])
58 np.testing.assert_array_equal(
59 m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :])
62 functions = [m.partial_copy_four_rm_r, m.partial_copy_four_rm_c,
63 m.partial_copy_four_cm_r, m.partial_copy_four_cm_c]
64 matrix_with_wrong_shape = [[1, 2],
67 with pytest.raises(TypeError)
as excinfo:
68 f(matrix_with_wrong_shape)
69 assert "incompatible function arguments" in str(excinfo.value)
73 zr = np.arange(30, dtype=
'float32').reshape(5, 6)
74 zc = zr.reshape(6, 5).transpose()
80 with pytest.raises(TypeError)
as excinfo:
82 assert (
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.c_contiguous]) -> None' 83 in str(excinfo.value))
84 with pytest.raises(TypeError)
as excinfo:
86 assert (
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.f_contiguous]) -> None' 87 in str(excinfo.value))
88 with pytest.raises(TypeError)
as excinfo:
89 m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype=
'float32'))
90 assert (
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable]) -> None' 91 in str(excinfo.value))
92 zr.flags.writeable =
False 93 with pytest.raises(TypeError):
95 with pytest.raises(TypeError):
100 assert m.cpp_copy(m.fixed_r()) == 22.
101 assert m.cpp_copy(m.fixed_c()) == 22.
102 z = np.array([[5., 6], [7, 8]])
103 assert m.cpp_copy(z) == 7.
104 assert m.cpp_copy(m.get_cm_ref()) == 21.
105 assert m.cpp_copy(m.get_rm_ref()) == 21.
106 assert m.cpp_ref_c(m.get_cm_ref()) == 21.
107 assert m.cpp_ref_r(m.get_rm_ref()) == 21.
108 with pytest.raises(RuntimeError)
as excinfo:
110 m.cpp_ref_any(m.fixed_c())
111 assert 'Unable to cast Python instance' in str(excinfo.value)
112 with pytest.raises(RuntimeError)
as excinfo:
114 m.cpp_ref_any(m.fixed_r())
115 assert 'Unable to cast Python instance' in str(excinfo.value)
116 assert m.cpp_ref_any(m.ReturnTester.create()) == 1.
118 assert m.cpp_ref_any(m.get_cm_ref()) == 21.
119 assert m.cpp_ref_any(m.get_cm_ref()) == 21.
123 z = np.full((5, 6), 42.0)
124 z.flags.writeable =
False 125 np.testing.assert_array_equal(z, m.fixed_copy_r(z))
126 np.testing.assert_array_equal(m.fixed_r_const(), m.fixed_r())
127 assert not m.fixed_r_const().flags.writeable
128 np.testing.assert_array_equal(m.fixed_copy_r(m.fixed_r_const()), m.fixed_r_const())
132 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
133 second_row = counting_mat[1, :]
134 second_col = counting_mat[:, 1]
135 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
136 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
137 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
138 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
139 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
140 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
142 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
143 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
144 for slice_idx, ref_mat
in enumerate(slices):
145 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
146 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
149 m.double_threer(second_row)
150 m.double_threec(second_col)
151 np.testing.assert_array_equal(counting_mat, [[0., 2, 2], [6, 16, 10], [6, 14, 8]])
155 """Eigen doesn't support (as of yet) negative strides. When a function takes an Eigen matrix by 156 copy or const reference, we can pass a numpy array that has negative strides. Otherwise, an 157 exception will be thrown as Eigen will not be able to map the numpy array.""" 159 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
160 counting_mat = counting_mat[::-1, ::-1]
161 second_row = counting_mat[1, :]
162 second_col = counting_mat[:, 1]
163 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
164 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
165 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
166 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
167 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
168 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
170 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
171 counting_3d = counting_3d[::-1, ::-1, ::-1]
172 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
173 for slice_idx, ref_mat
in enumerate(slices):
174 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
175 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
178 with pytest.raises(TypeError)
as excinfo:
179 m.double_threer(second_row)
180 assert msg(excinfo.value) ==
""" 181 double_threer(): incompatible function arguments. The following argument types are supported: 182 1. (arg0: numpy.ndarray[float32[1, 3], flags.writeable]) -> None 184 Invoked with: """ +
repr(np.array([ 5., 4., 3.], dtype=
'float32'))
186 with pytest.raises(TypeError)
as excinfo:
187 m.double_threec(second_col)
188 assert msg(excinfo.value) ==
""" 189 double_threec(): incompatible function arguments. The following argument types are supported: 190 1. (arg0: numpy.ndarray[float32[3, 1], flags.writeable]) -> None 192 Invoked with: """ +
repr(np.array([ 7., 4., 1.], dtype=
'float32'))
196 assert np.all(m.diagonal(ref) == ref.diagonal())
197 assert np.all(m.diagonal_1(ref) == ref.diagonal(1))
198 for i
in range(-5, 7):
199 assert np.all(m.diagonal_n(ref, i) == ref.diagonal(i)),
"m.diagonal_n({})".
format(i)
201 assert np.all(m.block(ref, 2, 1, 3, 3) == ref[2:5, 1:4])
202 assert np.all(m.block(ref, 1, 4, 4, 2) == ref[1:, 4:])
203 assert np.all(m.block(ref, 1, 4, 3, 2) == ref[1:4, 4:])
207 chols = [m.cholesky1, m.cholesky2, m.cholesky3, m.cholesky4]
208 for i, chol
in enumerate(chols, start=1):
209 mymat = chol(np.array([[1., 2, 4], [2, 13, 23], [4, 23, 77]]))
210 assert np.all(mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])),
"cholesky{}".
format(i)
219 z = np.array(a, copy=
True)
225 """Tests various ways of returning references and non-referencing copies""" 227 master = np.ones((10, 10))
230 assert not a_get1.flags.owndata
and a_get1.flags.writeable
233 assert not a_get2.flags.owndata
and a_get2.flags.writeable
237 assert not a_view1.flags.owndata
and not a_view1.flags.writeable
238 with pytest.raises(ValueError):
240 a_view2 = a.view_ptr()
241 assert not a_view2.flags.owndata
and not a_view2.flags.writeable
242 with pytest.raises(ValueError):
245 a_copy1 = a.copy_get()
246 assert a_copy1.flags.owndata
and a_copy1.flags.writeable
247 np.testing.assert_array_equal(a_copy1, master)
250 a_copy2 = a.copy_view()
251 assert a_copy2.flags.owndata
and a_copy2.flags.writeable
252 np.testing.assert_array_equal(a_copy2, master)
257 assert not a_ref1.flags.owndata
and a_ref1.flags.writeable
259 a_ref2 = a.ref_const()
260 assert not a_ref2.flags.owndata
and not a_ref2.flags.writeable
261 with pytest.raises(ValueError):
263 a_ref3 = a.ref_safe()
264 assert not a_ref3.flags.owndata
and a_ref3.flags.writeable
266 a_ref4 = a.ref_const_safe()
267 assert not a_ref4.flags.owndata
and not a_ref4.flags.writeable
268 with pytest.raises(ValueError):
269 a_ref4[7, 0] = 987654321
271 a_copy3 = a.copy_ref()
272 assert a_copy3.flags.owndata
and a_copy3.flags.writeable
273 np.testing.assert_array_equal(a_copy3, master)
276 a_copy4 = a.copy_ref_const()
277 assert a_copy4.flags.owndata
and a_copy4.flags.writeable
278 np.testing.assert_array_equal(a_copy4, master)
282 a_block1 = a.block(3, 3, 2, 2)
283 assert not a_block1.flags.owndata
and a_block1.flags.writeable
286 a_block2 = a.block_safe(2, 2, 3, 2)
287 assert not a_block2.flags.owndata
and a_block2.flags.writeable
288 a_block2[2, 1] = -123
290 a_block3 = a.block_const(6, 7, 4, 3)
291 assert not a_block3.flags.owndata
and not a_block3.flags.writeable
292 with pytest.raises(ValueError):
293 a_block3[2, 2] = -44444
295 a_copy5 = a.copy_block(2, 2, 2, 3)
296 assert a_copy5.flags.owndata
and a_copy5.flags.writeable
297 np.testing.assert_array_equal(a_copy5, master[2:4, 2:5])
301 a_corn1 = a.corners()
302 assert not a_corn1.flags.owndata
and a_corn1.flags.writeable
309 a_corn2 = a.corners_const()
310 assert not a_corn2.flags.owndata
and not a_corn2.flags.writeable
311 with pytest.raises(ValueError):
316 np.testing.assert_array_equal(a_get1, master)
317 np.testing.assert_array_equal(a_get2, master)
318 np.testing.assert_array_equal(a_view1, master)
319 np.testing.assert_array_equal(a_view2, master)
320 np.testing.assert_array_equal(a_ref1, master)
321 np.testing.assert_array_equal(a_ref2, master)
322 np.testing.assert_array_equal(a_ref3, master)
323 np.testing.assert_array_equal(a_ref4, master)
324 np.testing.assert_array_equal(a_block1, master[3:5, 3:5])
325 np.testing.assert_array_equal(a_block2, master[2:5, 2:4])
326 np.testing.assert_array_equal(a_block3, master[6:10, 7:10])
327 np.testing.assert_array_equal(a_corn1, master[0::master.shape[0] - 1, 0::master.shape[1] - 1])
328 np.testing.assert_array_equal(a_corn2, master[0::master.shape[0] - 1, 0::master.shape[1] - 1])
330 np.testing.assert_array_equal(a_copy1, c1want)
331 np.testing.assert_array_equal(a_copy2, c2want)
332 np.testing.assert_array_equal(a_copy3, c3want)
333 np.testing.assert_array_equal(a_copy4, c4want)
334 np.testing.assert_array_equal(a_copy5, c5want)
339 start_with = cstats.alive()
341 assert cstats.alive() == start_with + 1
343 assert cstats.alive() == start_with + 1
346 assert cstats.alive() == start_with + 1
349 assert cstats.alive() == start_with
355 assert cstats.alive() == 1
356 unsafe = [a.ref(), a.ref_const(), a.block(1, 2, 3, 4)]
357 copies = [a.copy_get(), a.copy_view(), a.copy_ref(), a.copy_ref_const(),
358 a.copy_block(4, 3, 2, 1)]
360 assert cstats.alive() == 0
364 for meth
in [m.ReturnTester.get, m.ReturnTester.get_ptr, m.ReturnTester.view,
365 m.ReturnTester.view_ptr, m.ReturnTester.ref_safe, m.ReturnTester.ref_const_safe,
366 m.ReturnTester.corners, m.ReturnTester.corners_const]:
369 for meth
in [m.ReturnTester.block_safe, m.ReturnTester.block_const]:
374 """Tests Eigen's ability to mutate numpy values""" 376 orig = np.array([[1., 2, 3], [4, 5, 6], [7, 8, 9]])
378 zc = np.array(orig, order=
'F')
379 m.add_rm(zr, 1, 0, 100)
380 assert np.all(zr == np.array([[1., 2, 3], [104, 5, 6], [7, 8, 9]]))
381 m.add_cm(zc, 1, 0, 200)
382 assert np.all(zc == np.array([[1., 2, 3], [204, 5, 6], [7, 8, 9]]))
384 m.add_any(zr, 1, 0, 20)
385 assert np.all(zr == np.array([[1., 2, 3], [124, 5, 6], [7, 8, 9]]))
386 m.add_any(zc, 1, 0, 10)
387 assert np.all(zc == np.array([[1., 2, 3], [214, 5, 6], [7, 8, 9]]))
390 with pytest.raises(TypeError):
391 m.add_rm(zc, 1, 0, 1)
392 with pytest.raises(TypeError):
393 m.add_cm(zr, 1, 0, 1)
396 m.add1(zr, 1, 0, -100)
397 m.add2(zr, 1, 0, -20)
398 assert np.all(zr == orig)
399 m.add1(zc, 1, 0, -200)
400 m.add2(zc, 1, 0, -10)
401 assert np.all(zc == orig)
405 cornersr = zr[0::2, 0::2]
406 cornersc = zc[0::2, 0::2]
408 assert np.all(cornersr == np.array([[1., 3], [7, 9]]))
409 assert np.all(cornersc == np.array([[1., 3], [7, 9]]))
411 with pytest.raises(TypeError):
412 m.add_rm(cornersr, 0, 1, 25)
413 with pytest.raises(TypeError):
414 m.add_cm(cornersr, 0, 1, 25)
415 with pytest.raises(TypeError):
416 m.add_rm(cornersc, 0, 1, 25)
417 with pytest.raises(TypeError):
418 m.add_cm(cornersc, 0, 1, 25)
419 m.add_any(cornersr, 0, 1, 25)
420 m.add_any(cornersc, 0, 1, 44)
421 assert np.all(zr == np.array([[1., 2, 28], [4, 5, 6], [7, 8, 9]]))
422 assert np.all(zc == np.array([[1., 2, 47], [4, 5, 6], [7, 8, 9]]))
426 zro.flags.writeable =
False 427 with pytest.raises(TypeError):
428 m.add_rm(zro, 0, 0, 0)
429 with pytest.raises(TypeError):
430 m.add_any(zro, 0, 0, 0)
431 with pytest.raises(TypeError):
433 with pytest.raises(TypeError):
437 zi = np.array([[1, 2], [3, 4]])
438 with pytest.raises(TypeError):
443 """Tests numpy mutating Eigen matrices (for returned Eigen::Ref<...>s)""" 448 zcro = m.get_cm_const_ref()
450 zrro = m.get_rm_const_ref()
452 assert [zc[1, 2], zcro[1, 2], zr[1, 2], zrro[1, 2]] == [23] * 4
454 assert not zc.flags.owndata
and zc.flags.writeable
455 assert not zr.flags.owndata
and zr.flags.writeable
456 assert not zcro.flags.owndata
and not zcro.flags.writeable
457 assert not zrro.flags.owndata
and not zrro.flags.writeable
460 expect = np.array([[11., 12, 13], [21, 22, 99], [31, 32, 33]])
462 assert np.all(zc == expect)
463 assert np.all(zcro == expect)
464 assert np.all(m.get_cm_ref() == expect)
467 assert np.all(zr == expect)
468 assert np.all(zrro == expect)
469 assert np.all(m.get_rm_ref() == expect)
472 with pytest.raises(ValueError):
474 with pytest.raises(ValueError):
479 y1 = np.array(m.get_cm_const_ref())
481 assert y1.flags.owndata
and y1.flags.writeable
483 assert y1[1, 2] == 99
485 assert y1[1, 2] == 111
486 assert zc[1, 2] == 99
490 """Tests a complex chain of nested eigen/numpy references""" 496 z2 = m.incr_matrix(z, 1)
498 z3 = m.incr_matrix(z, 2)
500 z4 = m.incr_matrix(z, 3)
502 z5 = m.incr_matrix(z, 4)
504 assert np.all(z == z2)
505 assert np.all(z == z3)
506 assert np.all(z == z4)
507 assert np.all(z == z5)
508 expect = np.array([[0., 22, 20], [31, 37, 33], [41, 42, 38]])
509 assert np.all(z == expect)
511 y = np.array(
range(100), dtype=
'float64').reshape(10, 10)
512 y2 = m.incr_matrix_any(y, 10)
513 y3 = m.incr_matrix_any(y2[0::2, 0::2], -33)
516 y6 = m.incr_matrix_any(y5, 1000)
519 yexpect = np.array(
range(100), dtype=
'float64').reshape(10, 10)
521 yexpect[0::2, 0::2] -= 33
522 yexpect[0::4, 0::4] += 1000
523 assert np.all(y6 == yexpect[0::4, 0::4])
524 assert np.all(y5 == yexpect[0::4, 0::4])
525 assert np.all(y4 == yexpect[0::4, 0::2])
526 assert np.all(y3 == yexpect[0::2, 0::2])
527 assert np.all(y2 == yexpect)
528 assert np.all(y == yexpect)
534 int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order=
'F')
535 dbl_matrix_colmajor = np.array(int_matrix_colmajor, dtype=
'double', order=
'F', copy=
True)
536 int_matrix_rowmajor = np.array(int_matrix_colmajor, order=
'C', copy=
True)
537 dbl_matrix_rowmajor = np.array(int_matrix_rowmajor, dtype=
'double', order=
'C', copy=
True)
540 assert m.get_elem(int_matrix_colmajor) == 8
541 assert m.get_elem(dbl_matrix_colmajor) == 8
542 assert m.get_elem(int_matrix_rowmajor) == 8
543 assert m.get_elem(dbl_matrix_rowmajor) == 8
546 with pytest.raises(TypeError)
as excinfo:
547 m.get_elem_nocopy(int_matrix_colmajor)
548 assert (
'get_elem_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 549 ', flags.f_contiguous' in str(excinfo.value))
550 assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
551 with pytest.raises(TypeError)
as excinfo:
552 m.get_elem_nocopy(int_matrix_rowmajor)
553 assert (
'get_elem_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 554 ', flags.f_contiguous' in str(excinfo.value))
555 with pytest.raises(TypeError)
as excinfo:
556 m.get_elem_nocopy(dbl_matrix_rowmajor)
557 assert (
'get_elem_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 558 ', flags.f_contiguous' in str(excinfo.value))
561 with pytest.raises(TypeError)
as excinfo:
562 m.get_elem_rm_nocopy(int_matrix_colmajor)
563 assert (
'get_elem_rm_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 564 ', flags.c_contiguous' in str(excinfo.value))
565 with pytest.raises(TypeError)
as excinfo:
566 m.get_elem_rm_nocopy(dbl_matrix_colmajor)
567 assert (
'get_elem_rm_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 568 ', flags.c_contiguous' in str(excinfo.value))
569 assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
570 with pytest.raises(TypeError)
as excinfo:
571 m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
572 assert (
'get_elem_rm_nocopy(): incompatible function arguments.' in str(excinfo.value)
and 573 ', flags.c_contiguous' in str(excinfo.value))
577 """Ensure the lifetime of temporary arrays created by the `Ref` caster 579 The `Ref` caster sometimes creates a copy which needs to stay alive. This needs to 580 happen both for directs casts (just the array) or indirectly (e.g. list of arrays). 583 a = np.full(shape=10, fill_value=8, dtype=np.int8)
584 assert m.get_elem_direct(a) == 8
587 assert m.get_elem_indirect(list_of_a) == 8
591 assert np.all(m.incr_diag(7) == np.diag([1., 2, 3, 4, 5, 6, 7]))
593 asymm = np.array([[ 1., 2, 3, 4],
597 symm_lower = np.array(asymm)
598 symm_upper = np.array(asymm)
600 for j
in range(i + 1, 4):
601 symm_lower[i, j] = symm_lower[j, i]
602 symm_upper[j, i] = symm_upper[i, j]
604 assert np.all(m.symmetric_lower(asymm) == symm_lower)
605 assert np.all(m.symmetric_upper(asymm) == symm_upper)
609 assert doc(m.double_col) ==
""" 610 double_col(arg0: numpy.ndarray[float32[m, 1]]) -> numpy.ndarray[float32[m, 1]] 612 assert doc(m.double_row) ==
""" 613 double_row(arg0: numpy.ndarray[float32[1, n]]) -> numpy.ndarray[float32[1, n]] 615 assert doc(m.double_complex) ==
""" 616 double_complex(arg0: numpy.ndarray[complex64[m, 1]]) -> numpy.ndarray[complex64[m, 1]] 618 assert doc(m.double_mat_rm) ==
""" 619 double_mat_rm(arg0: numpy.ndarray[float32[m, n]]) -> numpy.ndarray[float32[m, n]] 624 a = np.array([[1.0, 2], [3, 4], [5, 6]])
627 assert np.all(m.matrix_multiply(a, b) == np.array([[3.], [7], [11]]))
628 assert np.all(m.matrix_multiply(A=a, B=b) == np.array([[3.], [7], [11]]))
629 assert np.all(m.matrix_multiply(B=b, A=a) == np.array([[3.], [7], [11]]))
631 with pytest.raises(ValueError)
as excinfo:
632 m.matrix_multiply(b, a)
633 assert str(excinfo.value) ==
'Nonconformable matrices!' 635 with pytest.raises(ValueError)
as excinfo:
636 m.matrix_multiply(A=b, B=a)
637 assert str(excinfo.value) ==
'Nonconformable matrices!' 639 with pytest.raises(ValueError)
as excinfo:
640 m.matrix_multiply(B=a, A=b)
641 assert str(excinfo.value) ==
'Nonconformable matrices!' 644 @pytest.requires_eigen_and_scipy
654 @pytest.requires_eigen_and_scipy
656 assert doc(m.sparse_copy_r) ==
""" 657 sparse_copy_r(arg0: scipy.sparse.csr_matrix[float32]) -> scipy.sparse.csr_matrix[float32] 659 assert doc(m.sparse_copy_c) ==
""" 660 sparse_copy_c(arg0: scipy.sparse.csc_matrix[float32]) -> scipy.sparse.csc_matrix[float32] 665 """Ignore strides on a length-1 dimension (even if they would be incompatible length > 1)""" 666 assert np.all(m.iss738_f1(np.array([[1., 2, 3]])) == np.array([[1., 102, 203]]))
667 assert np.all(m.iss738_f1(np.array([[1.], [2], [3]])) == np.array([[1.], [12], [23]]))
669 assert np.all(m.iss738_f2(np.array([[1., 2, 3]])) == np.array([[1., 102, 203]]))
670 assert np.all(m.iss738_f2(np.array([[1.], [2], [3]])) == np.array([[1.], [12], [23]]))
674 """Issue 1105: 1xN or Nx1 input arrays weren't accepted for eigen 675 compile-time row vectors or column vector""" 676 assert m.iss1105_row(np.ones((1, 7)))
677 assert m.iss1105_col(np.ones((7, 1)))
680 with pytest.raises(TypeError)
as excinfo:
681 m.iss1105_row(np.ones((7, 1)))
682 assert "incompatible function arguments" in str(excinfo.value)
683 with pytest.raises(TypeError)
as excinfo:
684 m.iss1105_col(np.ones((1, 7)))
685 assert "incompatible function arguments" in str(excinfo.value)
689 """Using Eigen types as member variables requires a class-specific 690 operator new with proper alignment""" 692 o = m.CustomOperatorNew()
693 np.testing.assert_allclose(o.a, 0.0)
694 np.testing.assert_allclose(o.b.diagonal(), 1.0)
def test_dense_signature(doc)
def test_mutator_descriptors()
def test_eigen_ref_to_python()
def test_eigen_return_references()
static ConstructorStats & get(std::type_index type)
def test_negative_stride_from_python(msg)
def test_sparse_signature(doc)
def assert_keeps_alive(cl, method, args)
def test_eigen_ref_mutators()
def test_nonunit_stride_to_python()
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > &>(), fmt, tp), std::basic_string< CharT >
def test_named_arguments()
def test_eigen_ref_life_support()
def test_special_matrix_objects()
def test_eigen_keepalive()
def test_custom_operator_new()
def array_copy_but_one(a, r, c, v)
def test_partially_fixed()
def assert_sparse_equal_ref(sparse_mat)
def test_pass_readonly_array()
def assign_both(a1, a2, r, c, v)
def assert_equal_ref(mat)
def test_both_ref_mutators()
def test_nocopy_wrapper()
def test_numpy_ref_mutators()
def test_nonunit_stride_from_python()