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"
|
2025-03-06 19:23:38 -08:00
|
|
|
#include "mlx/backend/cpu/encoder.h"
|
2023-11-29 10:30:41 -08:00
|
|
|
|
|
|
|
|
namespace mlx::core {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2025-03-06 19:23:38 -08:00
|
|
|
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;
|
2025-03-06 19:23:38 -08:00
|
|
|
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
|