MCPcopy
hub / github.com/dask/dask / Random

Class Random

dask/array/_array_expr/random.py:883–990  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881
882
883class Random(IO):
884 _parameters = [
885 "rng",
886 "distribution",
887 "size",
888 "chunks",
889 "extra_chunks",
890 "args",
891 "kwargs",
892 ]
893 _defaults = {"extra_chunks": ()}
894
895 @cached_property
896 def kwargs(self):
897 return self.operand("kwargs")
898
899 @property
900 def chunks(self):
901 size = self.operand("size")
902 chunks = self.operand("chunks")
903
904 # shapes = list(
905 # {
906 # ar.shape
907 # for ar in chain(args, kwargs.values())
908 # if isinstance(ar, (Array, np.ndarray))
909 # }
910 # )
911 # if size is not None:
912 # shapes.append(size)
913 shapes = [size]
914 # broadcast to the final size(shape)
915 size = broadcast_shapes(*shapes)
916 return normalize_chunks(
917 chunks,
918 size, # ideally would use dtype here
919 dtype=self.kwargs.get("dtype", np.float64),
920 )
921
922 @cached_property
923 def _info(self):
924 sizes = list(product(*self.chunks))
925 if isinstance(self.rng, Generator):
926 bitgens = _spawn_bitgens(self.rng._bit_generator, len(sizes))
927 bitgen_token = tokenize(bitgens)
928 bitgens = [_bitgen._seed_seq for _bitgen in bitgens]
929 func_applier = _apply_random_func
930 gen = type(self.rng._bit_generator)
931 elif isinstance(self.rng, RandomState):
932 bitgens = random_state_data(len(sizes), self.rng._numpy_state)
933 bitgen_token = tokenize(bitgens)
934 func_applier = _apply_random
935 gen = self.rng._RandomState
936 else:
937 raise TypeError(
938 "Unknown object type: Not a Generator and Not a RandomState"
939 )
940 token = tokenize(bitgen_token, self.size, self.chunks, self.args, self.kwargs)

Callers 4

random_sampleMethod · 0.90
random_sampleFunction · 0.90
random_state_data_pythonFunction · 0.90
_wrap_funcFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…