[Piglit] [PATCH 3/6] gen_tess_input_tests.py: use numpy for random data

Dylan Baker baker.dylan.c at gmail.com
Wed Oct 7 14:27:57 PDT 2015


Python 2.x and python 3.x produce different results. This is probably a
difference between the implementations. This result is largely the same
in order of magnitude differences, but the numbers themselves are
sometimes significantly different. This might be due to the difference
between python 2 and python 3's int implementations (int in python 2 can
roll over, but it will grow to consume all memory in python 3), or it
might be due to differences in random.

When ported to numpy both python 2.x and python 3.x produce the same
result, which is very close to the value that python 3.x produces.
This produces deterministic results between python 2.x and python 3.x.

This has not been tested, i965 lacks tessalation support.
---
 generated_tests/gen_tess_input_tests.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/generated_tests/gen_tess_input_tests.py b/generated_tests/gen_tess_input_tests.py
index cf1c1aa..f4c50e6 100644
--- a/generated_tests/gen_tess_input_tests.py
+++ b/generated_tests/gen_tess_input_tests.py
@@ -32,9 +32,9 @@ Currently test for VS -> TCS and TCS -> TES are generated.
 from __future__ import print_function, absolute_import, division
 import os
 import sys
-import random
 
-from six.moves import range
+from six.moves import range  # pylint: disable=redefined-builtin
+import numpy as np
 
 from modules.utils import safe_makedirs, lazy_property
 from templates import template_dir
@@ -131,7 +131,7 @@ class TcsTest(object):
         Where n is the number of vertices times the array length and
         c is the number of components in the tested scalar data type.
         """
-        random.seed(17)
+        np.random.seed(17)
 
         if self.var_array:
             n = self.var_array * 12
@@ -139,13 +139,14 @@ class TcsTest(object):
             n = 12
 
         if self.var_type.startswith('i'):
-            rand = lambda: random.randint(-0x80000000, 0x7fffffff)
+            rand = lambda: np.random.randint(-0x80000000, 0x7fffffff)
         elif self.var_type.startswith('u'):
-            rand = lambda: random.randint(0, 0xffffffff)
+            rand = lambda: np.random.randint(0, 0xffffffff)
         else:
-            rand = lambda: ((-1 + 2 * random.randint(0, 1)) *
-                            random.randint(0, 2**23-1) *
-                            2.0**(random.randint(-126, 127)))
+            rand = lambda: ((np.int_(-1) + np.int_(2) *
+                             np.random.randint(0, 1)) *
+                            np.random.randint(0, 2**23-1) *
+                            np.float_(2.0)**(np.random.randint(-126, 127)))
 
         c = self.components()
 
@@ -293,7 +294,7 @@ class TesTest(object):
         Where n is the number of vertices times the array length and
         c is the number of components in the tested scalar data type.
         """
-        random.seed(17)
+        np.random.seed(17)
 
         if self.var_array:
             n = self.var_array * self.reference_size
@@ -301,13 +302,14 @@ class TesTest(object):
             n = self.reference_size
 
         if self.var_type.startswith('i'):
-            rand = lambda: random.randint(-0x80000000, 0x7fffffff)
+            rand = lambda: np.random.randint(-0x80000000, 0x7fffffff)
         elif self.var_type.startswith('u'):
-            rand = lambda: random.randint(0, 0xffffffff)
+            rand = lambda: np.random.randint(0, 0xffffffff)
         else:
-            rand = lambda: ((-1 + 2 * random.randint(0, 1)) *
-                            random.randint(0, 2**23-1) *
-                            2.0**(random.randint(-126, 127)))
+            rand = lambda: ((np.int_(-1) + np.int_(2) *
+                             np.random.randint(0, 1)) *
+                            np.random.randint(0, 2**23-1) *
+                            np.float_(2.0)**(np.random.randint(-126, 127)))
 
         c = self.components()
 
-- 
2.6.1



More information about the Piglit mailing list