()
| 397 | |
| 398 | |
| 399 | def test_tril_indices(): |
| 400 | # indices without and with offset |
| 401 | il1 = tril_indices(4) |
| 402 | il2 = tril_indices(4, k=2) |
| 403 | il3 = tril_indices(4, m=5) |
| 404 | il4 = tril_indices(4, k=2, m=5) |
| 405 | |
| 406 | a = np.array([[1, 2, 3, 4], |
| 407 | [5, 6, 7, 8], |
| 408 | [9, 10, 11, 12], |
| 409 | [13, 14, 15, 16]]) |
| 410 | b = np.arange(1, 21).reshape(4, 5) |
| 411 | |
| 412 | # indexing: |
| 413 | assert_array_equal(a[il1], |
| 414 | array([1, 5, 6, 9, 10, 11, 13, 14, 15, 16])) |
| 415 | assert_array_equal(b[il3], |
| 416 | array([1, 6, 7, 11, 12, 13, 16, 17, 18, 19])) |
| 417 | |
| 418 | # And for assigning values: |
| 419 | a[il1] = -1 |
| 420 | assert_array_equal(a, |
| 421 | array([[-1, 2, 3, 4], |
| 422 | [-1, -1, 7, 8], |
| 423 | [-1, -1, -1, 12], |
| 424 | [-1, -1, -1, -1]])) |
| 425 | b[il3] = -1 |
| 426 | assert_array_equal(b, |
| 427 | array([[-1, 2, 3, 4, 5], |
| 428 | [-1, -1, 8, 9, 10], |
| 429 | [-1, -1, -1, 14, 15], |
| 430 | [-1, -1, -1, -1, 20]])) |
| 431 | # These cover almost the whole array (two diagonals right of the main one): |
| 432 | a[il2] = -10 |
| 433 | assert_array_equal(a, |
| 434 | array([[-10, -10, -10, 4], |
| 435 | [-10, -10, -10, -10], |
| 436 | [-10, -10, -10, -10], |
| 437 | [-10, -10, -10, -10]])) |
| 438 | b[il4] = -10 |
| 439 | assert_array_equal(b, |
| 440 | array([[-10, -10, -10, 4, 5], |
| 441 | [-10, -10, -10, -10, 10], |
| 442 | [-10, -10, -10, -10, -10], |
| 443 | [-10, -10, -10, -10, -10]])) |
| 444 | |
| 445 | |
| 446 | class TestTriuIndices: |
nothing calls this directly
no test coverage detected