• Home
  • Raw
  • Download

Lines Matching full:shape

256 def strides_from_shape(ndim, shape, itemsize, layout):  argument
262 strides = list(shape[1:]) + [itemsize]
266 strides = [itemsize] + list(shape[:-1])
273 multidimensional C array with shape 's'."""
287 multidimensional Fortran array with shape 's'."""
298 def carray(items, shape): argument
299 if listp(items) and not 0 in shape and prod(shape) != len(items):
300 raise ValueError("prod(shape) != len(items)")
301 return _ca(items, shape)
303 def farray(items, shape): argument
304 if listp(items) and not 0 in shape and prod(shape) != len(items):
305 raise ValueError("prod(shape) != len(items)")
306 return _fa(items, shape)
308 def indices(shape): argument
310 iterables = [range(v) for v in shape]
320 def transpose(src, shape): argument
322 matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """
323 if not shape:
325 ndim = len(shape)
326 sstrides = strides_from_shape(ndim, shape, 1, 'C')
327 dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C')
329 for ind in indices(shape):
350 """Get the shape of lst after slicing: slices is a list of slice
412 # - shape can be zero
424 # t = (memlen, itemsize, ndim, shape, strides, offset)
427 def verify_structure(memlen, itemsize, ndim, shape, strides, offset): argument
442 return ndim == 0 and not shape and not strides
443 if 0 in shape:
446 imin = sum(strides[j]*(shape[j]-1) for j in range(ndim)
448 imax = sum(strides[j]*(shape[j]-1) for j in range(ndim)
460 memlen, itemsize, ndim, shape, strides, offset = t
470 memlen, itemsize, ndim, shape, strides, offset = t
472 for ind in indices(shape):
480 def rand_structure(itemsize, valid, maxdim=5, maxshape=16, shape=()): argument
482 (memlen, itemsize, ndim, shape, strides, offset)
484 If 'shape' is given, use that instead of creating a random shape.
486 if not shape:
503 shape = [0] * ndim
506 shape[i] = randrange(minshape, maxshape+1)
508 ndim = len(shape)
520 maxstride *= shape[i+1] if shape[i+1] else 1
528 if not 0 in shape:
529 imin = sum(strides[j]*(shape[j]-1) for j in range(ndim)
531 imax = sum(strides[j]*(shape[j]-1) for j in range(ndim)
541 return memlen, itemsize, ndim, shape, strides, offset
556 def randslice_from_shape(ndim, shape): argument
557 """Create two sets of slices for an array x with shape 'shape'
562 l = shape[n]
571 with shape 'lshape' and y is an array with shape 'rshape'."""
619 memlen, itemsize, ndim, shape, strides, offset = t
620 return ndarray(items, shape=shape, strides=strides, format=fmt,
625 memlen, itemsize, ndim, shape, strides, offset = t
629 return numpy_array(buffer=buf, shape=shape, strides=strides,
637 def cast_items(exporter, fmt, itemsize, shape=None): argument
639 size 'itemsize'. If shape=None, the new structure is assumed to
640 be 1-D with n * itemsize = bytelen. If shape is given, the usual
641 constraint for contiguous arrays prod(shape) * itemsize = bytelen
642 applies. On success, return (items, shape). If the constraints
646 if shape:
647 if prod(shape) * itemsize != bytelen:
648 return None, shape
649 elif shape == []:
651 return None, shape
654 shape = [n]
656 return None, shape
665 return 'nan', shape
668 return (items, shape) if shape != [] else (items[0], shape)
690 def genslices_ndim(ndim, shape): argument
691 """Generate all possible slice tuples for 'shape'."""
692 iterables = [genslices(shape[n]) for n in range(ndim)]
708 def rslices_ndim(ndim, shape, iterations=5): argument
709 """Generate random slice tuples for 'shape'."""
712 yield tuple(rslice(shape[n]) for n in range(ndim))
715 yield tuple(rslice(shape[n], allow_empty=True) for n in range(ndim))
736 print("ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, "
738 (x, nd.shape, nd.strides, nd.suboffsets, offset,
766 ndim={1}, shape=-1, strides=-1, argument
770 if shape:
771 expected_len = prod(shape)*itemsize
786 if shape[n] == 0:
789 suboffset0 += -strides[n] * (shape[n]-1)
805 self.assertEqual(result.shape, tuple(shape))
826 for ind in indices(shape):
864 trans = transpose(flattened, shape)
865 expected = ndarray(trans, shape=shape, format=ff,
871 expected = ndarray(flattened, shape=shape, format=ff)
894 y = ndarray(initlst, shape=shape, flags=ro, format=fmt)
905 y = ndarray(initlst, shape=shape, flags=ro|ND_FORTRAN,
918 y = ndarray(initlst, shape=shape, flags=f|ro, format=fmt)
933 self.assertEqual(m.shape, tuple(shape))
980 # The equality product(shape) * itemsize = len still holds.
986 shape = orig_ex.shape if match(req, PyBUF_ND) else ()
992 ndim=ndim, shape=shape, strides=strides,
1013 # shape, strides, offset
1037 for shape, strides, offset in structure:
1044 if not shape and (flags&ND_PIL):
1047 _items = items if shape else items[0]
1049 shape=shape, strides=strides, offset=offset)
1050 ex2 = ex1[::-2] if shape else None
1055 if ex1.ndim == 0 or (ex1.ndim == 1 and shape and strides):
1057 if ex2 and ex2.ndim == 1 and shape and strides:
1073 ex = ndarray(items, shape=[12], flags=ND_GETBUF_FAIL)
1089 for shape in [1,12,1], [7,0,7]:
1091 ex = ndarray(items, shape=shape, flags=order|ND_WRITABLE)
1110 self.assertRaises(TypeError, c, [1,2,3], shape={3})
1111 self.assertRaises(TypeError, c, [1,2,3], shape=[3], strides={1})
1112 self.assertRaises(TypeError, c, [1,2,3], shape=[3], offset=[])
1113 self.assertRaises(TypeError, c, [1], shape=[1], format={})
1114 self.assertRaises(TypeError, c, [1], shape=[1], flags={})
1115 self.assertRaises(TypeError, c, [1], shape=[1], getbuf={})
1118 self.assertRaises(TypeError, c, [1], shape=[1], strides=[1],
1122 self.assertRaises(TypeError, c, [1], shape=[], flags=ND_PIL)
1125 self.assertRaises(ValueError, c, [], shape=[1])
1126 self.assertRaises(ValueError, c, ['XXX'], shape=[1], format="L")
1128 self.assertRaises(struct.error, c, [1000], shape=[1], format="B")
1129 self.assertRaises(ValueError, c, [1,(2,3)], shape=[2], format="B")
1130 self.assertRaises(ValueError, c, [1,2,3], shape=[3], format="QL")
1134 self.assertRaises(ValueError, c, [1]*n, shape=[1]*n)
1136 # Invalid shape.
1137 self.assertRaises(ValueError, c, [1], shape=[-1])
1138 self.assertRaises(ValueError, c, [1,2,3], shape=['3'])
1139 self.assertRaises(OverflowError, c, [1], shape=[2**128])
1140 # prod(shape) * itemsize != len(items)
1141 self.assertRaises(ValueError, c, [1,2,3,4,5], shape=[2,2], offset=3)
1144 self.assertRaises(ValueError, c, [1,2,3], shape=[3], strides=['1'])
1145 self.assertRaises(OverflowError, c, [1], shape=[1],
1148 # Invalid combination of strides and shape.
1149 self.assertRaises(ValueError, c, [1,2], shape=[2,1], strides=[1])
1151 self.assertRaises(ValueError, c, [1,2,3,4], shape=[2], strides=[3],
1155 self.assertRaises(ValueError, c, [1,2,3], shape=[3], offset=4)
1156 self.assertRaises(ValueError, c, [1,2,3], shape=[1], offset=3,
1160 self.assertRaises(ValueError, c, [1,2,3], shape=[3], format="")
1161 self.assertRaises(struct.error, c, [(1,2,3)], shape=[1],
1166 self.assertRaises(ValueError, c, items, shape=[2,3],
1173 self.assertRaises(TypeError, c, [1], shape=[1], getbuf=PyBUF_FULL)
1175 # Shape argument is mandatory for original base objects.
1208 nd = ndarray(list(range(100)), shape=[1]*100)
1211 nd = ndarray(list(range(12)), shape=[3,4])
1218 ex = ndarray([1,2,3], shape=[3], format='L')
1223 ex1 = ndarray([1,2,3], shape=[3], format='L')
1228 nd = ndarray([(1,)*200], shape=[1], format='L'*200)
1232 nd = ndarray(list(range(n)), shape=[1]*n)
1236 nd = ndarray([1], shape=[1])
1247 nd = ndarray([1], shape=[1])
1253 nd = ndarray([1], shape=[1])
1261 nd = ndarray([1,2,3], shape=[3], flags=ND_VAREXPORT)
1265 nd.push([1,2,3], shape=[3])
1278 nd = ndarray(scalar, shape=(), format=fmt)
1281 ndim=0, shape=(), strides=(),
1285 # ndim = 1, shape = [n]
1290 nd = ndarray(items, shape=[nitems], format=fmt, flags=flags)
1293 ndim=1, shape=(nitems,), strides=(itemsize,),
1305 shape = [len(items[::step])]
1310 nd = ndarray(items, shape=shape, strides=strides,
1314 ndim=1, shape=shape, strides=strides,
1319 ex = ndarray(items, shape=(3, 4), strides=(1, 3))
1327 for shape in permutations(shape_t):
1337 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1339 strides = strides_from_shape(ndim, shape, itemsize, 'C')
1340 lst = carray(items, shape)
1343 ndim=ndim, shape=shape, strides=strides,
1348 ex = ndarray(items, shape=shape, format=fmt)
1354 ndim=ndim, shape=shape, strides=strides,
1358 nd = ndarray(items, shape=shape, format=fmt,
1361 strides = strides_from_shape(ndim, shape, itemsize, 'F')
1362 lst = farray(items, shape)
1365 ndim=ndim, shape=shape, strides=strides,
1370 nd = ndarray([1], shape=[1])
1377 nd = ndarray([1], shape=[1], flags=ND_WRITABLE)
1384 nd = ndarray([1], shape=[1], flags=ND_WRITABLE)
1394 nd = ndarray(items, shape=[len(items)], format="B", flags=ND_WRITABLE)
1403 nd = ndarray(items, shape=[len(items)], format="LQ", flags=ND_WRITABLE)
1409 nd = ndarray(1, shape=(), flags=ND_WRITABLE)
1434 ex = ndarray(list(range(2*4)), shape=[2, 4], flags=ND_WRITABLE)
1445 nd = ndarray(items, shape=[5], format=fmt)
1463 ex = ndarray(items, shape=[5], flags=ND_WRITABLE, format=fmt)
1477 ex = ndarray(items, shape=[5])
1482 # getitem with null shape/strides/format
1484 ex = ndarray(items, shape=[5])
1493 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1505 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1519 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1528 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1539 for shape in permutations(shape_t):
1545 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1546 lst = carray(items, shape)
1548 for i in range(-shape[0], shape[0]):
1550 for j in range(-shape[1], shape[1]):
1552 for k in range(-shape[2], shape[2]):
1556 nd = ndarray(items, shape=shape, format=fmt,
1558 lst = farray(items, shape)
1560 for i in range(-shape[0], shape[0]):
1562 for j in range(-shape[1], shape[1]):
1564 for k in range(shape[2], shape[2]):
1568 nd = ndarray(1, shape=())
1575 nd = ndarray(items, shape=[5], format=fmt)
1590 xl = ndarray(items, shape=[8], flags=ND_WRITABLE)
1596 xl = ndarray(items, shape=[8], flags=ND_WRITABLE)
1597 ex = ndarray(items, shape=[8], flags=ND_WRITABLE)
1602 nd = ndarray(items, shape=[8], format="L", flags=ND_WRITABLE)
1607 nd = ndarray(items, shape=[2,4], format="L", flags=ND_WRITABLE)
1624 xl = ndarray(items, shape=[8], format="B", flags=ND_WRITABLE)
1625 xr = ndarray(items, shape=[8], format="b")
1634 xl = ndarray(items, shape=[8], format="B", flags=ND_WRITABLE)
1635 yr = ndarray(items, shape=[8], format="L")
1644 xl = ndarray(items, shape=[2, 4], format="b", flags=ND_WRITABLE)
1645 xr = ndarray(items, shape=[8], format="b")
1653 # differing shape
1654 xl = ndarray(items, shape=[8], format="b", flags=ND_WRITABLE)
1655 xr = ndarray(items, shape=[8], format="b")
1668 x = ndarray(items, shape=[8], format="b", flags=ND_PIL)
1671 ex = ndarray(items, shape=[8], format="B")
1678 x = ndarray(items, shape=[12], format="L", flags=ND_WRITABLE)
1679 y = ndarray(items, shape=[12], format="L")
1690 x = ndarray(items, shape=[3, 4], format="L", flags=ND_WRITABLE)
1691 y = ndarray(items, shape=[4, 3], format="L")
1699 for shape in permutations(shape_t):
1705 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1706 lst = carray(items, shape)
1708 for slices in rslices_ndim(ndim, shape):
1731 for shape in permutations(shape_t):
1736 nd = ndarray(items, shape=shape, format=fmt)
1738 ex = ndarray(items, shape=shape, format=fmt)
1741 lst = carray(items, shape)
1743 for slices in rslices_ndim(ndim, shape):
1769 nd = ndarray(items, shape=[5], format=fmt, flags=f)
1770 ex = ndarray(items, shape=[5], format=fmt, flags=f)
1790 if diff_structure: # ndarray cannot change shape
1805 if diff_structure: # memoryview cannot change shape
1813 ndim=nd.ndim, shape=nd.shape, strides=nd.strides,
1820 for shape in permutations(shape_t):
1826 lslices, rslices = randslice_from_shape(ndim, shape)
1828 nd = ndarray(items, shape=shape, format=fmt,
1830 lst = carray(items, shape)
1881 shape = t[3]
1882 if 0 in shape:
1887 ndim=z.ndim, shape=z.shape, strides=z.strides,
1926 tl = rand_structure(itemsize, True, shape=lshape)
1927 tr = rand_structure(itemsize, True, shape=rshape)
1972 ndim=zl.ndim, shape=zl.shape,
1977 ndim=zr.ndim, shape=zr.shape,
1983 nd = ndarray(items, shape=[3,4], flags=ND_PIL)
1994 # zeros in shape
1996 nd = ndarray([1,2,3], shape=[0], flags=flags)
2002 nd = ndarray([1,2,3], shape=[0,3,3], flags=flags)
2005 nd = ndarray([1,2,3], shape=[3,0,3], flags=flags)
2008 nd = ndarray([1,2,3], shape=[3,3,0], flags=flags)
2015 nd = ndarray([1], shape=[5], strides=[0], flags=flags)
2022 nd = ndarray(list(range(20)), shape=[3], offset=7)
2028 nd = ndarray(list(range(3)), shape=[3], flags=flags)
2034 nd = ndarray(list(range(3)), shape=[3], flags=flags)
2039 ex = ndarray(list(range(20)), shape=[2,2,5])
2051 x = ndarray(list(range(12)), shape=[3,4])
2052 y = ndarray(list(range(12)), shape=[4,3])
2055 x = ndarray([1], shape=[1], format="B")
2068 nd = ndarray(list(range(12)), shape=[12])
2072 nd = ndarray(list(range(12)), shape=[3,4])
2075 nd = ndarray(list(range(12)), shape=[3,2,2])
2079 b = bytes(transpose(list(range(12)), shape=[4,3]))
2080 nd = ndarray(list(range(12)), shape=[3,4], flags=ND_FORTRAN)
2083 b = bytes(transpose(list(range(12)), shape=[2,3,2]))
2084 nd = ndarray(list(range(12)), shape=[2,3,2], flags=ND_FORTRAN)
2089 nd = ndarray(list(range(12)), shape=[2,2,3], flags=ND_PIL)
2093 nd = ndarray(list(range(12)), shape=[2,2,3], format='L')
2115 nd = ndarray(9, shape=(), format="L", flags=ND_WRITABLE)
2121 # zeros in shape
2122 nd = ndarray([1], shape=[0], format="L", flags=ND_WRITABLE)
2128 nd = ndarray(list(range(8)), shape=[2, 0, 7], format="L",
2140 nd = ndarray([1], shape=[1], format="h", flags=f|ND_WRITABLE)
2147 nd = ndarray([1, 2, 3], shape=[3], format="b", flags=f|ND_WRITABLE)
2155 nd = ndarray([1, 2, 3], shape=[2], strides=[2], flags=ND_WRITABLE)
2183 ### >>> nd = ndarray(list(range(12)), shape=[3, 4])
2196 ### >>> nd = ndarray([0,4,8,1,5,9,2,6,10,3,7,11], shape=[3,4],
2214 ### shape=[3, 4], dtype='B')
2226 ### >>> nd = ndarray(buffer=fortran_buf, shape=[3, 4],
2238 nd = ndarray(lst, shape=[3, 4], flags=f|ND_WRITABLE)
2241 shape=[3, 4], dtype='B',
2246 x = ndarray(transpose(lst, [4, 3]), shape=[3, 4],
2261 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2269 x = ndarray(transpose(lst, [3, 4]), shape=[4, 3],
2272 x = ndarray(lst, shape=[3, 4], flags=ND_WRITABLE)
2284 y = ndarray([v for v in b], shape=[3, 4], flags=ND_FORTRAN|ND_WRITABLE)
2292 x = ndarray(lst, shape=[3, 4], flags=ND_WRITABLE)
2308 y = ndarray([v for v in b], shape=[3, 4], flags=f|ND_WRITABLE)
2315 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE|ND_PIL)
2320 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2325 x = ndarray(transpose(lst, [3, 4]), shape=[4, 3], flags=ND_WRITABLE)
2327 y = ndarray([v for v in b], shape=[3, 4], flags=ND_FORTRAN|ND_WRITABLE)
2333 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2341 for items, shape in items_shape:
2344 ex = ndarray(items, shape=shape)
2349 ndim = len(shape)
2350 strides = strides_from_shape(ndim, shape, 1, 'C')
2351 lst = carray(items, shape)
2355 ndim=ndim, shape=shape, strides=strides,
2362 ndim=ndim, shape=shape, strides=strides,
2371 ndim=ndim, shape=shape, strides=strides,
2374 # PyMemoryView_FromBuffer(): no format, shape, strides
2377 self.assertEqual(nd.shape, ())
2384 ndim=1, shape=[ex.nbytes], strides=(1,),
2388 for items, shape in items_shape:
2391 ex = ndarray(items, shape=shape, flags=ND_FORTRAN)
2396 ndim = len(shape)
2397 strides = strides_from_shape(ndim, shape, 1, 'F')
2398 lst = farray(items, shape)
2402 ndim=ndim, shape=shape, strides=strides,
2409 ndim=ndim, shape=shape, strides=strides,
2413 for items, shape in items_shape[1:]:
2416 ex = ndarray(items, shape=shape, flags=ND_PIL)
2419 ndim = len(shape)
2420 lst = carray(items, shape)
2424 ndim=ndim, shape=shape, strides=ex.strides,
2431 ndim=ndim, shape=shape, strides=ex.strides,
2439 ex = ndarray([1,2,3], shape=[3])
2446 nd = ndarray([1]*128, shape=[1]*128, format='L')
2454 # Casts are undefined if buffer is multidimensional and shape
2459 for shape in ([0,3,3], [3,0,3], [0,3,3]):
2460 ex = ndarray(items, shape=shape)
2481 a = ndarray(items, shape=[2, 4], format="b")
2483 a = ndarray(items, shape=[2, 2, 2], format="b")
2511 ex = ndarray(items, shape=[10], format=fmt, flags=ND_WRITABLE)
2512 nd = ndarray(items, shape=[10], format=fmt, flags=ND_WRITABLE)
2546 ex = ndarray([1,2,3], shape=[3], strides=[0])
2559 ex = ndarray(list(range(32)), shape=[32//ssize], format=sformat)
2564 ex = ndarray(sitems, shape=[1], format=sfmt)
2575 # invalid shape
2578 ex = ndarray(list(range(2*2*size_d)), shape=[2,2,size_d], format='h')
2580 self.assertRaises(TypeError, msrc.cast, shape=[2,2,size_h], format='d')
2582 ex = ndarray(list(range(120)), shape=[1,2,3,4,5])
2606 ex = ndarray([(1,2), (3,4)], shape=[2], format="II")
2612 # incorrect shape type
2613 ex = ndarray(list(range(120)), shape=[1,2,3,4,5])
2615 self.assertRaises(TypeError, m.cast, "B", shape={})
2617 # incorrect shape elements
2618 ex = ndarray(list(range(120)), shape=[2*3*4*5])
2620 self.assertRaises(OverflowError, m.cast, "B", shape=[2**64])
2621 self.assertRaises(ValueError, m.cast, "B", shape=[-1])
2622 self.assertRaises(ValueError, m.cast, "B", shape=[2,3,4,5,6,7,-1])
2623 self.assertRaises(ValueError, m.cast, "B", shape=[2,3,4,5,6,7,0])
2624 self.assertRaises(TypeError, m.cast, "B", shape=[2,3,4,5,6,7,'x'])
2627 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3,5,7,11])
2629 self.assertRaises(TypeError, m.cast, "I", shape=[2,3,4,5])
2632 nd = ndarray(list(range(128)), shape=[128], format='I')
2637 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3*5*7*11])
2639 self.assertRaises(TypeError, m.cast, "I", shape=[2,3,4,5])
2641 # product(shape) * itemsize != buffer size
2642 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3*5*7*11])
2644 self.assertRaises(TypeError, m.cast, "B", shape=[2,3,4,5])
2646 # product(shape) * itemsize overflow
2647 nd = ndarray(list(range(128)), shape=[128], format='I')
2649 nd = ndarray(list(range(128)), shape=[128], format='B')
2681 ndim=1, shape=[31*srcsize], strides=(1,),
2689 ndim=1, shape=[31], strides=(srcsize,),
2694 ex = ndarray(9, shape=[], format='I')
2700 ndim=1, shape=destshape, strides=(1,),
2705 ex = ndarray([9]*destsize, shape=[destsize], format='B')
2706 destitems, destshape = cast_items(ex, 'I', destsize, shape=[])
2708 m2 = m.cast('I', shape=[])
2711 ndim=0, shape=(), strides=(),
2722 ex = ndarray(items, shape=[31], format=fmt, flags=ND_WRITABLE)
2737 shape = [n] if n > 0 else []
2740 ex = ndarray(items, shape=shape, format=fmt)
2743 titems, tshape = cast_items(ex, tfmt, tsize, shape=tshape)
2752 nd = ndarray(titems, shape=tshape, format=tfmt)
2754 m2 = m.cast(tfmt, shape=tshape)
2760 ndim=ndim, shape=tshape, strides=strides,
2765 m4 = m2.cast(fmt, shape=shape)
2766 ndim = len(shape)
2772 ndim=ndim, shape=shape, strides=strides,
2777 ndim=ndim, shape=shape, strides=strides,
2791 self.assertEqual(m2.shape, (m2.nbytes,))
2802 self.assertEqual(m2.shape, (m2.nbytes,))
2820 ex = ndarray(list(range(2*3*5*7*11)), shape=[11,2,7,3,5], format='L')
2824 ex = ndarray([(2, 5), (7, 11)], shape=[2], format='lh')
2828 ex = ndarray([b'12345'], shape=[1], format="s")
2832 ex = ndarray([b"a",b"b",b"c",b"d",b"e",b"f"], shape=[2,3], format='s')
2869 ex = ndarray(12.5, shape=[], format='d')
2876 ex = ndarray((1,2,3), shape=[], format='iii')
2881 ex = ndarray(list(range(7)), shape=[7], flags=ND_WRITABLE)
2893 ex = ndarray(list(range(12)), shape=[3,4], flags=ND_WRITABLE)
2922 ex = ndarray(12.5, shape=[], format='f', flags=ND_WRITABLE)
2931 ex = ndarray(list(range(7)), shape=[7])
2936 ex = ndarray(list(range(7)), shape=[7], flags=ND_WRITABLE)
2951 ex = ndarray([1,2,3], shape=[3], format=fmt, flags=ND_WRITABLE)
2958 ex = ndarray([b'1', b'2', b'3'], shape=[3], format='c',
2964 ex = ndarray([True, False, True], shape=[3], format='?',
2971 nd = ndarray([b'x'], shape=[1], format='c', flags=ND_WRITABLE)
2975 ex = ndarray(list(range(120)), shape=[1,2,3,4,5], flags=ND_WRITABLE)
2997 ex = ndarray(list(range(1)), shape=[1], format="xL", flags=ND_WRITABLE)
3001 ex = ndarray([b'12345'], shape=[1], format="s", flags=ND_WRITABLE)
3006 ex = ndarray(list(range(12)), shape=[3,4], flags=ND_WRITABLE)
3030 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE)
3042 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE)
3060 ex1 = ndarray(list(range(12)), shape=[12], strides=[-1], offset=11,
3062 ex2 = ndarray(list(range(24)), shape=[12], strides=[2], flags=flags)
3136 if have_resize: # memoryview cannot change shape
3176 nd = ndarray([(0, 0)], shape=[1], format='l x d x', flags=ND_WRITABLE)
3201 nd1 = ndarray(1729, shape=[], format='@L')
3202 nd2 = ndarray(1729, shape=[], format='L', flags=ND_WRITABLE)
3226 nd = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE|ND_PIL)
3227 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE|ND_PIL)
3235 nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s')
3236 nd2 = ndarray((1729, 1.2, b'12345'), shape=[], format='hf5s',
3248 nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s')
3249 nd2 = ndarray((-1729, 1.2, b'12345'), shape=[], format='hf5s',
3265 nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h')
3266 nd2 = ndarray([-529, 576, -625, 676, 729], shape=[5], format='@h')
3277 nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='<i')
3278 nd2 = ndarray([-529, 576, -625, 676, 729], shape=[5], format='>h')
3289 nd1 = ndarray([-529, -625, -729], shape=[3], format='@h')
3290 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h')
3300 nd1 = ndarray([-529, -625, -729], shape=[3], format='!h')
3301 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='<l')
3311 nd1 = ndarray([-529, -625, -729], shape=[3], format='@h')
3312 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h',
3323 nd1 = ndarray([-529, -625, -729], shape=[3], format='h 0c')
3324 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='> h',
3336 # zeros in shape
3337 nd1 = ndarray([900, 961], shape=[0], format='@h')
3338 nd2 = ndarray([-900, -961], shape=[0], format='@h')
3348 # zeros in shape, struct module
3349 nd1 = ndarray([900, 961], shape=[0], format='= h0c')
3350 nd2 = ndarray([-900, -961], shape=[0], format='@ i')
3363 nd1 = ndarray([900, 900, 900, 900], shape=[4], format='@L')
3364 nd2 = ndarray([900], shape=[4], strides=[0], format='L')
3375 nd1 = ndarray([(900, 900)]*4, shape=[4], format='@ Li')
3376 nd2 = ndarray([(900, 900)], shape=[4], strides=[0], format='!L h')
3393 nd = ndarray(items, shape=[n], format=fmt, flags=flags)
3406 nd = ndarray(items, shape=[n], format=fmt, flags=flags)
3417 nd1 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='@h')
3418 nd2 = ndarray(list(range(0, 30)), shape=[3, 2, 5], format='@h')
3429 nd1 = ndarray([(0, 1, 2)]*30, shape=[3, 2, 5], format='=f q xxL')
3430 nd2 = ndarray([(-1.2, 1, 2)]*30, shape=[3, 2, 5], format='< f 2Q')
3440 # C-contiguous, different shape
3441 nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L')
3442 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='L')
3452 # C-contiguous, different shape, struct module
3453 nd1 = ndarray([(0, 1, 2)]*21, shape=[3, 7], format='! b B xL')
3454 nd2 = ndarray([(0, 1, 2)]*21, shape=[7, 3], format='= Qx l xxL')
3465 nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L')
3466 nd2 = ndarray(list(range(30)), shape=[2, 3, 5], format='l')
3479 nd1 = ndarray(list(range(-15, 15)), shape=[5, 2, 3], format='@h',
3481 nd2 = ndarray(list(range(0, 30)), shape=[5, 2, 3], format='@h',
3493 nd1 = ndarray([(2**64-1, -1)]*6, shape=[2, 3], format='=Qq',
3495 nd2 = ndarray([(-1, 2**64-1)]*6, shape=[2, 3], format='=qQ',
3506 # Fortran-contiguous, different shape
3507 nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='l',
3509 nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l',
3520 # Fortran-contiguous, different shape, struct module
3521 nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='0ll',
3523 nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l',
3535 nd1 = ndarray(list(range(30)), shape=[5, 2, 3], format='@h',
3537 nd2 = ndarray(list(range(30)), shape=[5, 2, 3], format='@b',
3553 nd1 = ndarray(lst1, shape=[3, 2, 5], format='@l')
3554 nd2 = ndarray(lst2, shape=[3, 2, 5], format='l', flags=ND_FORTRAN)
3566 nd1 = ndarray(lst1, shape=[3, 2, 5], format='d b c')
3567 nd2 = ndarray(lst2, shape=[3, 2, 5], format='d h c', flags=ND_FORTRAN)
3576 ex1 = ndarray(list(range(40)), shape=[5, 8], format='@I')
3578 ex2 = ndarray(list(range(40)), shape=[5, 8], format='I')
3590 ex1 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='=ii')
3592 ex2 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='>ii')
3603 # different shape
3604 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='b')
3606 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3617 # different shape, struct module
3618 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='B')
3620 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3632 ex1 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='b3s')
3634 nd2 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='i3s')
3647 # zeros in shape
3648 nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i')
3649 nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i')
3659 # zeros in shape, struct module
3660 nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i')
3661 nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i')
3674 nd1 = ndarray([900]*80, shape=[4, 5, 4], format='@L')
3675 nd2 = ndarray([900], shape=[4, 5, 4], strides=[0, 0, 0], format='L')
3687 nd1 = ndarray([(1, 2)]*10, shape=[2, 5], format='=lQ')
3688 nd2 = ndarray([(1, 2)], shape=[2, 5], strides=[0, 0], format='<lQ')
3701 ex1 = ndarray(list(range(40)), shape=[5, 8], format='@I')
3703 ex2 = ndarray(list(range(40)), shape=[5, 8], format='I', flags=ND_PIL)
3715 ex1 = ndarray([(2**64-1, -1)]*40, shape=[5, 8], format='=Qq',
3720 ex2 = ndarray([(2**64-1, -1)]*40, shape=[5, 8], format='>Qq',
3734 # suboffsets, different shape
3735 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='b',
3738 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3749 # suboffsets, different shape, struct module
3750 ex1 = ndarray([(2**8-1, -1)]*40, shape=[2, 3, 5], format='Bb',
3754 ex2 = ndarray([(2**8-1, -1)]*40, shape=[3, 2, 5], format='Bb')
3767 ex1 = ndarray(list(range(30)), shape=[5, 3, 2], format='i', flags=ND_PIL)
3769 ex2 = ndarray(list(range(30)), shape=[5, 3, 2], format='@I', flags=ND_PIL)
3781 ex1 = ndarray([(b'hello', b'', 1)]*27, shape=[3, 3, 3], format='5s0sP',
3786 ex2 = ndarray([(b'hello', b'', 1)]*27, shape=[3, 3, 3], format='5s0sP',
3803 nd1 = ndarray(lst1, shape=[3, 2, 5], format='@l', flags=ND_PIL)
3804 nd2 = ndarray(lst2, shape=[3, 2, 5], format='l', flags=ND_FORTRAN|ND_PIL)
3817 nd1 = ndarray(lst1, shape=[3, 2, 5], format='< 10p 9p d', flags=ND_PIL)
3818 nd2 = ndarray(lst2, shape=[3, 2, 5], format='> 10p 9p d',
3831 x = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q')
3832 y = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q',
3843 x = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2],
3845 y = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2],
3881 'shape', 'strides', 'suboffsets', 'c_contiguous',
3901 nd = ndarray(t, shape=[5], format='@h')
3906 nd = ndarray([t], shape=[1], format='>hQiLl')
3911 nd = ndarray([t for _ in range(12)], shape=[2,2,3], format='=hQiLl')
3916 nd = ndarray([t for _ in range(120)], shape=[5,2,2,3,2],
3941 nd = ndarray([1, 2, 3], shape=[2], strides=[2])
3945 nd = ndarray(9, shape=(), format="L")
3952 nd = ndarray(9, shape=(), format="L", flags=ND_WRITABLE)
3969 # zeros in shape
3970 nd = ndarray([1], shape=[0], format="L", flags=ND_WRITABLE)
3977 nd = ndarray(list(range(8)), shape=[2, 0, 7], format="L",
3984 nd = ndarray([1], shape=[1], format="h", flags=ND_WRITABLE)
3990 nd = ndarray([1, 2, 3], shape=[3], format="b", flags=ND_WRITABLE)
3997 nd = ndarray([1, 2, 3], shape=[2], strides=[2], flags=ND_WRITABLE)
4016 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE)
4025 nd = ndarray(list(range(12)), shape=[3, 4],
4036 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE|ND_PIL)
4044 nd = ndarray([1,2,3,4,5], shape=[3], strides=[2])
4061 nd = ndarray(list(range(12)), shape=[2,3,2], format="L")
4070 #nd = ndarray(list(range(12)), shape=[2,3,2], format="L",
4086 mc = m.cast('c', shape=[3,4])
4095 nd = ndarray(list(range(30)), shape=[3,2,5], flags=ND_FORTRAN)
4100 nd = ndarray(list(range(30)), shape=[3,2,5])
4106 nd = ndarray(list(range(30)), shape=[2,5,3], flags=ND_PIL)
4112 x = ndarray(list(range(12)), shape=[12], format='B')
4115 y = ndarray(list(range(12)), shape=[12], format='b')
4122 nd = ndarray(list(range(12)), shape=[2,2,3], format='L')
4126 nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='h')
4130 nd = ndarray(list(range(12)), shape=[2,2,3], format='= L')
4134 nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='< h')
4179 nd = ndarray([1,2,3], shape=[3], flags=ND_VAREXPORT)
4182 nd.push([4,5,6,7,8], shape=[5]) # mutate nd
4213 x = ndarray(list(range(12)), shape=[2,2,3], format='l')
4268 nd = ndarray([1.0 * x for x in range(12)], shape=[12], format='d')
4303 ndim=1, shape=[12], strides=[1],
4323 ndim=1, shape=[12], strides=[1],
4336 ndim=1, shape=[12], strides=[1],
4345 ndim=1, shape=[12], strides=[1],
4365 ndim=1, shape=[12], strides=[1],
4380 ndim=1, shape=[12], strides=[1],
4391 x = ndarray([1,2,3], shape=[3], flags=ND_GETBUF_FAIL)