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

Class Linspace

dask/array/_array_expr/_creation.py:78–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78class Linspace(Arange):
79 _parameters = ["start", "stop", "num", "endpoint", "chunks", "dtype"]
80 _defaults = {"num": 50, "endpoint": True, "chunks": "auto", "dtype": None}
81 like = None
82
83 @functools.cached_property
84 def num_rows(self):
85 return self.operand("num")
86
87 @functools.cached_property
88 def dtype(self):
89 return self.operand("dtype") or np.linspace(0, 1, 1).dtype
90
91 @functools.cached_property
92 def step(self):
93 range_ = self.stop - self.start
94
95 div = (self.num_rows - 1) if self.endpoint else self.num_rows
96 if div == 0:
97 div = 1
98
99 return float(range_) / div
100
101 def _layer(self) -> dict:
102 dsk = {}
103 blockstart = self.start
104 func = partial(_linspace, endpoint=self.endpoint, dtype=self.dtype)
105
106 for i, bs in enumerate(self.chunks[0]):
107 bs_space = bs - 1 if self.endpoint else bs
108 blockstop = blockstart + (bs_space * self.step)
109 task = Task(
110 (self._name, i),
111 func,
112 blockstart,
113 blockstop,
114 bs,
115 )
116 blockstart = blockstart + (self.step * bs)
117 dsk[task.key] = task
118 return dsk
119
120
121class BroadcastTrick(ArrayExpr):

Callers 1

linspaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected