[Piglit] [PATCH 12/34] builtin_function*py: convert to python3
Dylan Baker
baker.dylan.c at gmail.com
Fri Feb 20 18:17:59 PST 2015
This mostly adds code to make GlslBuiltinType hashable and sortable, it
also repalces xrange with six.moves.range
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
generated_tests/builtin_function.py | 27 ++++++++++++++++++++++----
generated_tests/builtin_function_fp64.py | 33 ++++++++++++++++++++++++++++----
2 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index 7f9fae1..a7407d3 100644
--- a/generated_tests/builtin_function.py
+++ b/generated_tests/builtin_function.py
@@ -50,6 +50,9 @@
import collections
import itertools
+import functools
+
+from six.moves import range
import numpy as np
@@ -66,6 +69,7 @@ UINT32_TYPES = tuple(set([np.uint32,
type(np.dot(np.uint32(0), np.uint32(0)))]))
+ at functools.total_ordering
class GlslBuiltinType(object):
"""Class representing a GLSL built-in type."""
def __init__(self, name, base_type, num_cols, num_rows,
@@ -124,6 +128,21 @@ class GlslBuiltinType(object):
"""
return self.__version_introduced
+ def __eq__(self, other):
+ if isinstance(other, GlslBuiltinType):
+ return self.name == other.name
+
+ return NotImplemented
+
+ def __lt__(self, other):
+ if isinstance(other, GlslBuiltinType):
+ return self.name < other.name
+
+ return NotImplemented
+
+ def __hash__(self):
+ return hash('__GLslBuiltinType_{}__'.format(self.name))
+
def __str__(self):
return self.__name
@@ -644,9 +663,9 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
vectors, wrap around as necessary to ensure that every input
test vector is included.
"""
- for i in xrange(0, len(test_vectors), partition_size):
+ for i in range(0, len(test_vectors), partition_size):
partition = []
- for j in xrange(partition_size):
+ for j in range(partition_size):
partition.append(test_vectors[(i + j) % len(test_vectors)])
yield partition
@@ -658,7 +677,7 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
"""
arity = len(test_vectors[0].arguments)
arguments = []
- for j in xrange(arity):
+ for j in range(arity):
if j in scalar_arg_indices:
arguments.append(test_vectors[0].arguments[j])
else:
@@ -692,7 +711,7 @@ def _store_test_vector(test_suite_dict, name, glsl_version, extension, test_vect
Signature objects generated.
"""
if template is None:
- arg_indices = xrange(len(test_vector.arguments))
+ arg_indices = range(len(test_vector.arguments))
template = '{0}({1})'.format(
name, ', '.join('{{{0}}}'.format(i) for i in arg_indices))
rettype = glsl_type_of(test_vector.result)
diff --git a/generated_tests/builtin_function_fp64.py b/generated_tests/builtin_function_fp64.py
index 6b98ec7..1bbfbd9 100644
--- a/generated_tests/builtin_function_fp64.py
+++ b/generated_tests/builtin_function_fp64.py
@@ -50,6 +50,9 @@
import collections
import itertools
+import functools
+
+from six.moves import range
import numpy as np
@@ -114,6 +117,28 @@ class GlslBuiltinType(object):
"""
return self.__version_introduced
+ def __eq__(self, other):
+ if isinstance(other, GlslBuiltinType):
+ return self.name == other.name
+
+ return NotImplemented
+
+ def __lt__(self, other):
+ if isinstance(other, GlslBuiltinType):
+ return self.name < other.name
+
+ return NotImplemented
+
+ def __hash__(self):
+ """Hash the object.
+
+ This hash isn't super awesome, but it isn't prone to change since you
+ have to muck with private (__prefixed values) and some unlikely text in
+ addition.
+
+ """
+ return hash('__GLslBuiltinType_{}__'.format(self.name))
+
def __str__(self):
return self.__name
@@ -580,9 +605,9 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
vectors, wrap around as necessary to ensure that every input
test vector is included.
"""
- for i in xrange(0, len(test_vectors), partition_size):
+ for i in range(0, len(test_vectors), partition_size):
partition = []
- for j in xrange(partition_size):
+ for j in range(partition_size):
partition.append(test_vectors[(i + j) % len(test_vectors)])
yield partition
@@ -594,7 +619,7 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
"""
arity = len(test_vectors[0].arguments)
arguments = []
- for j in xrange(arity):
+ for j in range(arity):
if j in scalar_arg_indices:
arguments.append(test_vectors[0].arguments[j])
else:
@@ -628,7 +653,7 @@ def _store_test_vector(test_suite_dict, name, glsl_version, extension, test_vect
Signature objects generated.
"""
if template is None:
- arg_indices = xrange(len(test_vector.arguments))
+ arg_indices = range(len(test_vector.arguments))
template = '{0}({1})'.format(
name, ', '.join('{{{0}}}'.format(i) for i in arg_indices))
rettype = glsl_type_of(test_vector.result)
--
2.3.0
More information about the Piglit
mailing list