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
"
6
#include "
mlx/backend/cpu/encoder.h
"
7
8
namespace
mlx::core
{
9
10
namespace
{
11
12
template
<
typename
T>
13
void
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
array.h
mlx::core::array
Definition
array.h:24
mlx::core::array::data
T * data()
Definition
array.h:349
encoder.h
mlx::core::arange
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).
mlx::core::cpu::get_command_encoder
CommandEncoder & get_command_encoder(Stream stream)
mlx::core
Definition
allocator.h:7
mlx::core::Stream
Definition
stream.h:9
mlx
backend
cpu
arange.h
Generated by
1.13.2