MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_ndarray_multidim

Method test_ndarray_multidim

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

Source from the content-addressed store, hash-verified

1359 self.assertEqual(nd.tolist(), farray(items, (3, 4)))
1360
1361 def test_ndarray_multidim(self):
1362 for ndim in range(5):
1363 shape_t = [randrange(2, 10) for _ in range(ndim)]
1364 nitems = prod(shape_t)
1365 for shape in permutations(shape_t):
1366
1367 fmt, items, _ = randitems(nitems)
1368 itemsize = struct.calcsize(fmt)
1369
1370 for flags in (0, ND_PIL):
1371 if ndim == 0 and flags == ND_PIL:
1372 continue
1373
1374 # C array
1375 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1376
1377 strides = strides_from_shape(ndim, shape, itemsize, 'C')
1378 lst = carray(items, shape)
1379 self.verify(nd, obj=None,
1380 itemsize=itemsize, fmt=fmt, readonly=True,
1381 ndim=ndim, shape=shape, strides=strides,
1382 lst=lst)
1383
1384 if is_memoryview_format(fmt):
1385 # memoryview: reconstruct strides
1386 ex = ndarray(items, shape=shape, format=fmt)
1387 nd = ndarray(ex, getbuf=PyBUF_CONTIG_RO|PyBUF_FORMAT)
1388 self.assertTrue(nd.strides == ())
1389 mv = nd.memoryview_from_buffer()
1390 self.verify(mv, obj=None,
1391 itemsize=itemsize, fmt=fmt, readonly=True,
1392 ndim=ndim, shape=shape, strides=strides,
1393 lst=lst)
1394
1395 # Fortran array
1396 nd = ndarray(items, shape=shape, format=fmt,
1397 flags=flags|ND_FORTRAN)
1398
1399 strides = strides_from_shape(ndim, shape, itemsize, 'F')
1400 lst = farray(items, shape)
1401 self.verify(nd, obj=None,
1402 itemsize=itemsize, fmt=fmt, readonly=True,
1403 ndim=ndim, shape=shape, strides=strides,
1404 lst=lst)
1405
1406 def test_ndarray_index_invalid(self):
1407 # 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