MCPcopy Create free account
hub / github.com/apache/tvm / arange

Function arange

python/tvm/relax/op/create.py:233–280  ·  view source on GitHub ↗

Construct a tensor with evenly spaced elements. Parameters ---------- start : PrimExprLike | PrimValue The start of the interval. end : Optional[PrimExprLike | PrimValue] The end of the interval. If not given, it will be set to start, and start will be set t

(
    start: PrimExprLike | PrimValue,
    end: PrimExprLike | PrimValue | None = None,
    step: PrimExprLike | PrimValue = 1,
    dtype: str | DataType | None = None,
)

Source from the content-addressed store, hash-verified

231
232
233def arange(
234 start: PrimExprLike | PrimValue,
235 end: PrimExprLike | PrimValue | None = None,
236 step: PrimExprLike | PrimValue = 1,
237 dtype: str | DataType | None = None,
238) -> Expr:
239 """Construct a tensor with evenly spaced elements.
240
241 Parameters
242 ----------
243 start : PrimExprLike | PrimValue
244 The start of the interval.
245
246 end : Optional[PrimExprLike | PrimValue]
247 The end of the interval. If not given, it will be set to start,
248 and start will be set to 0.
249
250 step : PrimExprLike | PrimValue
251 The step size.
252
253 dtype : Optional[str | DataType]
254 The data type of the created tensor.
255
256 Returns
257 -------
258 result : relax.Expr
259 The result tensor.
260 """
261 if end is None:
262 end = start
263 start = 0
264
265 def is_int(expr):
266 if isinstance(expr, int):
267 return True
268 if isinstance(expr, PrimValue):
269 expr = expr.value
270 return isinstance(expr, PrimExpr) and DataType(expr.dtype).type_code == DataTypeCode.INT # type: ignore
271
272 if dtype is None:
273 args = (start, end, step)
274 integer_args = all(is_int(arg) for arg in args)
275 dtype = "int64" if integer_args else "float32"
276
277 start = start if isinstance(start, PrimValue) else PrimValue(start)
278 end = end if isinstance(end, PrimValue) else PrimValue(end)
279 step = step if isinstance(step, PrimValue) else PrimValue(step)
280 return _ffi_api.arange(start, end, step, dtype) # type: ignore
281
282
283def hamming_window(window_size, periodic, alpha, beta, dtype):

Callers

nothing calls this directly

Calls 4

is_intFunction · 0.85
PrimValueClass · 0.85
allFunction · 0.50
arangeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…