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

Method test_put

numpy/core/tests/test_multiarray.py:3416–3454  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3414 assert_(isinstance(t, MyArray))
3415
3416 def test_put(self):
3417 icodes = np.typecodes['AllInteger']
3418 fcodes = np.typecodes['AllFloat']
3419 for dt in icodes + fcodes + 'O':
3420 tgt = np.array([0, 1, 0, 3, 0, 5], dtype=dt)
3421
3422 # test 1-d
3423 a = np.zeros(6, dtype=dt)
3424 a.put([1, 3, 5], [1, 3, 5])
3425 assert_equal(a, tgt)
3426
3427 # test 2-d
3428 a = np.zeros((2, 3), dtype=dt)
3429 a.put([1, 3, 5], [1, 3, 5])
3430 assert_equal(a, tgt.reshape(2, 3))
3431
3432 for dt in '?':
3433 tgt = np.array([False, True, False, True, False, True], dtype=dt)
3434
3435 # test 1-d
3436 a = np.zeros(6, dtype=dt)
3437 a.put([1, 3, 5], [True]*3)
3438 assert_equal(a, tgt)
3439
3440 # test 2-d
3441 a = np.zeros((2, 3), dtype=dt)
3442 a.put([1, 3, 5], [True]*3)
3443 assert_equal(a, tgt.reshape(2, 3))
3444
3445 # check must be writeable
3446 a = np.zeros(6)
3447 a.flags.writeable = False
3448 assert_raises(ValueError, a.put, [1, 3, 5], [1, 3, 5])
3449
3450 # when calling np.put, make sure a
3451 # TypeError is raised if the object
3452 # isn't an ndarray
3453 bad_array = [1, 2, 3]
3454 assert_raises(TypeError, np.put, bad_array, [0, 2], 5)
3455
3456 def test_ravel(self):
3457 a = np.array([[0, 1], [2, 3]])

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
assert_raisesFunction · 0.90
putMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected