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 09:46:03 UTC

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

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

 ##########
 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:
   @tvalentyn Do we have a JIRA issue that accumulates all things that have to be done when Beam drops py2? I know there is a https://issues.apache.org/jira/browse/BEAM-5949, but this refers only to `__ne__`

----------------------------------------------------------------
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