MCPcopy Index your code
hub / github.com/python/cpython / test_ndarray_multidim

Method test_ndarray_multidim

Lib/test/test_buffer.py:1373–1416  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1371 self.assertEqual(nd.tolist(), farray(items, (3, 4)))
1372
1373 def test_ndarray_multidim(self):
1374 for ndim in range(5):
1375 shape_t = [randrange(2, 10) for _ in range(ndim)]
1376 nitems = prod(shape_t)
1377 for shape in permutations(shape_t):
1378
1379 fmt, items, _ = randitems(nitems)
1380 itemsize = struct.calcsize(fmt)
1381
1382 for flags in (0, ND_PIL):
1383 if ndim == 0 and flags == ND_PIL:
1384 continue
1385
1386 # C array
1387 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1388
1389 strides = strides_from_shape(ndim, shape, itemsize, 'C')
1390 lst = carray(items, shape)
1391 self.verify(nd, obj=None,
1392 itemsize=itemsize, fmt=fmt, readonly=True,
1393 ndim=ndim, shape=shape, strides=strides,
1394 lst=lst)
1395
1396 if is_memoryview_format(fmt):
1397 # memoryview: reconstruct strides
1398 ex = ndarray(items, shape=shape, format=fmt)
1399 nd = ndarray(ex, getbuf=PyBUF_CONTIG_RO|PyBUF_FORMAT)
1400 self.assertTrue(nd.strides == ())
1401 mv = nd.memoryview_from_buffer()
1402 self.verify(mv, obj=None,
1403 itemsize=itemsize, fmt=fmt, readonly=True,
1404 ndim=ndim, shape=shape, strides=strides,
1405 lst=lst)
1406
1407 # Fortran array
1408 nd = ndarray(items, shape=shape, format=fmt,
1409 flags=flags|ND_FORTRAN)
1410
1411 strides = strides_from_shape(ndim, shape, itemsize, 'F')
1412 lst = farray(items, shape)
1413 self.verify(nd, obj=None,
1414 itemsize=itemsize, fmt=fmt, readonly=True,
1415 ndim=ndim, shape=shape, strides=strides,
1416 lst=lst)
1417
1418 def test_ndarray_index_invalid(self):
1419 # not writable

Callers

nothing calls this directly

Calls 8

verifyMethod · 0.95
randitemsFunction · 0.85
strides_from_shapeFunction · 0.85
carrayFunction · 0.85
is_memoryview_formatFunction · 0.85
farrayFunction · 0.85
assertTrueMethod · 0.80
prodFunction · 0.70

Tested by

no test coverage detected