Lines Matching refs:shape

264 def strides_from_shape(ndim, shape, itemsize, layout):
270 strides = list(shape[1:]) + [itemsize]
274 strides = [itemsize] + list(shape[:-1])
281 multidimensional C array with shape 's'."""
295 multidimensional Fortran array with shape 's'."""
306 def carray(items, shape):
307 if listp(items) and not 0 in shape and prod(shape) != len(items):
308 raise ValueError("prod(shape) != len(items)")
309 return _ca(items, shape)
311 def farray(items, shape):
312 if listp(items) and not 0 in shape and prod(shape) != len(items):
313 raise ValueError("prod(shape) != len(items)")
314 return _fa(items, shape)
316 def indices(shape):
318 iterables = [range(v) for v in shape]
328 def transpose(src, shape):
330 matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """
331 if not shape:
333 ndim = len(shape)
334 sstrides = strides_from_shape(ndim, shape, 1, 'C')
335 dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C')
337 for ind in indices(shape):
358 """Get the shape of lst after slicing: slices is a list of slice
420 # - shape can be zero
432 # t = (memlen, itemsize, ndim, shape, strides, offset)
435 def verify_structure(memlen, itemsize, ndim, shape, strides, offset):
450 return ndim == 0 and not shape and not strides
451 if 0 in shape:
454 imin = sum(strides[j]*(shape[j]-1) for j in range(ndim)
456 imax = sum(strides[j]*(shape[j]-1) for j in range(ndim)
468 memlen, itemsize, ndim, shape, strides, offset = t
478 memlen, itemsize, ndim, shape, strides, offset = t
480 for ind in indices(shape):
488 def rand_structure(itemsize, valid, maxdim=5, maxshape=16, shape=()):
490 (memlen, itemsize, ndim, shape, strides, offset)
492 If 'shape' is given, use that instead of creating a random shape.
494 if not shape:
511 shape = [0] * ndim
514 shape[i] = randrange(minshape, maxshape+1)
516 ndim = len(shape)
528 maxstride *= shape[i+1] if shape[i+1] else 1
536 if not 0 in shape:
537 imin = sum(strides[j]*(shape[j]-1) for j in range(ndim)
539 imax = sum(strides[j]*(shape[j]-1) for j in range(ndim)
549 return memlen, itemsize, ndim, shape, strides, offset
564 def randslice_from_shape(ndim, shape):
565 """Create two sets of slices for an array x with shape 'shape'
570 l = shape[n]
579 with shape 'lshape' and y is an array with shape 'rshape'."""
627 memlen, itemsize, ndim, shape, strides, offset = t
628 return ndarray(items, shape=shape, strides=strides, format=fmt,
633 memlen, itemsize, ndim, shape, strides, offset = t
637 return numpy_array(buffer=buf, shape=shape, strides=strides,
645 def cast_items(exporter, fmt, itemsize, shape=None):
647 size 'itemsize'. If shape=None, the new structure is assumed to
648 be 1-D with n * itemsize = bytelen. If shape is given, the usual
649 constraint for contiguous arrays prod(shape) * itemsize = bytelen
650 applies. On success, return (items, shape). If the constraints
654 if shape:
655 if prod(shape) * itemsize != bytelen:
656 return None, shape
657 elif shape == []:
659 return None, shape
662 shape = [n]
664 return None, shape
673 return 'nan', shape
676 return (items, shape) if shape != [] else (items[0], shape)
698 def genslices_ndim(ndim, shape):
699 """Generate all possible slice tuples for 'shape'."""
700 iterables = [genslices(shape[n]) for n in range(ndim)]
716 def rslices_ndim(ndim, shape, iterations=5):
717 """Generate random slice tuples for 'shape'."""
720 yield tuple(rslice(shape[n]) for n in range(ndim))
723 yield tuple(rslice(shape[n], allow_empty=True) for n in range(ndim))
744 print("ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, "
746 (x, nd.shape, nd.strides, nd.suboffsets, offset,
774 ndim, shape, strides,
777 if shape:
778 expected_len = prod(shape)*itemsize
793 if shape[n] == 0:
796 suboffset0 += -strides[n] * (shape[n]-1)
812 self.assertEqual(result.shape, tuple(shape))
833 for ind in indices(shape):
871 trans = transpose(flattened, shape)
872 expected = ndarray(trans, shape=shape, format=ff,
878 expected = ndarray(flattened, shape=shape, format=ff)
901 y = ndarray(initlst, shape=shape, flags=ro, format=fmt)
921 y = ndarray(initlst, shape=shape, flags=ro|ND_FORTRAN,
937 y = ndarray(initlst, shape=shape, flags=f|ro, format=fmt)
957 self.assertEqual(m.shape, tuple(shape))
1007 # The equality product(shape) * itemsize = len still holds.
1013 shape = orig_ex.shape if match(req, PyBUF_ND) else ()
1019 ndim=ndim, shape=shape, strides=strides,
1040 # shape, strides, offset
1064 for shape, strides, offset in structure:
1071 if not shape and (flags&ND_PIL):
1074 _items = items if shape else items[0]
1076 shape=shape, strides=strides, offset=offset)
1077 ex2 = ex1[::-2] if shape else None
1082 if ex1.ndim == 0 or (ex1.ndim == 1 and shape and strides):
1084 if ex2 and ex2.ndim == 1 and shape and strides:
1100 ex = ndarray(items, shape=[12], flags=ND_GETBUF_FAIL)
1116 for shape in [1,12,1], [7,0,7]:
1118 ex = ndarray(items, shape=shape, flags=order|ND_WRITABLE)
1137 self.assertRaises(TypeError, c, [1,2,3], shape={3})
1138 self.assertRaises(TypeError, c, [1,2,3], shape=[3], strides={1})
1139 self.assertRaises(TypeError, c, [1,2,3], shape=[3], offset=[])
1140 self.assertRaises(TypeError, c, [1], shape=[1], format={})
1141 self.assertRaises(TypeError, c, [1], shape=[1], flags={})
1142 self.assertRaises(TypeError, c, [1], shape=[1], getbuf={})
1145 self.assertRaises(TypeError, c, [1], shape=[1], strides=[1],
1149 self.assertRaises(TypeError, c, [1], shape=[], flags=ND_PIL)
1152 self.assertRaises(ValueError, c, [], shape=[1])
1153 self.assertRaises(ValueError, c, ['XXX'], shape=[1], format="L")
1155 self.assertRaises(struct.error, c, [1000], shape=[1], format="B")
1156 self.assertRaises(ValueError, c, [1,(2,3)], shape=[2], format="B")
1157 self.assertRaises(ValueError, c, [1,2,3], shape=[3], format="QL")
1161 self.assertRaises(ValueError, c, [1]*n, shape=[1]*n)
1163 # Invalid shape.
1164 self.assertRaises(ValueError, c, [1], shape=[-1])
1165 self.assertRaises(ValueError, c, [1,2,3], shape=['3'])
1166 self.assertRaises(OverflowError, c, [1], shape=[2**128])
1167 # prod(shape) * itemsize != len(items)
1168 self.assertRaises(ValueError, c, [1,2,3,4,5], shape=[2,2], offset=3)
1171 self.assertRaises(ValueError, c, [1,2,3], shape=[3], strides=['1'])
1172 self.assertRaises(OverflowError, c, [1], shape=[1],
1175 # Invalid combination of strides and shape.
1176 self.assertRaises(ValueError, c, [1,2], shape=[2,1], strides=[1])
1178 self.assertRaises(ValueError, c, [1,2,3,4], shape=[2], strides=[3],
1182 self.assertRaises(ValueError, c, [1,2,3], shape=[3], offset=4)
1183 self.assertRaises(ValueError, c, [1,2,3], shape=[1], offset=3,
1187 self.assertRaises(ValueError, c, [1,2,3], shape=[3], format="")
1188 self.assertRaises(struct.error, c, [(1,2,3)], shape=[1],
1193 self.assertRaises(ValueError, c, items, shape=[2,3],
1200 self.assertRaises(TypeError, c, [1], shape=[1], getbuf=PyBUF_FULL)
1235 nd = ndarray(list(range(100)), shape=[1]*100)
1238 nd = ndarray(list(range(12)), shape=[3,4])
1245 ex = ndarray([1,2,3], shape=[3], format='L')
1250 ex1 = ndarray([1,2,3], shape=[3], format='L')
1255 nd = ndarray([(1,)*200], shape=[1], format='L'*200)
1259 nd = ndarray(list(range(n)), shape=[1]*n)
1263 nd = ndarray([1], shape=[1])
1274 nd = ndarray([1], shape=[1])
1280 nd = ndarray([1], shape=[1])
1288 nd = ndarray([1,2,3], shape=[3], flags=ND_VAREXPORT)
1292 nd.push([1,2,3], shape=[3])
1305 nd = ndarray(scalar, shape=(), format=fmt)
1308 ndim=0, shape=(), strides=(),
1312 # ndim = 1, shape = [n]
1317 nd = ndarray(items, shape=[nitems], format=fmt, flags=flags)
1320 ndim=1, shape=(nitems,), strides=(itemsize,),
1332 shape = [len(items[::step])]
1337 nd = ndarray(items, shape=shape, strides=strides,
1341 ndim=1, shape=shape, strides=strides,
1346 ex = ndarray(items, shape=(3, 4), strides=(1, 3))
1354 for shape in permutations(shape_t):
1364 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1366 strides = strides_from_shape(ndim, shape, itemsize, 'C')
1367 lst = carray(items, shape)
1370 ndim=ndim, shape=shape, strides=strides,
1375 ex = ndarray(items, shape=shape, format=fmt)
1381 ndim=ndim, shape=shape, strides=strides,
1385 nd = ndarray(items, shape=shape, format=fmt,
1388 strides = strides_from_shape(ndim, shape, itemsize, 'F')
1389 lst = farray(items, shape)
1392 ndim=ndim, shape=shape, strides=strides,
1397 nd = ndarray([1], shape=[1])
1404 nd = ndarray([1], shape=[1], flags=ND_WRITABLE)
1411 nd = ndarray([1], shape=[1], flags=ND_WRITABLE)
1421 nd = ndarray(items, shape=[len(items)], format="B", flags=ND_WRITABLE)
1430 nd = ndarray(items, shape=[len(items)], format="LQ", flags=ND_WRITABLE)
1436 nd = ndarray(1, shape=(), flags=ND_WRITABLE)
1461 ex = ndarray(list(range(2*4)), shape=[2, 4], flags=ND_WRITABLE)
1472 nd = ndarray(items, shape=[5], format=fmt)
1490 ex = ndarray(items, shape=[5], flags=ND_WRITABLE, format=fmt)
1504 ex = ndarray(items, shape=[5])
1509 # getitem with null shape/strides/format
1511 ex = ndarray(items, shape=[5])
1520 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1532 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1546 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1555 nd = ndarray(items, shape=[5], format=fmt, flags=ND_WRITABLE)
1566 for shape in permutations(shape_t):
1572 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1573 lst = carray(items, shape)
1575 for i in range(-shape[0], shape[0]):
1577 for j in range(-shape[1], shape[1]):
1579 for k in range(-shape[2], shape[2]):
1583 nd = ndarray(items, shape=shape, format=fmt,
1585 lst = farray(items, shape)
1587 for i in range(-shape[0], shape[0]):
1589 for j in range(-shape[1], shape[1]):
1591 for k in range(shape[2], shape[2]):
1595 nd = ndarray(1, shape=())
1602 nd = ndarray(items, shape=[5], format=fmt)
1617 xl = ndarray(items, shape=[8], flags=ND_WRITABLE)
1623 xl = ndarray(items, shape=[8], flags=ND_WRITABLE)
1624 ex = ndarray(items, shape=[8], flags=ND_WRITABLE)
1629 nd = ndarray(items, shape=[8], format="L", flags=ND_WRITABLE)
1634 nd = ndarray(items, shape=[2,4], format="L", flags=ND_WRITABLE)
1651 xl = ndarray(items, shape=[8], format="B", flags=ND_WRITABLE)
1652 xr = ndarray(items, shape=[8], format="b")
1661 xl = ndarray(items, shape=[8], format="B", flags=ND_WRITABLE)
1662 yr = ndarray(items, shape=[8], format="L")
1671 xl = ndarray(items, shape=[2, 4], format="b", flags=ND_WRITABLE)
1672 xr = ndarray(items, shape=[8], format="b")
1680 # differing shape
1681 xl = ndarray(items, shape=[8], format="b", flags=ND_WRITABLE)
1682 xr = ndarray(items, shape=[8], format="b")
1695 x = ndarray(items, shape=[8], format="b", flags=ND_PIL)
1698 ex = ndarray(items, shape=[8], format="B")
1705 x = ndarray(items, shape=[12], format="L", flags=ND_WRITABLE)
1706 y = ndarray(items, shape=[12], format="L")
1717 x = ndarray(items, shape=[3, 4], format="L", flags=ND_WRITABLE)
1718 y = ndarray(items, shape=[4, 3], format="L")
1726 for shape in permutations(shape_t):
1732 nd = ndarray(items, shape=shape, format=fmt, flags=flags)
1733 lst = carray(items, shape)
1735 for slices in rslices_ndim(ndim, shape):
1758 for shape in permutations(shape_t):
1763 nd = ndarray(items, shape=shape, format=fmt)
1765 ex = ndarray(items, shape=shape, format=fmt)
1768 lst = carray(items, shape)
1770 for slices in rslices_ndim(ndim, shape):
1796 nd = ndarray(items, shape=[5], format=fmt, flags=f)
1797 ex = ndarray(items, shape=[5], format=fmt, flags=f)
1817 if diff_structure: # ndarray cannot change shape
1832 if diff_structure: # memoryview cannot change shape
1840 ndim=nd.ndim, shape=nd.shape, strides=nd.strides,
1847 for shape in permutations(shape_t):
1853 lslices, rslices = randslice_from_shape(ndim, shape)
1855 nd = ndarray(items, shape=shape, format=fmt,
1857 lst = carray(items, shape)
1908 shape = t[3]
1909 if 0 in shape:
1914 ndim=z.ndim, shape=z.shape, strides=z.strides,
1953 tl = rand_structure(itemsize, True, shape=lshape)
1954 tr = rand_structure(itemsize, True, shape=rshape)
1999 ndim=zl.ndim, shape=zl.shape,
2004 ndim=zr.ndim, shape=zr.shape,
2010 nd = ndarray(items, shape=[3,4], flags=ND_PIL)
2021 # zeros in shape
2023 nd = ndarray([1,2,3], shape=[0], flags=flags)
2029 nd = ndarray([1,2,3], shape=[0,3,3], flags=flags)
2032 nd = ndarray([1,2,3], shape=[3,0,3], flags=flags)
2035 nd = ndarray([1,2,3], shape=[3,3,0], flags=flags)
2042 nd = ndarray([1], shape=[5], strides=[0], flags=flags)
2049 nd = ndarray(list(range(20)), shape=[3], offset=7)
2055 nd = ndarray(list(range(3)), shape=[3], flags=flags)
2061 nd = ndarray(list(range(3)), shape=[3], flags=flags)
2066 ex = ndarray(list(range(20)), shape=[2,2,5])
2078 x = ndarray(list(range(12)), shape=[3,4])
2079 y = ndarray(list(range(12)), shape=[4,3])
2082 x = ndarray([1], shape=[1], format="B")
2095 nd = ndarray(list(range(12)), shape=[12])
2099 nd = ndarray(list(range(12)), shape=[3,4])
2102 nd = ndarray(list(range(12)), shape=[3,2,2])
2106 b = bytes(transpose(list(range(12)), shape=[4,3]))
2107 nd = ndarray(list(range(12)), shape=[3,4], flags=ND_FORTRAN)
2110 b = bytes(transpose(list(range(12)), shape=[2,3,2]))
2111 nd = ndarray(list(range(12)), shape=[2,3,2], flags=ND_FORTRAN)
2116 nd = ndarray(list(range(12)), shape=[2,2,3], flags=ND_PIL)
2120 nd = ndarray(list(range(12)), shape=[2,2,3], format='L')
2142 nd = ndarray(9, shape=(), format="L", flags=ND_WRITABLE)
2148 # zeros in shape
2149 nd = ndarray([1], shape=[0], format="L", flags=ND_WRITABLE)
2155 nd = ndarray(list(range(8)), shape=[2, 0, 7], format="L",
2167 nd = ndarray([1], shape=[1], format="h", flags=f|ND_WRITABLE)
2174 nd = ndarray([1, 2, 3], shape=[3], format="b", flags=f|ND_WRITABLE)
2182 nd = ndarray([1, 2, 3], shape=[2], strides=[2], flags=ND_WRITABLE)
2210 ### >>> nd = ndarray(list(range(12)), shape=[3, 4])
2223 ### >>> nd = ndarray([0,4,8,1,5,9,2,6,10,3,7,11], shape=[3,4],
2241 ### shape=[3, 4], dtype='B')
2253 ### >>> nd = ndarray(buffer=fortran_buf, shape=[3, 4],
2265 nd = ndarray(lst, shape=[3, 4], flags=f|ND_WRITABLE)
2268 shape=[3, 4], dtype='B',
2273 x = ndarray(transpose(lst, [4, 3]), shape=[3, 4],
2288 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2296 x = ndarray(transpose(lst, [3, 4]), shape=[4, 3],
2299 x = ndarray(lst, shape=[3, 4], flags=ND_WRITABLE)
2311 y = ndarray([v for v in b], shape=[3, 4], flags=ND_FORTRAN|ND_WRITABLE)
2319 x = ndarray(lst, shape=[3, 4], flags=ND_WRITABLE)
2335 y = ndarray([v for v in b], shape=[3, 4], flags=f|ND_WRITABLE)
2342 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE|ND_PIL)
2347 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2352 x = ndarray(transpose(lst, [3, 4]), shape=[4, 3], flags=ND_WRITABLE)
2354 y = ndarray([v for v in b], shape=[3, 4], flags=ND_FORTRAN|ND_WRITABLE)
2360 y = ndarray([v for v in b], shape=[3, 4], flags=ND_WRITABLE)
2368 for items, shape in items_shape:
2371 ex = ndarray(items, shape=shape)
2376 ndim = len(shape)
2377 strides = strides_from_shape(ndim, shape, 1, 'C')
2378 lst = carray(items, shape)
2382 ndim=ndim, shape=shape, strides=strides,
2389 ndim=ndim, shape=shape, strides=strides,
2398 ndim=ndim, shape=shape, strides=strides,
2401 # PyMemoryView_FromBuffer(): no format, shape, strides
2404 self.assertEqual(nd.shape, ())
2411 ndim=1, shape=[ex.nbytes], strides=(1,),
2415 for items, shape in items_shape:
2418 ex = ndarray(items, shape=shape, flags=ND_FORTRAN)
2423 ndim = len(shape)
2424 strides = strides_from_shape(ndim, shape, 1, 'F')
2425 lst = farray(items, shape)
2429 ndim=ndim, shape=shape, strides=strides,
2436 ndim=ndim, shape=shape, strides=strides,
2440 for items, shape in items_shape[1:]:
2443 ex = ndarray(items, shape=shape, flags=ND_PIL)
2446 ndim = len(shape)
2447 lst = carray(items, shape)
2451 ndim=ndim, shape=shape, strides=ex.strides,
2458 ndim=ndim, shape=shape, strides=ex.strides,
2466 ex = ndarray([1,2,3], shape=[3])
2473 nd = ndarray([1]*128, shape=[1]*128, format='L')
2481 # Casts are undefined if buffer is multidimensional and shape
2486 for shape in ([0,3,3], [3,0,3], [0,3,3]):
2487 ex = ndarray(items, shape=shape)
2508 a = ndarray(items, shape=[2, 4], format="b")
2510 a = ndarray(items, shape=[2, 2, 2], format="b")
2538 ex = ndarray(items, shape=[10], format=fmt, flags=ND_WRITABLE)
2539 nd = ndarray(items, shape=[10], format=fmt, flags=ND_WRITABLE)
2573 ex = ndarray([1,2,3], shape=[3], strides=[0])
2586 ex = ndarray(list(range(32)), shape=[32//ssize], format=sformat)
2591 ex = ndarray(sitems, shape=[1], format=sfmt)
2602 # invalid shape
2605 ex = ndarray(list(range(2*2*size_d)), shape=[2,2,size_d], format='h')
2607 self.assertRaises(TypeError, msrc.cast, shape=[2,2,size_h], format='d')
2609 ex = ndarray(list(range(120)), shape=[1,2,3,4,5])
2633 ex = ndarray([(1,2), (3,4)], shape=[2], format="II")
2639 # incorrect shape type
2640 ex = ndarray(list(range(120)), shape=[1,2,3,4,5])
2642 self.assertRaises(TypeError, m.cast, "B", shape={})
2644 # incorrect shape elements
2645 ex = ndarray(list(range(120)), shape=[2*3*4*5])
2647 self.assertRaises(OverflowError, m.cast, "B", shape=[2**64])
2648 self.assertRaises(ValueError, m.cast, "B", shape=[-1])
2649 self.assertRaises(ValueError, m.cast, "B", shape=[2,3,4,5,6,7,-1])
2650 self.assertRaises(ValueError, m.cast, "B", shape=[2,3,4,5,6,7,0])
2651 self.assertRaises(TypeError, m.cast, "B", shape=[2,3,4,5,6,7,'x'])
2654 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3,5,7,11])
2656 self.assertRaises(TypeError, m.cast, "I", shape=[2,3,4,5])
2659 nd = ndarray(list(range(128)), shape=[128], format='I')
2664 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3*5*7*11])
2666 self.assertRaises(TypeError, m.cast, "I", shape=[2,3,4,5])
2668 # product(shape) * itemsize != buffer size
2669 ex = ndarray(list([9 for _ in range(3*5*7*11)]), shape=[3*5*7*11])
2671 self.assertRaises(TypeError, m.cast, "B", shape=[2,3,4,5])
2673 # product(shape) * itemsize overflow
2674 nd = ndarray(list(range(128)), shape=[128], format='I')
2676 nd = ndarray(list(range(128)), shape=[128], format='B')
2708 ndim=1, shape=[31*srcsize], strides=(1,),
2716 ndim=1, shape=[31], strides=(srcsize,),
2721 ex = ndarray(9, shape=[], format='I')
2727 ndim=1, shape=destshape, strides=(1,),
2732 ex = ndarray([9]*destsize, shape=[destsize], format='B')
2733 destitems, destshape = cast_items(ex, 'I', destsize, shape=[])
2735 m2 = m.cast('I', shape=[])
2738 ndim=0, shape=(), strides=(),
2749 ex = ndarray(items, shape=[31], format=fmt, flags=ND_WRITABLE)
2768 shape = [n] if n > 0 else []
2771 ex = ndarray(items, shape=shape, format=fmt)
2774 titems, tshape = cast_items(ex, tfmt, tsize, shape=tshape)
2783 nd = ndarray(titems, shape=tshape, format=tfmt)
2785 m2 = m.cast(tfmt, shape=tshape)
2791 ndim=ndim, shape=tshape, strides=strides,
2796 m4 = m2.cast(fmt, shape=shape)
2797 ndim = len(shape)
2803 ndim=ndim, shape=shape, strides=strides,
2808 ndim=ndim, shape=shape, strides=strides,
2822 self.assertEqual(m2.shape, (m2.nbytes,))
2833 self.assertEqual(m2.shape, (m2.nbytes,))
2851 ex = ndarray(list(range(2*3*5*7*11)), shape=[11,2,7,3,5], format='L')
2855 ex = ndarray([(2, 5), (7, 11)], shape=[2], format='lh')
2859 ex = ndarray([b'12345'], shape=[1], format="s")
2863 ex = ndarray([b"a",b"b",b"c",b"d",b"e",b"f"], shape=[2,3], format='s')
2900 ex = ndarray(12.5, shape=[], format='d')
2907 ex = ndarray((1,2,3), shape=[], format='iii')
2912 ex = ndarray(list(range(7)), shape=[7], flags=ND_WRITABLE)
2924 ex = ndarray(list(range(12)), shape=[3,4], flags=ND_WRITABLE)
2953 ex = ndarray(12.5, shape=[], format='f', flags=ND_WRITABLE)
2962 ex = ndarray(list(range(7)), shape=[7])
2967 ex = ndarray(list(range(7)), shape=[7], flags=ND_WRITABLE)
2982 ex = ndarray([1,2,3], shape=[3], format=fmt, flags=ND_WRITABLE)
2989 ex = ndarray([b'1', b'2', b'3'], shape=[3], format='c',
2995 ex = ndarray([True, False, True], shape=[3], format='?',
3002 nd = ndarray([b'x'], shape=[1], format='c', flags=ND_WRITABLE)
3006 ex = ndarray(list(range(120)), shape=[1,2,3,4,5], flags=ND_WRITABLE)
3028 ex = ndarray(list(range(1)), shape=[1], format="xL", flags=ND_WRITABLE)
3032 ex = ndarray([b'12345'], shape=[1], format="s", flags=ND_WRITABLE)
3037 ex = ndarray(list(range(12)), shape=[3,4], flags=ND_WRITABLE)
3061 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE)
3073 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE)
3091 ex1 = ndarray(list(range(12)), shape=[12], strides=[-1], offset=11,
3093 ex2 = ndarray(list(range(24)), shape=[12], strides=[2], flags=flags)
3167 if have_resize: # memoryview cannot change shape
3207 nd = ndarray([(0, 0)], shape=[1], format='l x d x', flags=ND_WRITABLE)
3232 nd1 = ndarray(1729, shape=[], format='@L')
3233 nd2 = ndarray(1729, shape=[], format='L', flags=ND_WRITABLE)
3257 nd = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE|ND_PIL)
3258 ex = ndarray(list(range(12)), shape=[12], flags=ND_WRITABLE|ND_PIL)
3266 nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s')
3267 nd2 = ndarray((1729, 1.2, b'12345'), shape=[], format='hf5s',
3279 nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s')
3280 nd2 = ndarray((-1729, 1.2, b'12345'), shape=[], format='hf5s',
3296 nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h')
3297 nd2 = ndarray([-529, 576, -625, 676, 729], shape=[5], format='@h')
3308 nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='<i')
3309 nd2 = ndarray([-529, 576, -625, 676, 729], shape=[5], format='>h')
3320 nd1 = ndarray([-529, -625, -729], shape=[3], format='@h')
3321 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h')
3331 nd1 = ndarray([-529, -625, -729], shape=[3], format='!h')
3332 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='<l')
3342 nd1 = ndarray([-529, -625, -729], shape=[3], format='@h')
3343 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h',
3354 nd1 = ndarray([-529, -625, -729], shape=[3], format='h 0c')
3355 nd2 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='> h',
3367 # zeros in shape
3368 nd1 = ndarray([900, 961], shape=[0], format='@h')
3369 nd2 = ndarray([-900, -961], shape=[0], format='@h')
3379 # zeros in shape, struct module
3380 nd1 = ndarray([900, 961], shape=[0], format='= h0c')
3381 nd2 = ndarray([-900, -961], shape=[0], format='@ i')
3394 nd1 = ndarray([900, 900, 900, 900], shape=[4], format='@L')
3395 nd2 = ndarray([900], shape=[4], strides=[0], format='L')
3406 nd1 = ndarray([(900, 900)]*4, shape=[4], format='@ Li')
3407 nd2 = ndarray([(900, 900)], shape=[4], strides=[0], format='!L h')
3424 nd = ndarray(items, shape=[n], format=fmt, flags=flags)
3437 nd = ndarray(items, shape=[n], format=fmt, flags=flags)
3448 nd1 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='@h')
3449 nd2 = ndarray(list(range(0, 30)), shape=[3, 2, 5], format='@h')
3460 nd1 = ndarray([(0, 1, 2)]*30, shape=[3, 2, 5], format='=f q xxL')
3461 nd2 = ndarray([(-1.2, 1, 2)]*30, shape=[3, 2, 5], format='< f 2Q')
3471 # C-contiguous, different shape
3472 nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L')
3473 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='L')
3483 # C-contiguous, different shape, struct module
3484 nd1 = ndarray([(0, 1, 2)]*21, shape=[3, 7], format='! b B xL')
3485 nd2 = ndarray([(0, 1, 2)]*21, shape=[7, 3], format='= Qx l xxL')
3496 nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L')
3497 nd2 = ndarray(list(range(30)), shape=[2, 3, 5], format='l')
3510 nd1 = ndarray(list(range(-15, 15)), shape=[5, 2, 3], format='@h',
3512 nd2 = ndarray(list(range(0, 30)), shape=[5, 2, 3], format='@h',
3524 nd1 = ndarray([(2**64-1, -1)]*6, shape=[2, 3], format='=Qq',
3526 nd2 = ndarray([(-1, 2**64-1)]*6, shape=[2, 3], format='=qQ',
3537 # Fortran-contiguous, different shape
3538 nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='l',
3540 nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l',
3551 # Fortran-contiguous, different shape, struct module
3552 nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='0ll',
3554 nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l',
3566 nd1 = ndarray(list(range(30)), shape=[5, 2, 3], format='@h',
3568 nd2 = ndarray(list(range(30)), shape=[5, 2, 3], format='@b',
3584 nd1 = ndarray(lst1, shape=[3, 2, 5], format='@l')
3585 nd2 = ndarray(lst2, shape=[3, 2, 5], format='l', flags=ND_FORTRAN)
3597 nd1 = ndarray(lst1, shape=[3, 2, 5], format='d b c')
3598 nd2 = ndarray(lst2, shape=[3, 2, 5], format='d h c', flags=ND_FORTRAN)
3607 ex1 = ndarray(list(range(40)), shape=[5, 8], format='@I')
3609 ex2 = ndarray(list(range(40)), shape=[5, 8], format='I')
3621 ex1 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='=ii')
3623 ex2 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='>ii')
3634 # different shape
3635 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='b')
3637 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3648 # different shape, struct module
3649 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='B')
3651 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3663 ex1 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='b3s')
3665 nd2 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='i3s')
3678 # zeros in shape
3679 nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i')
3680 nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i')
3690 # zeros in shape, struct module
3691 nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i')
3692 nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i')
3705 nd1 = ndarray([900]*80, shape=[4, 5, 4], format='@L')
3706 nd2 = ndarray([900], shape=[4, 5, 4], strides=[0, 0, 0], format='L')
3718 nd1 = ndarray([(1, 2)]*10, shape=[2, 5], format='=lQ')
3719 nd2 = ndarray([(1, 2)], shape=[2, 5], strides=[0, 0], format='<lQ')
3732 ex1 = ndarray(list(range(40)), shape=[5, 8], format='@I')
3734 ex2 = ndarray(list(range(40)), shape=[5, 8], format='I', flags=ND_PIL)
3746 ex1 = ndarray([(2**64-1, -1)]*40, shape=[5, 8], format='=Qq',
3751 ex2 = ndarray([(2**64-1, -1)]*40, shape=[5, 8], format='>Qq',
3765 # suboffsets, different shape
3766 ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='b',
3769 nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b')
3780 # suboffsets, different shape, struct module
3781 ex1 = ndarray([(2**8-1, -1)]*40, shape=[2, 3, 5], format='Bb',
3785 ex2 = ndarray([(2**8-1, -1)]*40, shape=[3, 2, 5], format='Bb')
3798 ex1 = ndarray(list(range(30)), shape=[5, 3, 2], format='i', flags=ND_PIL)
3800 ex2 = ndarray(list(range(30)), shape=[5, 3, 2], format='@I', flags=ND_PIL)
3812 ex1 = ndarray([(b'hello', b'', 1)]*27, shape=[3, 3, 3], format='5s0sP',
3817 ex2 = ndarray([(b'hello', b'', 1)]*27, shape=[3, 3, 3], format='5s0sP',
3834 nd1 = ndarray(lst1, shape=[3, 2, 5], format='@l', flags=ND_PIL)
3835 nd2 = ndarray(lst2, shape=[3, 2, 5], format='l', flags=ND_FORTRAN|ND_PIL)
3848 nd1 = ndarray(lst1, shape=[3, 2, 5], format='< 10p 9p d', flags=ND_PIL)
3849 nd2 = ndarray(lst2, shape=[3, 2, 5], format='> 10p 9p d',
3862 x = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q')
3863 y = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q',
3874 x = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2],
3876 y = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2],
3912 'shape', 'strides', 'suboffsets', 'c_contiguous',
3932 nd = ndarray(t, shape=[5], format='@h')
3937 nd = ndarray([t], shape=[1], format='>hQiLl')
3942 nd = ndarray([t for _ in range(12)], shape=[2,2,3], format='=hQiLl')
3947 nd = ndarray([t for _ in range(120)], shape=[5,2,2,3,2],
3972 nd = ndarray([1, 2, 3], shape=[2], strides=[2])
3976 nd = ndarray(9, shape=(), format="L")
3983 nd = ndarray(9, shape=(), format="L", flags=ND_WRITABLE)
4000 # zeros in shape
4001 nd = ndarray([1], shape=[0], format="L", flags=ND_WRITABLE)
4008 nd = ndarray(list(range(8)), shape=[2, 0, 7], format="L",
4015 nd = ndarray([1], shape=[1], format="h", flags=ND_WRITABLE)
4021 nd = ndarray([1, 2, 3], shape=[3], format="b", flags=ND_WRITABLE)
4028 nd = ndarray([1, 2, 3], shape=[2], strides=[2], flags=ND_WRITABLE)
4047 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE)
4056 nd = ndarray(list(range(12)), shape=[3, 4],
4067 nd = ndarray(list(range(12)), shape=[3, 4], flags=ND_WRITABLE|ND_PIL)
4075 nd = ndarray([1,2,3,4,5], shape=[3], strides=[2])
4092 nd = ndarray(list(range(12)), shape=[2,3,2], format="L")
4101 #nd = ndarray(list(range(12)), shape=[2,3,2], format="L",
4117 mc = m.cast('c', shape=[3,4])
4126 nd = ndarray(list(range(30)), shape=[3,2,5], flags=ND_FORTRAN)
4131 nd = ndarray(list(range(30)), shape=[3,2,5])
4137 nd = ndarray(list(range(30)), shape=[2,5,3], flags=ND_PIL)
4143 x = ndarray(list(range(12)), shape=[12], format='B')
4146 y = ndarray(list(range(12)), shape=[12], format='b')
4153 nd = ndarray(list(range(12)), shape=[2,2,3], format='L')
4157 nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='h')
4161 nd = ndarray(list(range(12)), shape=[2,2,3], format='= L')
4165 nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='< h')
4210 nd = ndarray([1,2,3], shape=[3], flags=ND_VAREXPORT)
4213 nd.push([4,5,6,7,8], shape=[5]) # mutate nd
4244 x = ndarray(list(range(12)), shape=[2,2,3], format='l')
4299 nd = ndarray([1.0 * x for x in range(12)], shape=[12], format='d')
4334 ndim=1, shape=[12], strides=[1],
4354 ndim=1, shape=[12], strides=[1],
4367 ndim=1, shape=[12], strides=[1],
4376 ndim=1, shape=[12], strides=[1],
4396 ndim=1, shape=[12], strides=[1],
4411 ndim=1, shape=[12], strides=[1],
4422 x = ndarray([1,2,3], shape=[3], flags=ND_GETBUF_FAIL)