You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/04/08 17:59:56 UTC

[GitHub] [beam] tvalentyn commented on a change in pull request #11092: [BEAM-9085] Fix performance regression in SyntheticSource

tvalentyn commented on a change in pull request #11092: [BEAM-9085] Fix performance regression in SyntheticSource
URL: https://github.com/apache/beam/pull/11092#discussion_r405711175
 
 

 ##########
 File path: sdks/python/apache_beam/testing/synthetic_pipeline.py
 ##########
 @@ -61,6 +65,35 @@
   np = None
 
 
+class _Random(Random):
+  """A subclass of `random.Random` from the Python Standard Library that
+  provides a method returning random bytes of arbitrary length.
+  """
+
+  # `numpy.random.RandomState` does not provide `random()` method, we keep this
+  # for compatibility reasons.
+  random_sample = Random.random
+
+  def bytes(self, length):
+    """Returns random bytes.
+
+    Args:
+      length (int): Number of random bytes.
+    """
+    n = length // 8 + 1
+    # pylint: disable=map-builtin-not-iterating
+    return struct.pack(
+        '{}Q'.format(n), *map(self.getrandbits, itertools.repeat(64,
+                                                                 n)))[:length]
+
+
+Generator = _Random
+
+# TODO: Remove this when Beam drops Python 2.
 
 Review comment:
   yes - https://issues.apache.org/jira/browse/BEAM-7372

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services