4from pybind11_tests
import ConstructorStats
6np = pytest.importorskip(
"numpy")
7m = pytest.importorskip(
"pybind11_tests.eigen")
12 [0.0, 3, 0, 0, 0, 11],
13 [22, 0, 0, 0, 17, 11],
22 np.testing.assert_array_equal(mat, ref)
48 ref2 = np.array([[0.0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]])
49 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2), ref2)
50 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2), ref2)
51 np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, 1]), ref2[:, [1]])
52 np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[0, :]), ref2[[0], :])
53 np.testing.assert_array_equal(
54 m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
56 np.testing.assert_array_equal(
57 m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
60 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2), ref2)
61 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2), ref2)
62 np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, 1]), ref2[:, [1]])
63 np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[0, :]), ref2[[0], :])
64 np.testing.assert_array_equal(
65 m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
67 np.testing.assert_array_equal(
68 m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
73 m.partial_copy_four_rm_r,
74 m.partial_copy_four_rm_c,
75 m.partial_copy_four_cm_r,
76 m.partial_copy_four_cm_c,
78 matrix_with_wrong_shape = [[1, 2], [3, 4]]
80 with pytest.raises(TypeError)
as excinfo:
81 f(matrix_with_wrong_shape)
82 assert "incompatible function arguments" in str(excinfo.value)
86 zr = np.arange(30, dtype=
"float32").reshape(5, 6)
87 zc = zr.reshape(6, 5).transpose()
93 with pytest.raises(TypeError)
as excinfo:
96 "(arg0: numpy.ndarray[numpy.float32[5, 6],"
97 " flags.writeable, flags.c_contiguous]) -> None" in str(excinfo.value)
99 with pytest.raises(TypeError)
as excinfo:
100 m.fixed_mutator_c(zr)
102 "(arg0: numpy.ndarray[numpy.float32[5, 6],"
103 " flags.writeable, flags.f_contiguous]) -> None" in str(excinfo.value)
105 with pytest.raises(TypeError)
as excinfo:
106 m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype=
"float32"))
107 assert "(arg0: numpy.ndarray[numpy.float32[5, 6], flags.writeable]) -> None" in str(
110 zr.flags.writeable =
False
111 with pytest.raises(TypeError):
112 m.fixed_mutator_r(zr)
113 with pytest.raises(TypeError):
114 m.fixed_mutator_a(zr)
118 assert m.cpp_copy(m.fixed_r()) == 22.0
119 assert m.cpp_copy(m.fixed_c()) == 22.0
120 z = np.array([[5.0, 6], [7, 8]])
121 assert m.cpp_copy(z) == 7.0
122 assert m.cpp_copy(m.get_cm_ref()) == 21.0
123 assert m.cpp_copy(m.get_rm_ref()) == 21.0
124 assert m.cpp_ref_c(m.get_cm_ref()) == 21.0
125 assert m.cpp_ref_r(m.get_rm_ref()) == 21.0
126 with pytest.raises(RuntimeError)
as excinfo:
128 m.cpp_ref_any(m.fixed_c())
129 assert "Unable to cast Python instance" in str(excinfo.value)
130 with pytest.raises(RuntimeError)
as excinfo:
132 m.cpp_ref_any(m.fixed_r())
133 assert "Unable to cast Python instance" in str(excinfo.value)
134 assert m.cpp_ref_any(m.ReturnTester.create()) == 1.0
136 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
137 assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
141 z = np.full((5, 6), 42.0)
142 z.flags.writeable =
False
143 np.testing.assert_array_equal(z, m.fixed_copy_r(z))
144 np.testing.assert_array_equal(m.fixed_r_const(), m.fixed_r())
145 assert not m.fixed_r_const().flags.writeable
146 np.testing.assert_array_equal(m.fixed_copy_r(m.fixed_r_const()), m.fixed_r_const())
150 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
151 second_row = counting_mat[1, :]
152 second_col = counting_mat[:, 1]
153 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
154 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
155 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
156 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
157 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
158 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
160 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
161 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
162 for ref_mat
in slices:
163 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
164 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
167 m.double_threer(second_row)
168 m.double_threec(second_col)
169 np.testing.assert_array_equal(counting_mat, [[0.0, 2, 2], [6, 16, 10], [6, 14, 8]])
173 """Eigen doesn't support (as of yet) negative strides. When a function takes an Eigen matrix by
174 copy or const reference, we can
pass a numpy array that has negative strides. Otherwise, an
175 exception will be thrown
as Eigen will
not be able to map the numpy array.
"""
177 counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
178 counting_mat = counting_mat[::-1, ::-1]
179 second_row = counting_mat[1, :]
180 second_col = counting_mat[:, 1]
181 np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
182 np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
183 np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
184 np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
185 np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
186 np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
188 counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
189 counting_3d = counting_3d[::-1, ::-1, ::-1]
190 slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
191 for ref_mat
in slices:
192 np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
193 np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
196 with pytest.raises(TypeError)
as excinfo:
197 m.double_threer(second_row)
201 double_threer(): incompatible function arguments. The following argument types are supported:
202 1. (arg0: numpy.ndarray[numpy.float32[1, 3], flags.writeable]) -> None
205 +
repr(np.array([5.0, 4.0, 3.0], dtype=
"float32"))
208 with pytest.raises(TypeError)
as excinfo:
209 m.double_threec(second_col)
213 double_threec(): incompatible function arguments. The following argument types are supported:
214 1. (arg0: numpy.ndarray[numpy.float32[3, 1], flags.writeable]) -> None
217 +
repr(np.array([7.0, 4.0, 1.0], dtype=
"float32"))
222 assert np.all(m.diagonal(ref) == ref.diagonal())
223 assert np.all(m.diagonal_1(ref) == ref.diagonal(1))
224 for i
in range(-5, 7):
226 m.diagonal_n(ref, i) == ref.diagonal(i)
227 ),
"m.diagonal_n({})".format(i)
229 assert np.all(m.block(ref, 2, 1, 3, 3) == ref[2:5, 1:4])
230 assert np.all(m.block(ref, 1, 4, 4, 2) == ref[1:, 4:])
231 assert np.all(m.block(ref, 1, 4, 3, 2) == ref[1:4, 4:])
235 chols = [m.cholesky1, m.cholesky2, m.cholesky3, m.cholesky4]
236 for i, chol
in enumerate(chols, start=1):
237 mymat = chol(np.array([[1.0, 2, 4], [2, 13, 23], [4, 23, 77]]))
239 mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])
240 ),
"cholesky{}".format(i)
249 z = np.array(a, copy=
True)
255 """Tests various ways of returning references and non-referencing copies"""
257 master = np.ones((10, 10))
260 assert not a_get1.flags.owndata
and a_get1.flags.writeable
263 assert not a_get2.flags.owndata
and a_get2.flags.writeable
267 assert not a_view1.flags.owndata
and not a_view1.flags.writeable
268 with pytest.raises(ValueError):
270 a_view2 = a.view_ptr()
271 assert not a_view2.flags.owndata
and not a_view2.flags.writeable
272 with pytest.raises(ValueError):
275 a_copy1 = a.copy_get()
276 assert a_copy1.flags.owndata
and a_copy1.flags.writeable
277 np.testing.assert_array_equal(a_copy1, master)
280 a_copy2 = a.copy_view()
281 assert a_copy2.flags.owndata
and a_copy2.flags.writeable
282 np.testing.assert_array_equal(a_copy2, master)
287 assert not a_ref1.flags.owndata
and a_ref1.flags.writeable
289 a_ref2 = a.ref_const()
290 assert not a_ref2.flags.owndata
and not a_ref2.flags.writeable
291 with pytest.raises(ValueError):
293 a_ref3 = a.ref_safe()
294 assert not a_ref3.flags.owndata
and a_ref3.flags.writeable
296 a_ref4 = a.ref_const_safe()
297 assert not a_ref4.flags.owndata
and not a_ref4.flags.writeable
298 with pytest.raises(ValueError):
299 a_ref4[7, 0] = 987654321
301 a_copy3 = a.copy_ref()
302 assert a_copy3.flags.owndata
and a_copy3.flags.writeable
303 np.testing.assert_array_equal(a_copy3, master)
306 a_copy4 = a.copy_ref_const()
307 assert a_copy4.flags.owndata
and a_copy4.flags.writeable
308 np.testing.assert_array_equal(a_copy4, master)
312 a_block1 = a.block(3, 3, 2, 2)
313 assert not a_block1.flags.owndata
and a_block1.flags.writeable
316 a_block2 = a.block_safe(2, 2, 3, 2)
317 assert not a_block2.flags.owndata
and a_block2.flags.writeable
318 a_block2[2, 1] = -123
320 a_block3 = a.block_const(6, 7, 4, 3)
321 assert not a_block3.flags.owndata
and not a_block3.flags.writeable
322 with pytest.raises(ValueError):
323 a_block3[2, 2] = -44444
325 a_copy5 = a.copy_block(2, 2, 2, 3)
326 assert a_copy5.flags.owndata
and a_copy5.flags.writeable
327 np.testing.assert_array_equal(a_copy5, master[2:4, 2:5])
331 a_corn1 = a.corners()
332 assert not a_corn1.flags.owndata
and a_corn1.flags.writeable
339 a_corn2 = a.corners_const()
340 assert not a_corn2.flags.owndata
and not a_corn2.flags.writeable
341 with pytest.raises(ValueError):
346 np.testing.assert_array_equal(a_get1, master)
347 np.testing.assert_array_equal(a_get2, master)
348 np.testing.assert_array_equal(a_view1, master)
349 np.testing.assert_array_equal(a_view2, master)
350 np.testing.assert_array_equal(a_ref1, master)
351 np.testing.assert_array_equal(a_ref2, master)
352 np.testing.assert_array_equal(a_ref3, master)
353 np.testing.assert_array_equal(a_ref4, master)
354 np.testing.assert_array_equal(a_block1, master[3:5, 3:5])
355 np.testing.assert_array_equal(a_block2, master[2:5, 2:4])
356 np.testing.assert_array_equal(a_block3, master[6:10, 7:10])
357 np.testing.assert_array_equal(
358 a_corn1, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1]
360 np.testing.assert_array_equal(
361 a_corn2, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1]
364 np.testing.assert_array_equal(a_copy1, c1want)
365 np.testing.assert_array_equal(a_copy2, c2want)
366 np.testing.assert_array_equal(a_copy3, c3want)
367 np.testing.assert_array_equal(a_copy4, c4want)
368 np.testing.assert_array_equal(a_copy5, c5want)
373 start_with = cstats.alive()
375 assert cstats.alive() == start_with + 1
377 assert cstats.alive() == start_with + 1
380 assert cstats.alive() == start_with + 1
383 assert cstats.alive() == start_with
389 assert cstats.alive() == 1
390 unsafe = [a.ref(), a.ref_const(), a.block(1, 2, 3, 4)]
396 a.copy_block(4, 3, 2, 1),
399 assert cstats.alive() == 0
405 m.ReturnTester.get_ptr,
407 m.ReturnTester.view_ptr,
408 m.ReturnTester.ref_safe,
409 m.ReturnTester.ref_const_safe,
410 m.ReturnTester.corners,
411 m.ReturnTester.corners_const,
415 for meth
in [m.ReturnTester.block_safe, m.ReturnTester.block_const]:
420 """Tests Eigen's ability to mutate numpy values"""
422 orig = np.array([[1.0, 2, 3], [4, 5, 6], [7, 8, 9]])
424 zc = np.array(orig, order=
"F")
425 m.add_rm(zr, 1, 0, 100)
426 assert np.all(zr == np.array([[1.0, 2, 3], [104, 5, 6], [7, 8, 9]]))
427 m.add_cm(zc, 1, 0, 200)
428 assert np.all(zc == np.array([[1.0, 2, 3], [204, 5, 6], [7, 8, 9]]))
430 m.add_any(zr, 1, 0, 20)
431 assert np.all(zr == np.array([[1.0, 2, 3], [124, 5, 6], [7, 8, 9]]))
432 m.add_any(zc, 1, 0, 10)
433 assert np.all(zc == np.array([[1.0, 2, 3], [214, 5, 6], [7, 8, 9]]))
436 with pytest.raises(TypeError):
437 m.add_rm(zc, 1, 0, 1)
438 with pytest.raises(TypeError):
439 m.add_cm(zr, 1, 0, 1)
442 m.add1(zr, 1, 0, -100)
443 m.add2(zr, 1, 0, -20)
444 assert np.all(zr == orig)
445 m.add1(zc, 1, 0, -200)
446 m.add2(zc, 1, 0, -10)
447 assert np.all(zc == orig)
451 cornersr = zr[0::2, 0::2]
452 cornersc = zc[0::2, 0::2]
454 assert np.all(cornersr == np.array([[1.0, 3], [7, 9]]))
455 assert np.all(cornersc == np.array([[1.0, 3], [7, 9]]))
457 with pytest.raises(TypeError):
458 m.add_rm(cornersr, 0, 1, 25)
459 with pytest.raises(TypeError):
460 m.add_cm(cornersr, 0, 1, 25)
461 with pytest.raises(TypeError):
462 m.add_rm(cornersc, 0, 1, 25)
463 with pytest.raises(TypeError):
464 m.add_cm(cornersc, 0, 1, 25)
465 m.add_any(cornersr, 0, 1, 25)
466 m.add_any(cornersc, 0, 1, 44)
467 assert np.all(zr == np.array([[1.0, 2, 28], [4, 5, 6], [7, 8, 9]]))
468 assert np.all(zc == np.array([[1.0, 2, 47], [4, 5, 6], [7, 8, 9]]))
472 zro.flags.writeable =
False
473 with pytest.raises(TypeError):
474 m.add_rm(zro, 0, 0, 0)
475 with pytest.raises(TypeError):
476 m.add_any(zro, 0, 0, 0)
477 with pytest.raises(TypeError):
479 with pytest.raises(TypeError):
483 zi = np.array([[1, 2], [3, 4]])
484 with pytest.raises(TypeError):
489 """Tests numpy mutating Eigen matrices (for returned Eigen::Ref<...>s)"""
494 zcro = m.get_cm_const_ref()
496 zrro = m.get_rm_const_ref()
498 assert [zc[1, 2], zcro[1, 2], zr[1, 2], zrro[1, 2]] == [23] * 4
500 assert not zc.flags.owndata
and zc.flags.writeable
501 assert not zr.flags.owndata
and zr.flags.writeable
502 assert not zcro.flags.owndata
and not zcro.flags.writeable
503 assert not zrro.flags.owndata
and not zrro.flags.writeable
506 expect = np.array([[11.0, 12, 13], [21, 22, 99], [31, 32, 33]])
508 assert np.all(zc == expect)
509 assert np.all(zcro == expect)
510 assert np.all(m.get_cm_ref() == expect)
513 assert np.all(zr == expect)
514 assert np.all(zrro == expect)
515 assert np.all(m.get_rm_ref() == expect)
518 with pytest.raises(ValueError):
520 with pytest.raises(ValueError):
525 y1 = np.array(m.get_cm_const_ref())
527 assert y1.flags.owndata
and y1.flags.writeable
529 assert y1[1, 2] == 99
531 assert y1[1, 2] == 111
532 assert zc[1, 2] == 99
536 """Tests a complex chain of nested eigen/numpy references"""
542 z2 = m.incr_matrix(z, 1)
544 z3 = m.incr_matrix(z, 2)
546 z4 = m.incr_matrix(z, 3)
548 z5 = m.incr_matrix(z, 4)
550 assert np.all(z == z2)
551 assert np.all(z == z3)
552 assert np.all(z == z4)
553 assert np.all(z == z5)
554 expect = np.array([[0.0, 22, 20], [31, 37, 33], [41, 42, 38]])
555 assert np.all(z == expect)
557 y = np.array(range(100), dtype=
"float64").reshape(10, 10)
558 y2 = m.incr_matrix_any(y, 10)
559 y3 = m.incr_matrix_any(
564 y6 = m.incr_matrix_any(y5, 1000)
567 yexpect = np.array(range(100), dtype=
"float64").reshape(10, 10)
569 yexpect[0::2, 0::2] -= 33
570 yexpect[0::4, 0::4] += 1000
571 assert np.all(y6 == yexpect[0::4, 0::4])
572 assert np.all(y5 == yexpect[0::4, 0::4])
573 assert np.all(y4 == yexpect[0::4, 0::2])
574 assert np.all(y3 == yexpect[0::2, 0::2])
575 assert np.all(y2 == yexpect)
576 assert np.all(y == yexpect)
582 int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order=
"F")
583 dbl_matrix_colmajor = np.array(
584 int_matrix_colmajor, dtype=
"double", order=
"F", copy=
True
586 int_matrix_rowmajor = np.array(int_matrix_colmajor, order=
"C", copy=
True)
587 dbl_matrix_rowmajor = np.array(
588 int_matrix_rowmajor, dtype=
"double", order=
"C", copy=
True
592 assert m.get_elem(int_matrix_colmajor) == 8
593 assert m.get_elem(dbl_matrix_colmajor) == 8
594 assert m.get_elem(int_matrix_rowmajor) == 8
595 assert m.get_elem(dbl_matrix_rowmajor) == 8
598 with pytest.raises(TypeError)
as excinfo:
599 m.get_elem_nocopy(int_matrix_colmajor)
600 assert "get_elem_nocopy(): incompatible function arguments." in str(
602 )
and ", flags.f_contiguous" in str(excinfo.value)
603 assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
604 with pytest.raises(TypeError)
as excinfo:
605 m.get_elem_nocopy(int_matrix_rowmajor)
606 assert "get_elem_nocopy(): incompatible function arguments." in str(
608 )
and ", flags.f_contiguous" in str(excinfo.value)
609 with pytest.raises(TypeError)
as excinfo:
610 m.get_elem_nocopy(dbl_matrix_rowmajor)
611 assert "get_elem_nocopy(): incompatible function arguments." in str(
613 )
and ", flags.f_contiguous" in str(excinfo.value)
616 with pytest.raises(TypeError)
as excinfo:
617 m.get_elem_rm_nocopy(int_matrix_colmajor)
618 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
620 )
and ", flags.c_contiguous" in str(excinfo.value)
621 with pytest.raises(TypeError)
as excinfo:
622 m.get_elem_rm_nocopy(dbl_matrix_colmajor)
623 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
625 )
and ", flags.c_contiguous" in str(excinfo.value)
626 assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
627 with pytest.raises(TypeError)
as excinfo:
628 m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
629 assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
631 )
and ", flags.c_contiguous" in str(excinfo.value)
635 """Ensure the lifetime of temporary arrays created by the `Ref` caster
637 The `Ref` caster sometimes creates a copy which needs to stay alive. This needs to
638 happen both for directs casts (just the array)
or indirectly (e.g. list of arrays).
641 a = np.full(shape=10, fill_value=8, dtype=np.int8)
642 assert m.get_elem_direct(a) == 8
645 assert m.get_elem_indirect(list_of_a) == 8
649 assert np.all(m.incr_diag(7) == np.diag([1.0, 2, 3, 4, 5, 6, 7]))
651 asymm = np.array([[1.0, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
652 symm_lower = np.array(asymm)
653 symm_upper = np.array(asymm)
655 for j
in range(i + 1, 4):
656 symm_lower[i, j] = symm_lower[j, i]
657 symm_upper[j, i] = symm_upper[i, j]
659 assert np.all(m.symmetric_lower(asymm) == symm_lower)
660 assert np.all(m.symmetric_upper(asymm) == symm_upper)
667 double_col(arg0: numpy.ndarray[numpy.float32[m, 1]]) -> numpy.ndarray[numpy.float32[m, 1]]
673 double_row(arg0: numpy.ndarray[numpy.float32[1, n]]) -> numpy.ndarray[numpy.float32[1, n]]
676 assert doc(m.double_complex) == (
678 double_complex(arg0: numpy.ndarray[numpy.complex64[m, 1]])"""
679 """ -> numpy.ndarray[numpy.complex64[m, 1]]
682 assert doc(m.double_mat_rm) == (
684 double_mat_rm(arg0: numpy.ndarray[numpy.float32[m, n]])"""
685 """ -> numpy.ndarray[numpy.float32[m, n]]
691 a = np.array([[1.0, 2], [3, 4], [5, 6]])
694 assert np.all(m.matrix_multiply(a, b) == np.array([[3.0], [7], [11]]))
695 assert np.all(m.matrix_multiply(A=a, B=b) == np.array([[3.0], [7], [11]]))
696 assert np.all(m.matrix_multiply(B=b, A=a) == np.array([[3.0], [7], [11]]))
698 with pytest.raises(ValueError)
as excinfo:
699 m.matrix_multiply(b, a)
700 assert str(excinfo.value) ==
"Nonconformable matrices!"
702 with pytest.raises(ValueError)
as excinfo:
703 m.matrix_multiply(A=b, B=a)
704 assert str(excinfo.value) ==
"Nonconformable matrices!"
706 with pytest.raises(ValueError)
as excinfo:
707 m.matrix_multiply(B=a, A=b)
708 assert str(excinfo.value) ==
"Nonconformable matrices!"
712 pytest.importorskip(
"scipy")
722 pytest.importorskip(
"scipy")
726 sparse_copy_r(arg0: scipy.sparse.csr_matrix[numpy.float32]) -> scipy.sparse.csr_matrix[numpy.float32]
732 sparse_copy_c(arg0: scipy.sparse.csc_matrix[numpy.float32]) -> scipy.sparse.csc_matrix[numpy.float32]
738 """Ignore strides on a length-1 dimension (even if they would be incompatible length > 1)"""
739 assert np.all(m.iss738_f1(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
741 m.iss738_f1(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
744 assert np.all(m.iss738_f2(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
746 m.iss738_f2(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
751 """Issue 1105: 1xN or Nx1 input arrays weren't accepted for eigen
752 compile-time row vectors or column vector
"""
753 assert m.iss1105_row(np.ones((1, 7)))
754 assert m.iss1105_col(np.ones((7, 1)))
757 with pytest.raises(TypeError)
as excinfo:
758 m.iss1105_row(np.ones((7, 1)))
759 assert "incompatible function arguments" in str(excinfo.value)
760 with pytest.raises(TypeError)
as excinfo:
761 m.iss1105_col(np.ones((1, 7)))
762 assert "incompatible function arguments" in str(excinfo.value)
766 """Using Eigen types as member variables requires a class-specific
767 operator new with proper alignment
"""
769 o = m.CustomOperatorNew()
770 np.testing.assert_allclose(o.a, 0.0)
771 np.testing.assert_allclose(o.b.diagonal(), 1.0)
static ConstructorStats & get(std::type_index type)
def test_nonunit_stride_to_python()
def test_negative_stride_from_python(msg)
def test_numpy_ref_mutators()
def assert_sparse_equal_ref(sparse_mat)
def test_pass_readonly_array()
def test_nonunit_stride_from_python()
def test_sparse_signature(doc)
def test_eigen_keepalive()
def test_nocopy_wrapper()
def test_dense_signature(doc)
def test_eigen_ref_mutators()
def array_copy_but_one(a, r, c, v)
def assert_equal_ref(mat)
def test_mutator_descriptors()
def test_partially_fixed()
def test_named_arguments()
def test_special_matrix_objects()
def assert_keeps_alive(cl, method, *args)
def test_eigen_ref_to_python()
def assign_both(a1, a2, r, c, v)
def test_custom_operator_new()
def test_eigen_return_references()
def test_both_ref_mutators()
def test_eigen_ref_life_support()
Annotation for documentation.