MCPcopy Index your code
hub / github.com/ml-explore/mlx / ArrayAt

Class ArrayAt

python/src/array.cpp:28–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using namespace nb::literals;
27
28class ArrayAt {
29 public:
30 ArrayAt(mx::array x) : x_(std::move(x)) {}
31 ArrayAt& set_indices(nb::object indices) {
32 initialized_ = true;
33 indices_ = indices;
34 return *this;
35 }
36 void check_initialized() {
37 if (!initialized_) {
38 throw std::invalid_argument(
39 "Must give indices to array.at (e.g. `x.at[0].add(4)`).");
40 }
41 }
42
43 mx::array add(const ScalarOrArray& v) {
44 check_initialized();
45 return mlx_add_item(x_, indices_, v);
46 }
47 mx::array subtract(const ScalarOrArray& v) {
48 check_initialized();
49 return mlx_subtract_item(x_, indices_, v);
50 }
51 mx::array multiply(const ScalarOrArray& v) {
52 check_initialized();
53 return mlx_multiply_item(x_, indices_, v);
54 }
55 mx::array divide(const ScalarOrArray& v) {
56 check_initialized();
57 return mlx_divide_item(x_, indices_, v);
58 }
59 mx::array maximum(const ScalarOrArray& v) {
60 check_initialized();
61 return mlx_maximum_item(x_, indices_, v);
62 }
63 mx::array minimum(const ScalarOrArray& v) {
64 check_initialized();
65 return mlx_minimum_item(x_, indices_, v);
66 }
67
68 private:
69 mx::array x_;
70 bool initialized_{false};
71 nb::object indices_;
72};
73
74class ArrayPythonIterator {
75 public:

Callers 1

init_arrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected