MCPcopy Create free account
hub / github.com/apple/coremltools / test_from_python

Function test_from_python

deps/pybind11/tests/test_buffers.py:73–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71
72
73def test_from_python():
74 with pytest.raises(RuntimeError) as excinfo:
75 m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array
76 assert str(excinfo.value) == "Incompatible buffer format!"
77
78 m3 = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
79 m4 = m.Matrix(m3)
80
81 for i in range(m4.rows()):
82 for j in range(m4.cols()):
83 assert m3[i, j] == m4[i, j]
84
85 cstats = ConstructorStats.get(m.Matrix)
86 assert cstats.alive() == 1
87 del m3, m4
88 assert cstats.alive() == 0
89 assert cstats.values() == ["2x3 matrix"]
90 assert cstats.copy_constructions == 0
91 # assert cstats.move_constructions >= 0 # Don't invoke any
92 assert cstats.copy_assignments == 0
93 assert cstats.move_assignments == 0
94
95
96# https://foss.heptapod.net/pypy/pypy/-/issues/2444

Callers

nothing calls this directly

Calls 8

rowsMethod · 0.95
colsMethod · 0.95
aliveMethod · 0.80
getMethod · 0.65
strClass · 0.50
MatrixMethod · 0.45
arrayMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected