[Piglit] [PATCH v2 1/2] cl: Add generator for shuffle builtins
Dylan Baker
dylan at pnwbakers.com
Fri Sep 8 18:24:08 UTC 2017
Quoting Jan Vesely (2017-09-01 12:30:51)
[snip]
> +#
> +# Authors: Tom Stellard <thomas.stellard at amd.com>
I think we've stopped using these, anyway, it doesn't seem correct.
> +#
> +#
> +
> +from __future__ import print_function, division, absolute_import
> +import os
> +import random
> +import textwrap
> +
> +from six.moves import range
> +
> +from modules import utils
> +from genclbuiltins import MAX_VALUES, DATA_SIZES
> +
> +TYPES = {
> + 'char': 'uchar',
> + 'uchar': 'uchar',
> + 'short': 'ushort',
> + 'ushort': 'ushort',
> + 'half': 'ushort',
> + 'int': 'uint',
> + 'uint': 'uint',
> + 'float': 'uint',
> + 'long': 'ulong',
> + 'ulong': 'ulong',
> + 'double': 'ulong'
> +}
> +
> +VEC_SIZES = ['2', '4', '8', '16']
> +ELEMENTS = 8
> +
> +DIR_NAME = os.path.join("cl", "builtin", "misc")
> +
> +
> +def gen_array(size, m):
> + return [random.randint(0, m) for i in range(size)]
> +
> +
> +def permute(data, mask, ssize, dsize):
> + ret = []
> + for i in range(len(mask)):
> + idx = mask[i] % ssize
> + ret.append(data[idx + ((i // dsize) * ssize)])
enumerate would be more efficient and idiomatic
for i, m in enumerate(mask):
idx = m % size
...
Alternatively if you like more functional approaches:
return [data[(m % ssize) + ((i // dsize) * ssize)]
for i, m in enumerate(mask)]
You could even inline this approach if you want, since there's only one caller
> + return ret
> +
> +
[snip]
Otherwise the python aspects look good to me. With either change:
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20170908/15c51a1f/attachment.sig>
More information about the Piglit
mailing list