MCPcopy Create free account
hub / github.com/numpy/numpy / test_two_values

Method test_two_values

numpy/lib/tests/test_arraypad.py:46–69  ·  view source on GitHub ↗

Test proper casting for two different values.

(self)

Source from the content-addressed store, hash-verified

44 )
45
46 def test_two_values(self):
47 """Test proper casting for two different values."""
48 # Broadcasting in the first dimension with numbers
49 expected = np.array([[3, 4]] * 10)
50 for x in ([3, 4], [[3, 4]]):
51 result = _as_pairs(x, 10)
52 assert_equal(result, expected)
53 # and with dtype=object
54 obj = object()
55 assert_equal(
56 _as_pairs(["a", obj], 10),
57 np.array([["a", obj]] * 10)
58 )
59
60 # Broadcasting in the second / last dimension with numbers
61 assert_equal(
62 _as_pairs([[3], [4]], 2),
63 np.array([[3, 3], [4, 4]])
64 )
65 # and with dtype=object
66 assert_equal(
67 _as_pairs([["a"], [obj]], 2),
68 np.array([["a", "a"], [obj, obj]])
69 )
70
71 def test_with_none(self):
72 expected = ((None, None), (None, None), (None, None))

Callers

nothing calls this directly

Calls 2

_as_pairsFunction · 0.90
assert_equalFunction · 0.90

Tested by

no test coverage detected