MCPcopy Create free account
hub / github.com/dask/dask / Random

Class Random

dask/array/_array_expr/random.py:885–992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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