3from pybind11_tests
import ConstructorStats
5np = pytest.importorskip(
"numpy")
6m = pytest.importorskip(
"pybind11_tests.eigen_matrix")
11 [0.0, 3, 0, 0, 0, 11],
12 [22, 0, 0, 0, 17, 11],
21 np.testing.assert_array_equal(mat, ref)
47 ref2 = np.array([[0.0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]])
48 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2), ref2)
49 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2), ref2)
50 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, 1]), ref2[:, [1]])
51 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[0, :]), ref2[[0], :])
52 np.testing.assert_array_equal(
53 m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
55 np.testing.assert_array_equal(
56 m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
59 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2), ref2)
60 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2), ref2)
61 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, 1]), ref2[:, [1]])
62 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[0, :]), ref2[[0], :])
63 np.testing.assert_array_equal(
64 m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
66 np.testing.assert_array_equal(
67 m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
72 m.partial_copy_four_rm_r,
73 m.partial_copy_four_rm_c,
74 m.partial_copy_four_cm_r,
75 m.partial_copy_four_cm_c,
77 matrix_with_wrong_shape = [[1, 2], [3, 4]]
79 with pytest.raises(TypeError)
as excinfo:
80 f(matrix_with_wrong_shape)
81 assert "incompatible function arguments" in str(excinfo.value)
85 zr = np.arange(30, dtype=
"float32").reshape(5, 6)
86 zc = zr.reshape(6, 5).transpose()
92 with pytest.raises(TypeError)
as excinfo:
95 "(arg0: numpy.ndarray[numpy.float32[5, 6],"
96 " flags.writeable, flags.c_contiguous]) -> None" in str(excinfo.value)
98 with pytest.raises(TypeError)
as excinfo:
101 "(arg0: numpy.ndarray[numpy.float32[5, 6],"
102 " flags.writeable, flags.f_contiguous]) -> None" in str(excinfo.value)
104 with pytest.raises(TypeError)
as excinfo:
105 m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype=
"float32"))
106 assert "(arg0: numpy.ndarray[numpy.float32[5, 6], flags.writeable]) -> None" in str(
109 zr.flags.writeable =
False
110 with pytest.raises(TypeError):
111 m.fixed_mutator_r(zr)
112 with pytest.raises(TypeError):
113 m.fixed_mutator_a(zr)
117 assert m.cpp_copy(m.fixed_r()) == 22.0
118 assert m.cpp_copy(m.fixed_c()) == 22.0
119 z = np.array([[5.0, 6], [7, 8]])
120 assert m.cpp_copy(z) == 7.0
121 assert m.cpp_copy(m.get_cm_ref()) == 21.0
122 assert m.cpp_copy(m.get_rm_ref()) == 21.0
123 assert m.cpp_ref_c(m.get_cm_ref()) == 21.0
124 assert m.cpp_ref_r(m.get_rm_ref()) == 21.0
125 with pytest.raises(RuntimeError)
as excinfo:
127 m.cpp_ref_any(m.fixed_c())
128 assert "Unable to cast Python instance" in str(excinfo.value)
129 with pytest.raises(RuntimeError)
as excinfo:
131 m.cpp_ref_any(m.fixed_r())
132 assert "Unable to cast Python instance" in str(excinfo.value)
133 assert m.cpp_ref_any(m.ReturnTester.create()) == 1.0
135 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
136 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
140 z = np.full((5, 6), 42.0)
141 z.flags.writeable =
False
142 np.testing.assert_array_equal(z, m.fixed_copy_r(z))
143 np.testing.assert_array_equal(m.fixed_r_const(), m.fixed_r())
144 assert not m.fixed_r_const().flags.writeable
145 np.testing.assert_array_equal(m.fixed_copy_r(m.fixed_r_const()), m.fixed_r_const())
149 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
150 second_row = counting_mat[1, :]
151 second_col = counting_mat[:, 1]
152 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
153 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
154 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
155 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
156 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
157 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
159 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
160 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
161 for ref_mat
in slices:
162 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
163 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
166 m.double_threer(second_row)
167 m.double_threec(second_col)
168 np.testing.assert_array_equal(counting_mat, [[0.0, 2, 2], [6, 16, 10], [6, 14, 8]])
172 """Eigen doesn't support (as of yet) negative strides. When a function takes an Eigen matrix by
173 copy or const reference, we can
pass a numpy array that has negative strides. Otherwise, an
174 exception will be thrown
as Eigen will
not be able to map the numpy array.
"""
176 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
177 counting_mat = counting_mat[::-1, ::-1]
178 second_row = counting_mat[1, :]
179 second_col = counting_mat[:, 1]
180 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
181 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
182 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
183 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
184 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
185 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
187 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
188 counting_3d = counting_3d[::-1, ::-1, ::-1]
189 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
190 for ref_mat
in slices:
191 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
192 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
195 with pytest.raises(TypeError)
as excinfo:
196 m.double_threer(second_row)
200 double_threer(): incompatible function arguments. The following argument types are supported:
201 1. (arg0: numpy.ndarray[numpy.float32[1, 3], flags.writeable]) -> None
204 + repr(np.array([5.0, 4.0, 3.0], dtype="float32"))
207 with pytest.raises(TypeError)
as excinfo:
208 m.double_threec(second_col)
212 double_threec(): incompatible function arguments. The following argument types are supported:
213 1. (arg0: numpy.ndarray[numpy.float32[3, 1], flags.writeable]) -> None
216 + repr(np.array([7.0, 4.0, 1.0], dtype="float32"))
221 with pytest.raises(RuntimeError)
as excinfo:
222 m.block(ref, 0, 0, 0, 0)
223 assert str(excinfo.value) ==
"type_caster for Eigen::Ref made a copy."
227 assert np.all(m.diagonal(ref) == ref.diagonal())
228 assert np.all(m.diagonal_1(ref) == ref.diagonal(1))
229 for i
in range(-5, 7):
230 assert np.all(m.diagonal_n(ref, i) == ref.diagonal(i)), f
"m.diagonal_n({i})"
234 rof = np.asarray(ref, order=
"F")
235 assert np.all(m.block(rof, 2, 1, 3, 3) == rof[2:5, 1:4])
236 assert np.all(m.block(rof, 1, 4, 4, 2) == rof[1:, 4:])
237 assert np.all(m.block(rof, 1, 4, 3, 2) == rof[1:4, 4:])
241 chols = [m.cholesky1, m.cholesky2, m.cholesky3, m.cholesky4]
242 for i, chol
in enumerate(chols, start=1):
243 mymat = chol(np.array([[1.0, 2, 4], [2, 13, 23], [4, 23, 77]]))
245 mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])
255 z = np.array(a, copy=
True)
261 """Tests various ways of returning references and non-referencing copies"""
263 primary = np.ones((10, 10))
266 assert not a_get1.flags.owndata
and a_get1.flags.writeable
269 assert not a_get2.flags.owndata
and a_get2.flags.writeable
273 assert not a_view1.flags.owndata
and not a_view1.flags.writeable
274 with pytest.raises(ValueError):
276 a_view2 = a.view_ptr()
277 assert not a_view2.flags.owndata
and not a_view2.flags.writeable
278 with pytest.raises(ValueError):
281 a_copy1 = a.copy_get()
282 assert a_copy1.flags.owndata
and a_copy1.flags.writeable
283 np.testing.assert_array_equal(a_copy1, primary)
286 a_copy2 = a.copy_view()
287 assert a_copy2.flags.owndata
and a_copy2.flags.writeable
288 np.testing.assert_array_equal(a_copy2, primary)
293 assert not a_ref1.flags.owndata
and a_ref1.flags.writeable
295 a_ref2 = a.ref_const()
296 assert not a_ref2.flags.owndata
and not a_ref2.flags.writeable
297 with pytest.raises(ValueError):
299 a_ref3 = a.ref_safe()
300 assert not a_ref3.flags.owndata
and a_ref3.flags.writeable
302 a_ref4 = a.ref_const_safe()
303 assert not a_ref4.flags.owndata
and not a_ref4.flags.writeable
304 with pytest.raises(ValueError):
305 a_ref4[7, 0] = 987654321
307 a_copy3 = a.copy_ref()
308 assert a_copy3.flags.owndata
and a_copy3.flags.writeable
309 np.testing.assert_array_equal(a_copy3, primary)
312 a_copy4 = a.copy_ref_const()
313 assert a_copy4.flags.owndata
and a_copy4.flags.writeable
314 np.testing.assert_array_equal(a_copy4, primary)
318 a_block1 = a.block(3, 3, 2, 2)
319 assert not a_block1.flags.owndata
and a_block1.flags.writeable
322 a_block2 = a.block_safe(2, 2, 3, 2)
323 assert not a_block2.flags.owndata
and a_block2.flags.writeable
324 a_block2[2, 1] = -123
326 a_block3 = a.block_const(6, 7, 4, 3)
327 assert not a_block3.flags.owndata
and not a_block3.flags.writeable
328 with pytest.raises(ValueError):
329 a_block3[2, 2] = -44444
331 a_copy5 = a.copy_block(2, 2, 2, 3)
332 assert a_copy5.flags.owndata
and a_copy5.flags.writeable
333 np.testing.assert_array_equal(a_copy5, primary[2:4, 2:5])
337 a_corn1 = a.corners()
338 assert not a_corn1.flags.owndata
and a_corn1.flags.writeable
345 a_corn2 = a.corners_const()
346 assert not a_corn2.flags.owndata
and not a_corn2.flags.writeable
347 with pytest.raises(ValueError):
352 np.testing.assert_array_equal(a_get1, primary)
353 np.testing.assert_array_equal(a_get2, primary)
354 np.testing.assert_array_equal(a_view1, primary)
355 np.testing.assert_array_equal(a_view2, primary)
356 np.testing.assert_array_equal(a_ref1, primary)
357 np.testing.assert_array_equal(a_ref2, primary)
358 np.testing.assert_array_equal(a_ref3, primary)
359 np.testing.assert_array_equal(a_ref4, primary)
360 np.testing.assert_array_equal(a_block1, primary[3:5, 3:5])
361 np.testing.assert_array_equal(a_block2, primary[2:5, 2:4])
362 np.testing.assert_array_equal(a_block3, primary[6:10, 7:10])
363 np.testing.assert_array_equal(
364 a_corn1, primary[0 :: primary.shape[0] - 1, 0 :: primary.shape[1] - 1]
366 np.testing.assert_array_equal(
367 a_corn2, primary[0 :: primary.shape[0] - 1, 0 :: primary.shape[1] - 1]
370 np.testing.assert_array_equal(a_copy1, c1want)
371 np.testing.assert_array_equal(a_copy2, c2want)
372 np.testing.assert_array_equal(a_copy3, c3want)
373 np.testing.assert_array_equal(a_copy4, c4want)
374 np.testing.assert_array_equal(a_copy5, c5want)
379 start_with = cstats.alive()
381 assert cstats.alive() == start_with + 1
383 assert cstats.alive() == start_with + 1
386 assert cstats.alive() == start_with + 1
389 assert cstats.alive() == start_with
395 assert cstats.alive() == 1
396 unsafe = [a.ref(), a.ref_const(), a.block(1, 2, 3, 4)]
402 a.copy_block(4, 3, 2, 1),
405 assert cstats.alive() == 0
411 m.ReturnTester.get_ptr,
413 m.ReturnTester.view_ptr,
414 m.ReturnTester.ref_safe,
415 m.ReturnTester.ref_const_safe,
416 m.ReturnTester.corners,
417 m.ReturnTester.corners_const,
421 for meth
in [m.ReturnTester.block_safe, m.ReturnTester.block_const]:
426 """Tests Eigen's ability to mutate numpy values"""
428 orig = np.array([[1.0, 2, 3], [4, 5, 6], [7, 8, 9]])
430 zc = np.array(orig, order=
"F")
431 m.add_rm(zr, 1, 0, 100)
432 assert np.all(zr == np.array([[1.0, 2, 3], [104, 5, 6], [7, 8, 9]]))
433 m.add_cm(zc, 1, 0, 200)
434 assert np.all(zc == np.array([[1.0, 2, 3], [204, 5, 6], [7, 8, 9]]))
436 m.add_any(zr, 1, 0, 20)
437 assert np.all(zr == np.array([[1.0, 2, 3], [124, 5, 6], [7, 8, 9]]))
438 m.add_any(zc, 1, 0, 10)
439 assert np.all(zc == np.array([[1.0, 2, 3], [214, 5, 6], [7, 8, 9]]))
442 with pytest.raises(TypeError):
443 m.add_rm(zc, 1, 0, 1)
444 with pytest.raises(TypeError):
445 m.add_cm(zr, 1, 0, 1)
448 m.add1(zr, 1, 0, -100)
449 m.add2(zr, 1, 0, -20)
450 assert np.all(zr == orig)
451 m.add1(zc, 1, 0, -200)
452 m.add2(zc, 1, 0, -10)
453 assert np.all(zc == orig)
457 cornersr = zr[0::2, 0::2]
458 cornersc = zc[0::2, 0::2]
460 assert np.all(cornersr == np.array([[1.0, 3], [7, 9]]))
461 assert np.all(cornersc == np.array([[1.0, 3], [7, 9]]))
463 with pytest.raises(TypeError):
464 m.add_rm(cornersr, 0, 1, 25)
465 with pytest.raises(TypeError):
466 m.add_cm(cornersr, 0, 1, 25)
467 with pytest.raises(TypeError):
468 m.add_rm(cornersc, 0, 1, 25)
469 with pytest.raises(TypeError):
470 m.add_cm(cornersc, 0, 1, 25)
471 m.add_any(cornersr, 0, 1, 25)
472 m.add_any(cornersc, 0, 1, 44)
473 assert np.all(zr == np.array([[1.0, 2, 28], [4, 5, 6], [7, 8, 9]]))
474 assert np.all(zc == np.array([[1.0, 2, 47], [4, 5, 6], [7, 8, 9]]))
478 zro.flags.writeable =
False
479 with pytest.raises(TypeError):
480 m.add_rm(zro, 0, 0, 0)
481 with pytest.raises(TypeError):
482 m.add_any(zro, 0, 0, 0)
483 with pytest.raises(TypeError):
485 with pytest.raises(TypeError):
489 zi = np.array([[1, 2], [3, 4]])
490 with pytest.raises(TypeError):
495 """Tests numpy mutating Eigen matrices (for returned Eigen::Ref<...>s)"""
500 zcro = m.get_cm_const_ref()
502 zrro = m.get_rm_const_ref()
504 assert [zc[1, 2], zcro[1, 2], zr[1, 2], zrro[1, 2]] == [23] * 4
506 assert not zc.flags.owndata
and zc.flags.writeable
507 assert not zr.flags.owndata
and zr.flags.writeable
508 assert not zcro.flags.owndata
and not zcro.flags.writeable
509 assert not zrro.flags.owndata
and not zrro.flags.writeable
512 expect = np.array([[11.0, 12, 13], [21, 22, 99], [31, 32, 33]])
514 assert np.all(zc == expect)
515 assert np.all(zcro == expect)
516 assert np.all(m.get_cm_ref() == expect)
519 assert np.all(zr == expect)
520 assert np.all(zrro == expect)
521 assert np.all(m.get_rm_ref() == expect)
524 with pytest.raises(ValueError):
526 with pytest.raises(ValueError):
531 y1 = np.array(m.get_cm_const_ref())
533 assert y1.flags.owndata
and y1.flags.writeable
535 assert y1[1, 2] == 99
537 assert y1[1, 2] == 111
538 assert zc[1, 2] == 99
542 """Tests a complex chain of nested eigen/numpy references"""
548 z2 = m.incr_matrix(z, 1)
550 z3 = m.incr_matrix(z, 2)
552 z4 = m.incr_matrix(z, 3)
554 z5 = m.incr_matrix(z, 4)
556 assert np.all(z == z2)
557 assert np.all(z == z3)
558 assert np.all(z == z4)
559 assert np.all(z == z5)
560 expect = np.array([[0.0, 22, 20], [31, 37, 33], [41, 42, 38]])
561 assert np.all(z == expect)
563 y = np.array(range(100), dtype=
"float64").reshape(10, 10)
564 y2 = m.incr_matrix_any(y, 10)
565 y3 = m.incr_matrix_any(
570 y6 = m.incr_matrix_any(y5, 1000)
573 yexpect = np.array(range(100), dtype=
"float64").reshape(10, 10)
575 yexpect[0::2, 0::2] -= 33
576 yexpect[0::4, 0::4] += 1000
577 assert np.all(y6 == yexpect[0::4, 0::4])
578 assert np.all(y5 == yexpect[0::4, 0::4])
579 assert np.all(y4 == yexpect[0::4, 0::2])
580 assert np.all(y3 == yexpect[0::2, 0::2])
581 assert np.all(y2 == yexpect)
582 assert np.all(y == yexpect)
588 int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order=
"F")
589 dbl_matrix_colmajor = np.array(
590 int_matrix_colmajor, dtype=
"double", order=
"F", copy=
True
592 int_matrix_rowmajor = np.array(int_matrix_colmajor, order=
"C", copy=
True)
593 dbl_matrix_rowmajor = np.array(
594 int_matrix_rowmajor, dtype=
"double", order=
"C", copy=
True
598 assert m.get_elem(int_matrix_colmajor) == 8
599 assert m.get_elem(dbl_matrix_colmajor) == 8
600 assert m.get_elem(int_matrix_rowmajor) == 8
601 assert m.get_elem(dbl_matrix_rowmajor) == 8
604 with pytest.raises(TypeError)
as excinfo:
605 m.get_elem_nocopy(int_matrix_colmajor)
606 assert "get_elem_nocopy(): incompatible function arguments." in str(
608 )
and ", flags.f_contiguous" in str(excinfo.value)
609 assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
610 with pytest.raises(TypeError)
as excinfo:
611 m.get_elem_nocopy(int_matrix_rowmajor)
612 assert "get_elem_nocopy(): incompatible function arguments." in str(
614 )
and ", flags.f_contiguous" in str(excinfo.value)
615 with pytest.raises(TypeError)
as excinfo:
616 m.get_elem_nocopy(dbl_matrix_rowmajor)
617 assert "get_elem_nocopy(): incompatible function arguments." in str(
619 )
and ", flags.f_contiguous" in str(excinfo.value)
622 with pytest.raises(TypeError)
as excinfo:
623 m.get_elem_rm_nocopy(int_matrix_colmajor)
624 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
626 )
and ", flags.c_contiguous" in str(excinfo.value)
627 with pytest.raises(TypeError)
as excinfo:
628 m.get_elem_rm_nocopy(dbl_matrix_colmajor)
629 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
631 )
and ", flags.c_contiguous" in str(excinfo.value)
632 assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
633 with pytest.raises(TypeError)
as excinfo:
634 m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
635 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
637 )
and ", flags.c_contiguous" in str(excinfo.value)
641 """Ensure the lifetime of temporary arrays created by the `Ref` caster
643 The `Ref` caster sometimes creates a copy which needs to stay alive. This needs to
644 happen both for directs casts (just the array)
or indirectly (e.g. list of arrays).
647 a = np.full(shape=10, fill_value=8, dtype=np.int8)
648 assert m.get_elem_direct(a) == 8
651 assert m.get_elem_indirect(list_of_a) == 8
655 assert np.all(m.incr_diag(7) == np.diag([1.0, 2, 3, 4, 5, 6, 7]))
657 asymm = np.array([[1.0, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
658 symm_lower = np.array(asymm)
659 symm_upper = np.array(asymm)
661 for j
in range(i + 1, 4):
662 symm_lower[i, j] = symm_lower[j, i]
663 symm_upper[j, i] = symm_upper[i, j]
665 assert np.all(m.symmetric_lower(asymm) == symm_lower)
666 assert np.all(m.symmetric_upper(asymm) == symm_upper)
673 double_col(arg0: numpy.ndarray[numpy.float32[m, 1]]) -> numpy.ndarray[numpy.float32[m, 1]]
679 double_row(arg0: numpy.ndarray[numpy.float32[1, n]]) -> numpy.ndarray[numpy.float32[1, n]]
682 assert doc(m.double_complex) == (
684 double_complex(arg0: numpy.ndarray[numpy.complex64[m, 1]])"""
685 """ -> numpy.ndarray[numpy.complex64[m, 1]]
688 assert doc(m.double_mat_rm) == (
690 double_mat_rm(arg0: numpy.ndarray[numpy.float32[m, n]])"""
691 """ -> numpy.ndarray[numpy.float32[m, n]]
697 a = np.array([[1.0, 2], [3, 4], [5, 6]])
700 assert np.all(m.matrix_multiply(a, b) == np.array([[3.0], [7], [11]]))
701 assert np.all(m.matrix_multiply(A=a, B=b) == np.array([[3.0], [7], [11]]))
702 assert np.all(m.matrix_multiply(B=b, A=a) == np.array([[3.0], [7], [11]]))
704 with pytest.raises(ValueError)
as excinfo:
705 m.matrix_multiply(b, a)
706 assert str(excinfo.value) ==
"Nonconformable matrices!"
708 with pytest.raises(ValueError)
as excinfo:
709 m.matrix_multiply(A=b, B=a)
710 assert str(excinfo.value) ==
"Nonconformable matrices!"
712 with pytest.raises(ValueError)
as excinfo:
713 m.matrix_multiply(B=a, A=b)
714 assert str(excinfo.value) ==
"Nonconformable matrices!"
718 pytest.importorskip(
"scipy")
728 pytest.importorskip(
"scipy")
732 sparse_copy_r(arg0: scipy.sparse.csr_matrix[numpy.float32]) -> scipy.sparse.csr_matrix[numpy.float32]
738 sparse_copy_c(arg0: scipy.sparse.csc_matrix[numpy.float32]) -> scipy.sparse.csc_matrix[numpy.float32]
744 """Ignore strides on a length-1 dimension (even if they would be incompatible length > 1)"""
745 assert np.all(m.iss738_f1(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
747 m.iss738_f1(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
750 assert np.all(m.iss738_f2(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
752 m.iss738_f2(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
756@pytest.mark.parametrize("func", [m.iss738_f1, m.iss738_f2])
757@pytest.mark.parametrize("sizes", [(0, 2), (2, 0)])
759 """Ignore strides on a length-0 dimension (even if they would be incompatible length > 1)"""
760 assert np.all(func(np.zeros(sizes)) == np.zeros(sizes))
764 """Issue 1105: 1xN or Nx1 input arrays weren't accepted for eigen
765 compile-time row vectors or column vector
"""
766 assert m.iss1105_row(np.ones((1, 7)))
767 assert m.iss1105_col(np.ones((7, 1)))
770 with pytest.raises(TypeError)
as excinfo:
771 m.iss1105_row(np.ones((7, 1)))
772 assert "incompatible function arguments" in str(excinfo.value)
773 with pytest.raises(TypeError)
as excinfo:
774 m.iss1105_col(np.ones((1, 7)))
775 assert "incompatible function arguments" in str(excinfo.value)
779 """Using Eigen types as member variables requires a class-specific
780 operator new with proper alignment
"""
782 o = m.CustomOperatorNew()
783 np.testing.assert_allclose(o.a, 0.0)
784 np.testing.assert_allclose(o.b.diagonal(), 1.0)
static ConstructorStats & get(std::type_index type)
def test_negative_stride_from_python(msg)
def assert_equal_ref(mat)
def test_named_arguments()
def assert_sparse_equal_ref(sparse_mat)
def array_copy_but_one(a, r, c, v)
def test_nonunit_stride_from_python()
def test_block_runtime_error_type_caster_eigen_ref_made_a_copy()
def assert_keeps_alive(cl, method, *args)
def test_eigen_keepalive()
def test_eigen_ref_mutators()
def test_sparse_signature(doc)
def test_both_ref_mutators()
def test_zero_length(func, sizes)
def test_nocopy_wrapper()
def test_eigen_return_references()
def test_eigen_ref_life_support()
def test_mutator_descriptors()
def test_partially_fixed()
def test_numpy_ref_mutators()
def test_dense_signature(doc)
def test_custom_operator_new()
def test_special_matrix_objects()
def test_pass_readonly_array()
def assign_both(a1, a2, r, c, v)
def test_nonunit_stride_to_python()
def test_eigen_ref_to_python()
Annotation for documentation.