MLX
 
Loading...
Searching...
No Matches
arange.h
Go to the documentation of this file.
1// Copyright © 2023 Apple Inc.
2
3#pragma once
4
5#include "mlx/array.h"
7
8namespace mlx::core {
9
10namespace {
11
12template <typename T>
13void arange(T start, T next, array& out, size_t size, Stream stream) {
14 auto ptr = out.data<T>();
15 auto step_size = next - start;
16 auto& encoder = cpu::get_command_encoder(stream);
17 encoder.set_output_array(out);
18 encoder.dispatch([ptr, start, step_size, size]() mutable {
19 for (int i = 0; i < size; ++i) {
20 ptr[i] = start;
21 start += step_size;
22 }
23 });
24}
25
26} // namespace
27
28} // namespace mlx::core
Definition array.h:24
T * data()
Definition array.h:349
array arange(double start, double stop, double step, Dtype dtype, StreamOrDevice s={})
A 1D array of numbers starting at start (optional), stopping at stop, stepping by step (optional).
CommandEncoder & get_command_encoder(Stream stream)
Definition allocator.h:7
Definition stream.h:9