Files
mlx/mlx/backend/cpu/arange.h

29 lines
585 B
C
Raw Normal View History

2023-11-30 11:12:53 -08:00
// Copyright © 2023 Apple Inc.
2023-11-29 10:30:41 -08:00
#pragma once
#include "mlx/array.h"
#include "mlx/backend/cpu/encoder.h"
2023-11-29 10:30:41 -08:00
namespace mlx::core {
namespace {
template <typename T>
void arange(T start, T next, array& out, size_t size, Stream stream) {
2023-11-29 10:30:41 -08:00
auto ptr = out.data<T>();
auto step_size = next - start;
auto& encoder = cpu::get_command_encoder(stream);
encoder.set_output_array(out);
encoder.dispatch([ptr, start, step_size, size]() mutable {
for (int i = 0; i < size; ++i) {
ptr[i] = start;
start += step_size;
}
});
2023-11-29 10:30:41 -08:00
}
} // namespace
} // namespace mlx::core