MLX
Loading...
Searching...
No Matches
ops.h
Go to the documentation of this file.
1// Copyright © 2023-2024 Apple Inc.
2
3#pragma once
4
5#include <optional>
6
7#include "mlx/array.h"
8#include "mlx/device.h"
9#include "mlx/stream.h"
10#include "mlx/utils.h"
11
12namespace mlx::core {
13
23 double start,
24 double stop,
25 double step,
26 Dtype dtype,
27 StreamOrDevice s = {});
28array arange(double start, double stop, double step, StreamOrDevice s = {});
29array arange(double start, double stop, Dtype dtype, StreamOrDevice s = {});
30array arange(double start, double stop, StreamOrDevice s = {});
31array arange(double stop, Dtype dtype, StreamOrDevice s = {});
32array arange(double stop, StreamOrDevice s = {});
33
34array arange(int start, int stop, int step, StreamOrDevice s = {});
35array arange(int start, int stop, StreamOrDevice s = {});
36array arange(int stop, StreamOrDevice s = {});
37
40 double start,
41 double stop,
42 int num = 50,
43 Dtype dtype = float32,
44 StreamOrDevice s = {});
45
48
51 array a,
52 std::vector<int> shape,
53 std::vector<size_t> strides,
54 size_t offset,
55 StreamOrDevice s = {});
56
59
62 std::vector<int> shape,
63 array vals,
64 Dtype dtype,
65 StreamOrDevice s = {});
66array full(std::vector<int> shape, array vals, StreamOrDevice s = {});
67template <typename T>
68array full(std::vector<int> shape, T val, Dtype dtype, StreamOrDevice s = {}) {
69 return full(std::move(shape), array(val, dtype), to_stream(s));
70}
71template <typename T>
72array full(std::vector<int> shape, T val, StreamOrDevice s = {}) {
73 return full(std::move(shape), array(val), to_stream(s));
74}
75
77array zeros(const std::vector<int>& shape, Dtype dtype, StreamOrDevice s = {});
78inline array zeros(const std::vector<int>& shape, StreamOrDevice s = {}) {
79 return zeros(shape, float32, s);
80}
82
84array ones(const std::vector<int>& shape, Dtype dtype, StreamOrDevice s = {});
85inline array ones(const std::vector<int>& shape, StreamOrDevice s = {}) {
86 return ones(shape, float32, s);
87}
89
92array eye(int n, int m, int k, Dtype dtype, StreamOrDevice s = {});
93inline array eye(int n, Dtype dtype, StreamOrDevice s = {}) {
94 return eye(n, n, 0, dtype, s);
95}
96inline array eye(int n, int m, StreamOrDevice s = {}) {
97 return eye(n, m, 0, float32, s);
98}
99inline array eye(int n, int m, int k, StreamOrDevice s = {}) {
100 return eye(n, m, k, float32, s);
101}
102inline array eye(int n, StreamOrDevice s = {}) {
103 return eye(n, n, 0, float32, s);
104}
105
108array identity(int n, Dtype dtype, StreamOrDevice s = {});
109inline array identity(int n, StreamOrDevice s = {}) {
110 return identity(n, float32, s);
111}
112
113array tri(int n, int m, int k, Dtype type, StreamOrDevice s = {});
114inline array tri(int n, Dtype type, StreamOrDevice s = {}) {
115 return tri(n, n, 0, type, s);
116}
117
118array tril(array x, int k = 0, StreamOrDevice s = {});
119array triu(array x, int k = 0, StreamOrDevice s = {});
120
122array reshape(const array& a, std::vector<int> shape, StreamOrDevice s = {});
123
126 const array& a,
127 int start_axis,
128 int end_axis = -1,
129 StreamOrDevice s = {});
130
133
136 const array& a,
137 std::optional<float> scale = std::nullopt,
138 StreamOrDevice s = {});
139
142 const array& a,
143 const std::vector<int>& axes,
144 StreamOrDevice s = {});
145
147inline array squeeze(const array& a, int axis, StreamOrDevice s = {}) {
148 return squeeze(a, std::vector<int>{axis}, s);
149}
150
153
156 const array& a,
157 const std::vector<int>& axes,
158 StreamOrDevice s = {});
159
161array expand_dims(const array& a, int axis, StreamOrDevice s = {});
162
165 const array& a,
166 std::vector<int> start,
167 std::vector<int> stop,
168 std::vector<int> strides,
169 StreamOrDevice s = {});
170
173 const array& a,
174 const std::vector<int>& start,
175 const std::vector<int>& stop,
176 StreamOrDevice s = {});
177
180 const array& src,
181 const array& update,
182 std::vector<int> start,
183 std::vector<int> stop,
184 std::vector<int> strides,
185 StreamOrDevice s = {});
186
189 const array& src,
190 const array& update,
191 std::vector<int> start,
192 std::vector<int> stop,
193 StreamOrDevice s = {});
194
196std::vector<array>
197split(const array& a, int num_splits, int axis, StreamOrDevice s = {});
198std::vector<array> split(const array& a, int num_splits, StreamOrDevice s = {});
199std::vector<array> split(
200 const array& a,
201 const std::vector<int>& indices,
202 int axis,
203 StreamOrDevice s = {});
204std::vector<array>
205split(const array& a, const std::vector<int>& indices, StreamOrDevice s = {});
206
208std::vector<array> meshgrid(
209 const std::vector<array>& arrays,
210 bool sparse = false,
211 std::string indexing = "xy",
212 StreamOrDevice s = {});
213
218 const array& a,
219 const std::optional<array>& a_min = std::nullopt,
220 const std::optional<array>& a_max = std::nullopt,
221 StreamOrDevice s = {});
222
225 const std::vector<array>& arrays,
226 int axis,
227 StreamOrDevice s = {});
228array concatenate(const std::vector<array>& arrays, StreamOrDevice s = {});
229
231array stack(const std::vector<array>& arrays, int axis, StreamOrDevice s = {});
232array stack(const std::vector<array>& arrays, StreamOrDevice s = {});
233
235array repeat(const array& arr, int repeats, int axis, StreamOrDevice s = {});
236array repeat(const array& arr, int repeats, StreamOrDevice s = {});
237
238array tile(const array& arr, std::vector<int> reps, StreamOrDevice s = {});
239
241array transpose(const array& a, std::vector<int> axes, StreamOrDevice s = {});
243 const array& a,
244 std::initializer_list<int> axes,
245 StreamOrDevice s = {}) {
246 return transpose(a, std::vector<int>(axes), s);
247}
248
250array swapaxes(const array& a, int axis1, int axis2, StreamOrDevice s = {});
251
254 const array& a,
255 int source,
256 int destination,
257 StreamOrDevice s = {});
258
261 const array& a,
262 const std::vector<int>& axes,
263 const std::vector<int>& low_pad_size,
264 const std::vector<int>& high_pad_size,
265 const array& pad_value = array(0),
266 const std::string mode = "constant",
267 StreamOrDevice s = {});
268
271 const array& a,
272 const std::vector<std::pair<int, int>>& pad_width,
273 const array& pad_value = array(0),
274 const std::string mode = "constant",
275 StreamOrDevice s = {});
277 const array& a,
278 const std::pair<int, int>& pad_width,
279 const array& pad_value = array(0),
280 const std::string mode = "constant",
281 StreamOrDevice s = {});
283 const array& a,
284 int pad_width,
285 const array& pad_value = array(0),
286 const std::string mode = "constant",
287 StreamOrDevice s = {});
288
291
294 const array& a,
295 const std::vector<int>& shape,
296 StreamOrDevice s = {});
297
299std::vector<array> broadcast_arrays(
300 const std::vector<array>& inputs,
301 StreamOrDevice s = {});
302
304array equal(const array& a, const array& b, StreamOrDevice s = {});
305inline array operator==(const array& a, const array& b) {
306 return equal(a, b);
307}
308template <typename T>
309array operator==(T a, const array& b) {
310 return equal(array(a), b);
311}
312template <typename T>
313array operator==(const array& a, T b) {
314 return equal(a, array(b));
315}
316
318array not_equal(const array& a, const array& b, StreamOrDevice s = {});
319inline array operator!=(const array& a, const array& b) {
320 return not_equal(a, b);
321}
322template <typename T>
323array operator!=(T a, const array& b) {
324 return not_equal(array(a), b);
325}
326template <typename T>
327array operator!=(const array& a, T b) {
328 return not_equal(a, array(b));
329}
330
332array greater(const array& a, const array& b, StreamOrDevice s = {});
333inline array operator>(const array& a, const array& b) {
334 return greater(a, b);
335}
336template <typename T>
337array operator>(T a, const array& b) {
338 return greater(array(a), b);
339}
340template <typename T>
341array operator>(const array& a, T b) {
342 return greater(a, array(b));
343}
344
346array greater_equal(const array& a, const array& b, StreamOrDevice s = {});
347inline array operator>=(const array& a, const array& b) {
348 return greater_equal(a, b);
349}
350template <typename T>
351array operator>=(T a, const array& b) {
352 return greater_equal(array(a), b);
353}
354template <typename T>
355array operator>=(const array& a, T b) {
356 return greater_equal(a, array(b));
357}
358
360array less(const array& a, const array& b, StreamOrDevice s = {});
361inline array operator<(const array& a, const array& b) {
362 return less(a, b);
363}
364template <typename T>
365array operator<(T a, const array& b) {
366 return less(array(a), b);
367}
368template <typename T>
369array operator<(const array& a, T b) {
370 return less(a, array(b));
371}
372
374array less_equal(const array& a, const array& b, StreamOrDevice s = {});
375inline array operator<=(const array& a, const array& b) {
376 return less_equal(a, b);
377}
378template <typename T>
379array operator<=(T a, const array& b) {
380 return less_equal(array(a), b);
381}
382template <typename T>
383array operator<=(const array& a, T b) {
384 return less_equal(a, array(b));
385}
386
389 const array& a,
390 const array& b,
391 bool equal_nan,
392 StreamOrDevice s = {});
393inline array
394array_equal(const array& a, const array& b, StreamOrDevice s = {}) {
395 return array_equal(a, b, false, s);
396}
397
398array isnan(const array& a, StreamOrDevice s = {});
399
400array isinf(const array& a, StreamOrDevice s = {});
401
403
405
407
410 const array& condition,
411 const array& x,
412 const array& y,
413 StreamOrDevice s = {});
414
417 const array& a,
418 float nan = 0.0f,
419 const std::optional<float> posinf = std::nullopt,
420 const std::optional<float> neginf = std::nullopt,
421 StreamOrDevice s = {});
422
424array all(const array& a, bool keepdims, StreamOrDevice s = {});
425inline array all(const array& a, StreamOrDevice s = {}) {
426 return all(a, false, to_stream(s));
427}
428
431 const array& a,
432 const array& b,
433 double rtol = 1e-5,
434 double atol = 1e-8,
435 bool equal_nan = false,
436 StreamOrDevice s = {});
437
441 const array& a,
442 const array& b,
443 double rtol = 1e-5,
444 double atol = 1e-8,
445 bool equal_nan = false,
446 StreamOrDevice s = {});
447
453 const array& a,
454 const std::vector<int>& axes,
455 bool keepdims = false,
456 StreamOrDevice s = {});
457
463 const array& a,
464 int axis,
465 bool keepdims = false,
466 StreamOrDevice s = {});
467
469array any(const array& a, bool keepdims, StreamOrDevice s = {});
470inline array any(const array& a, StreamOrDevice s = {}) {
471 return any(a, false, to_stream(s));
472}
473
479 const array& a,
480 const std::vector<int>& axes,
481 bool keepdims = false,
482 StreamOrDevice s = {});
483
489 const array& a,
490 int axis,
491 bool keepdims = false,
492 StreamOrDevice s = {});
493
495array sum(const array& a, bool keepdims, StreamOrDevice s = {});
496inline array sum(const array& a, StreamOrDevice s = {}) {
497 return sum(a, false, to_stream(s));
498}
499
502 const array& a,
503 const std::vector<int>& axes,
504 bool keepdims = false,
505 StreamOrDevice s = {});
506
509 const array& a,
510 int axis,
511 bool keepdims = false,
512 StreamOrDevice s = {});
513
515array mean(const array& a, bool keepdims, StreamOrDevice s = {});
516inline array mean(const array& a, StreamOrDevice s = {}) {
517 return mean(a, false, to_stream(s));
518}
519
522 const array& a,
523 const std::vector<int>& axes,
524 bool keepdims = false,
525 StreamOrDevice s = {});
526
529 const array& a,
530 int axis,
531 bool keepdims = false,
532 StreamOrDevice s = {});
533
535array var(const array& a, bool keepdims, int ddof = 0, StreamOrDevice s = {});
536inline array var(const array& a, StreamOrDevice s = {}) {
537 return var(a, false, 0, to_stream(s));
538}
539
543 const array& a,
544 const std::vector<int>& axes,
545 bool keepdims = false,
546 int ddof = 0,
547 StreamOrDevice s = {});
548
552 const array& a,
553 int axis,
554 bool keepdims = false,
555 int ddof = 0,
556 StreamOrDevice s = {});
557
559array std(const array& a, bool keepdims, int ddof = 0, StreamOrDevice s = {});
560inline array std(const array& a, StreamOrDevice s = {}) {
561 return std(a, false, 0, to_stream(s));
562}
563
567 const array& a,
568 const std::vector<int>& axes,
569 bool keepdims = false,
570 int ddof = 0,
571 StreamOrDevice s = {});
572
576 const array& a,
577 int axis,
578 bool keepdims = false,
579 int ddof = 0,
580 StreamOrDevice s = {});
581
583array prod(const array& a, bool keepdims, StreamOrDevice s = {});
584inline array prod(const array& a, StreamOrDevice s = {}) {
585 return prod(a, false, to_stream(s));
586}
587
590 const array& a,
591 const std::vector<int>& axes,
592 bool keepdims = false,
593 StreamOrDevice s = {});
594
597 const array& a,
598 int axis,
599 bool keepdims = false,
600 StreamOrDevice s = {});
601
603array max(const array& a, bool keepdims, StreamOrDevice s = {});
604inline array max(const array& a, StreamOrDevice s = {}) {
605 return max(a, false, to_stream(s));
606}
607
610 const array& a,
611 const std::vector<int>& axes,
612 bool keepdims = false,
613 StreamOrDevice s = {});
614
617 const array& a,
618 int axis,
619 bool keepdims = false,
620 StreamOrDevice s = {});
621
623array min(const array& a, bool keepdims, StreamOrDevice s = {});
624inline array min(const array& a, StreamOrDevice s = {}) {
625 return min(a, false, to_stream(s));
626}
627
630 const array& a,
631 const std::vector<int>& axes,
632 bool keepdims = false,
633 StreamOrDevice s = {});
634
637 const array& a,
638 int axis,
639 bool keepdims = false,
640 StreamOrDevice s = {});
641
643array argmin(const array& a, bool keepdims, StreamOrDevice s = {});
644inline array argmin(const array& a, StreamOrDevice s = {}) {
645 return argmin(a, false, s);
646}
647
650 const array& a,
651 int axis,
652 bool keepdims = false,
653 StreamOrDevice s = {});
654
656array argmax(const array& a, bool keepdims, StreamOrDevice s = {});
657inline array argmax(const array& a, StreamOrDevice s = {}) {
658 return argmax(a, false, s);
659}
660
663 const array& a,
664 int axis,
665 bool keepdims = false,
666 StreamOrDevice s = {});
667
669array sort(const array& a, StreamOrDevice s = {});
670
672array sort(const array& a, int axis, StreamOrDevice s = {});
673
676
678array argsort(const array& a, int axis, StreamOrDevice s = {});
679
684array partition(const array& a, int kth, StreamOrDevice s = {});
685
690array partition(const array& a, int kth, int axis, StreamOrDevice s = {});
691
696array argpartition(const array& a, int kth, StreamOrDevice s = {});
697
702array argpartition(const array& a, int kth, int axis, StreamOrDevice s = {});
703
705array topk(const array& a, int k, StreamOrDevice s = {});
706
708array topk(const array& a, int k, int axis, StreamOrDevice s = {});
709
711array logsumexp(const array& a, bool keepdims, StreamOrDevice s = {});
712inline array logsumexp(const array& a, StreamOrDevice s = {}) {
713 return logsumexp(a, false, to_stream(s));
714}
715
718 const array& a,
719 const std::vector<int>& axes,
720 bool keepdims = false,
721 StreamOrDevice s = {});
722
725 const array& a,
726 int axis,
727 bool keepdims = false,
728 StreamOrDevice s = {});
729
731array abs(const array& a, StreamOrDevice s = {});
732
736
738array sign(const array& a, StreamOrDevice s = {});
739
742
744array logical_and(const array& a, const array& b, StreamOrDevice s = {});
745array operator&&(const array& a, const array& b);
746
748array logical_or(const array& a, const array& b, StreamOrDevice s = {});
749array operator||(const array& a, const array& b);
750
753
755array add(const array& a, const array& b, StreamOrDevice s = {});
756array operator+(const array& a, const array& b);
757template <typename T>
758array operator+(T a, const array& b) {
759 return add(array(a), b);
760}
761template <typename T>
762array operator+(const array& a, T b) {
763 return add(a, array(b));
764}
765
767array subtract(const array& a, const array& b, StreamOrDevice s = {});
768array operator-(const array& a, const array& b);
769template <typename T>
770array operator-(T a, const array& b) {
771 return subtract(array(a), b);
772}
773template <typename T>
774array operator-(const array& a, T b) {
775 return subtract(a, array(b));
776}
777
779array multiply(const array& a, const array& b, StreamOrDevice s = {});
780array operator*(const array& a, const array& b);
781template <typename T>
782array operator*(T a, const array& b) {
783 return multiply(array(a), b);
784}
785template <typename T>
786array operator*(const array& a, T b) {
787 return multiply(a, array(b));
788}
789
791array divide(const array& a, const array& b, StreamOrDevice s = {});
792array operator/(const array& a, const array& b);
793array operator/(double a, const array& b);
794array operator/(const array& a, double b);
795
797std::vector<array>
798divmod(const array& a, const array& b, StreamOrDevice s = {});
799
801array floor_divide(const array& a, const array& b, StreamOrDevice s = {});
802
804array remainder(const array& a, const array& b, StreamOrDevice s = {});
805array operator%(const array& a, const array& b);
806template <typename T>
807array operator%(T a, const array& b) {
808 return remainder(array(a), b);
809}
810template <typename T>
811array operator%(const array& a, T b) {
812 return remainder(a, array(b));
813}
814
816array maximum(const array& a, const array& b, StreamOrDevice s = {});
817
819array minimum(const array& a, const array& b, StreamOrDevice s = {});
820
822array floor(const array& a, StreamOrDevice s = {});
823
825array ceil(const array& a, StreamOrDevice s = {});
826
829
831array exp(const array& a, StreamOrDevice s = {});
832
834array sin(const array& a, StreamOrDevice s = {});
835
837array cos(const array& a, StreamOrDevice s = {});
838
840array tan(const array& a, StreamOrDevice s = {});
841
844
847
850
852array arctan2(const array& a, const array& b, StreamOrDevice s = {});
853
855array sinh(const array& a, StreamOrDevice s = {});
856
858array cosh(const array& a, StreamOrDevice s = {});
859
861array tanh(const array& a, StreamOrDevice s = {});
862
865
868
871
874
877
879array log(const array& a, StreamOrDevice s = {});
880
882array log2(const array& a, StreamOrDevice s = {});
883
885array log10(const array& a, StreamOrDevice s = {});
886
888array log1p(const array& a, StreamOrDevice s = {});
889
891array logaddexp(const array& a, const array& b, StreamOrDevice s = {});
892
895
897array erf(const array& a, StreamOrDevice s = {});
898
901
903array expm1(const array& a, StreamOrDevice s = {});
904
907
909array round(const array& a, int decimals, StreamOrDevice s = {});
910inline array round(const array& a, StreamOrDevice s = {}) {
911 return round(a, 0, s);
912}
913
915array matmul(const array& a, const array& b, StreamOrDevice s = {});
916
919 const array& a,
920 const std::vector<array>& indices,
921 const std::vector<int>& axes,
922 const std::vector<int>& slice_sizes,
923 StreamOrDevice s = {});
925 const array& a,
926 const array& indices,
927 int axis,
928 const std::vector<int>& slice_sizes,
929 StreamOrDevice s = {}) {
930 return gather(a, {indices}, std::vector<int>{axis}, slice_sizes, s);
931}
932
935 const array& a,
936 const array& indices,
937 int axis,
938 StreamOrDevice s = {});
939
941array take(const array& a, const array& indices, StreamOrDevice s = {});
942
945 const array& a,
946 const array& indices,
947 int axis,
948 StreamOrDevice s = {});
949
1049 const array& a,
1050 const std::vector<array>& indices,
1051 const array& updates,
1052 const std::vector<int>& axes,
1053 StreamOrDevice s = {});
1055 const array& a,
1056 const array& indices,
1057 const array& updates,
1058 int axis,
1059 StreamOrDevice s = {}) {
1060 return scatter(a, {indices}, updates, std::vector<int>{axis}, s);
1061}
1062
1065 const array& a,
1066 const std::vector<array>& indices,
1067 const array& updates,
1068 const std::vector<int>& axes,
1069 StreamOrDevice s = {});
1071 const array& a,
1072 const array& indices,
1073 const array& updates,
1074 int axis,
1075 StreamOrDevice s = {}) {
1076 return scatter_add(a, {indices}, updates, std::vector<int>{axis}, s);
1077}
1078
1081 const array& a,
1082 const std::vector<array>& indices,
1083 const array& updates,
1084 const std::vector<int>& axes,
1085 StreamOrDevice s = {});
1087 const array& a,
1088 const array& indices,
1089 const array& updates,
1090 int axis,
1091 StreamOrDevice s = {}) {
1092 return scatter_prod(a, {indices}, updates, std::vector<int>{axis}, s);
1093}
1094
1097 const array& a,
1098 const std::vector<array>& indices,
1099 const array& updates,
1100 const std::vector<int>& axes,
1101 StreamOrDevice s = {});
1103 const array& a,
1104 const array& indices,
1105 const array& updates,
1106 int axis,
1107 StreamOrDevice s = {}) {
1108 return scatter_max(a, {indices}, updates, std::vector<int>{axis}, s);
1109}
1112 const array& a,
1113 const std::vector<array>& indices,
1114 const array& updates,
1115 const std::vector<int>& axes,
1116 StreamOrDevice s = {});
1118 const array& a,
1119 const array& indices,
1120 const array& updates,
1121 int axis,
1122 StreamOrDevice s = {}) {
1123 return scatter_min(a, {indices}, updates, std::vector<int>{axis}, s);
1124}
1125
1127array sqrt(const array& a, StreamOrDevice s = {});
1128
1131
1134 const array& a,
1135 const std::vector<int>& axes,
1136 bool precise = false,
1137 StreamOrDevice s = {});
1138
1140array softmax(const array& a, bool precise = false, StreamOrDevice s = {});
1141
1143inline array
1144softmax(const array& a, int axis, bool precise = false, StreamOrDevice s = {}) {
1145 return softmax(a, std::vector<int>{axis}, precise, s);
1146}
1147
1149array power(const array& a, const array& b, StreamOrDevice s = {});
1150
1153 const array& a,
1154 int axis,
1155 bool reverse = false,
1156 bool inclusive = true,
1157 StreamOrDevice s = {});
1158
1161 const array& a,
1162 int axis,
1163 bool reverse = false,
1164 bool inclusive = true,
1165 StreamOrDevice s = {});
1166
1169 const array& a,
1170 int axis,
1171 bool reverse = false,
1172 bool inclusive = true,
1173 StreamOrDevice s = {});
1174
1177 const array& a,
1178 int axis,
1179 bool reverse = false,
1180 bool inclusive = true,
1181 StreamOrDevice s = {});
1182
1185 array input,
1186 array weight,
1187 std::vector<int> stride = {},
1188 std::vector<int> padding_lo = {},
1189 std::vector<int> padding_hi = {},
1190 std::vector<int> kernel_dilation = {},
1191 std::vector<int> input_dilation = {},
1192 int groups = 1,
1193 bool flip = false,
1194 StreamOrDevice s = {});
1195
1198 const array& input,
1199 const array& weight,
1200 std::vector<int> stride = {},
1201 std::vector<int> padding = {},
1202 std::vector<int> kernel_dilation = {},
1203 std::vector<int> input_dilation = {},
1204 int groups = 1,
1205 bool flip = false,
1206 StreamOrDevice s = {}) {
1207 return conv_general(
1208 /* const array& input = */ input,
1209 /* const array& weight = */ weight,
1210 /* std::vector<int> stride = */ stride,
1211 /* std::vector<int> padding_lo = */ padding,
1212 /* std::vector<int> padding_hi = */ padding,
1213 /* std::vector<int> kernel_dilation = */ kernel_dilation,
1214 /* std::vector<int> input_dilation = */ input_dilation,
1215 /* int groups = */ groups,
1216 /* bool flip = */ flip,
1217 /* StreamOrDevice s = */ s);
1218}
1219
1222 const array& input,
1223 const array& weight,
1224 int stride = 1,
1225 int padding = 0,
1226 int dilation = 1,
1227 int groups = 1,
1228 StreamOrDevice s = {});
1229
1232 const array& input,
1233 const array& weight,
1234 const std::pair<int, int>& stride = {1, 1},
1235 const std::pair<int, int>& padding = {0, 0},
1236 const std::pair<int, int>& dilation = {1, 1},
1237 int groups = 1,
1238 StreamOrDevice s = {});
1239
1242 const array& input,
1243 const array& weight,
1244 const std::tuple<int, int, int>& stride = {1, 1, 1},
1245 const std::tuple<int, int, int>& padding = {0, 0, 0},
1246 const std::tuple<int, int, int>& dilation = {1, 1, 1},
1247 int groups = 1,
1248 StreamOrDevice s = {});
1249
1252 const array& input,
1253 const array& weight,
1254 int stride = 1,
1255 int padding = 0,
1256 int dilation = 1,
1257 int groups = 1,
1258 StreamOrDevice s = {});
1259
1262 const array& input,
1263 const array& weight,
1264 const std::pair<int, int>& stride = {1, 1},
1265 const std::pair<int, int>& padding = {0, 0},
1266 const std::pair<int, int>& dilation = {1, 1},
1267 int groups = 1,
1268 StreamOrDevice s = {});
1269
1272 const array& input,
1273 const array& weight,
1274 const std::tuple<int, int, int>& stride = {1, 1, 1},
1275 const std::tuple<int, int, int>& padding = {0, 0, 0},
1276 const std::tuple<int, int, int>& dilation = {1, 1, 1},
1277 int groups = 1,
1278 StreamOrDevice s = {});
1279
1282 const array& x,
1283 const array& w,
1284 const array& scales,
1285 const array& biases,
1286 bool transpose = true,
1287 int group_size = 64,
1288 int bits = 4,
1289 StreamOrDevice s = {});
1290
1292std::tuple<array, array, array> quantize(
1293 const array& w,
1294 int group_size = 64,
1295 int bits = 4,
1296 StreamOrDevice s = {});
1297
1300 const array& w,
1301 const array& scales,
1302 const array& biases,
1303 int group_size = 64,
1304 int bits = 4,
1305 StreamOrDevice s = {});
1306
1309 const array& x,
1310 const array& w,
1311 const array& scales,
1312 const array& biases,
1313 std::optional<array> lhs_indices = std::nullopt,
1314 std::optional<array> rhs_indices = std::nullopt,
1315 bool transpose = true,
1316 int group_size = 64,
1317 int bits = 4,
1318 StreamOrDevice s = {});
1319
1322 const array& a,
1323 const array& b,
1324 const int axis = 2,
1325 StreamOrDevice s = {});
1326
1328 const array& a,
1329 const array& b,
1330 const std::vector<int>& axes_a,
1331 const std::vector<int>& axes_b,
1332 StreamOrDevice s = {});
1333
1335array outer(const array& a, const array& b, StreamOrDevice s = {});
1336
1338array inner(const array& a, const array& b, StreamOrDevice s = {});
1339
1342 array c,
1343 array a,
1344 array b,
1345 const float& alpha = 1.f,
1346 const float& beta = 1.f,
1347 StreamOrDevice s = {});
1348
1351 array a,
1352 array b,
1353 int block_size,
1354 std::optional<array> mask_out = std::nullopt,
1355 std::optional<array> mask_lhs = std::nullopt,
1356 std::optional<array> mask_rhs = std::nullopt,
1357 StreamOrDevice s = {});
1358
1361 array a,
1362 array b,
1363 std::optional<array> lhs_indices = std::nullopt,
1364 std::optional<array> rhs_indices = std::nullopt,
1365 StreamOrDevice s = {});
1366
1369 const array& a,
1370 int offset = 0,
1371 int axis1 = 0,
1372 int axis2 = 1,
1373 StreamOrDevice s = {});
1374
1376array diag(const array& a, int k = 0, StreamOrDevice s = {});
1377
1380 const array& a,
1381 int offset,
1382 int axis1,
1383 int axis2,
1384 Dtype dtype,
1385 StreamOrDevice s = {});
1387 const array& a,
1388 int offset,
1389 int axis1,
1390 int axis2,
1391 StreamOrDevice s = {});
1393
1399std::vector<array> depends(
1400 const std::vector<array>& inputs,
1401 const std::vector<array>& dependencies);
1402
1405std::vector<array> atleast_1d(
1406 const std::vector<array>& a,
1407 StreamOrDevice s = {});
1409std::vector<array> atleast_2d(
1410 const std::vector<array>& a,
1411 StreamOrDevice s = {});
1413std::vector<array> atleast_3d(
1414 const std::vector<array>& a,
1415 StreamOrDevice s = {});
1416
1422 const array& a,
1423 std::vector<int> axes,
1424 bool inverted,
1425 Dtype dtype = int32,
1426 StreamOrDevice s = {});
1427
1429
1431array bitwise_and(const array& a, const array& b, StreamOrDevice s = {});
1432array operator&(const array& a, const array& b);
1433
1435array bitwise_or(const array& a, const array& b, StreamOrDevice s = {});
1436array operator|(const array& a, const array& b);
1437
1439array bitwise_xor(const array& a, const array& b, StreamOrDevice s = {});
1440array operator^(const array& a, const array& b);
1441
1443array left_shift(const array& a, const array& b, StreamOrDevice s = {});
1444array operator<<(const array& a, const array& b);
1445
1447array right_shift(const array& a, const array& b, StreamOrDevice s = {});
1448array operator>>(const array& a, const array& b);
1449
1450array view(const array& a, const Dtype& dtype, StreamOrDevice s = {});
1453} // namespace mlx::core
Definition array.h:20
array scatter_max(const array &a, const std::vector< array > &indices, const array &updates, const std::vector< int > &axes, StreamOrDevice s={})
Scatter and max updates to given linear indices.
array floor_divide(const array &a, const array &b, StreamOrDevice s={})
Compute integer division.
array radians(const array &a, StreamOrDevice s={})
Convert the elements of an array from Degrees to Radians.
array arccos(const array &a, StreamOrDevice s={})
Arc Cosine of the elements of an array.
array scatter_min(const array &a, const std::vector< array > &indices, const array &updates, const std::vector< int > &axes, StreamOrDevice s={})
Scatter and min updates to given linear indices.
array less_equal(const array &a, const array &b, StreamOrDevice s={})
Returns bool array with (a <= b) element-wise.
array cumprod(const array &a, int axis, bool reverse=false, bool inclusive=true, StreamOrDevice s={})
Cumulative product of an array.
array astype(array a, Dtype dtype, StreamOrDevice s={})
Convert an array to the given data type.
array rsqrt(const array &a, StreamOrDevice s={})
Square root and reciprocal the elements of an array.
array diag(const array &a, int k=0, StreamOrDevice s={})
Extract diagonal from a 2d array or create a diagonal matrix.
array square(const array &a, StreamOrDevice s={})
Square the elements of an array.
array ceil(const array &a, StreamOrDevice s={})
Ceil the element of an array.
array log2(const array &a, StreamOrDevice s={})
Log base 2 of the elements of an array.
array clip(const array &a, const std::optional< array > &a_min=std::nullopt, const std::optional< array > &a_max=std::nullopt, StreamOrDevice s={})
Clip (limit) the values in an array.
array isnan(const array &a, StreamOrDevice s={})
array isneginf(const array &a, StreamOrDevice s={})
array subtract(const array &a, const array &b, StreamOrDevice s={})
Subtract two arrays.
array cummin(const array &a, int axis, bool reverse=false, bool inclusive=true, StreamOrDevice s={})
Cumulative min of an array.
array log10(const array &a, StreamOrDevice s={})
Log base 10 of the elements of an array.
array log1p(const array &a, StreamOrDevice s={})
Natural logarithm of one plus elements in the array: log(1 + a).
array sign(const array &a, StreamOrDevice s={})
The sign of the elements in an array.
array cosh(const array &a, StreamOrDevice s={})
Hyperbolic Cosine of the elements of an array.
array conv_general(array input, array weight, std::vector< int > stride={}, std::vector< int > padding_lo={}, std::vector< int > padding_hi={}, std::vector< int > kernel_dilation={}, std::vector< int > input_dilation={}, int groups=1, bool flip=false, StreamOrDevice s={})
General convolution with a filter.
array logical_or(const array &a, const array &b, StreamOrDevice s={})
Logical or of two arrays.
array moveaxis(const array &a, int source, int destination, StreamOrDevice s={})
Move an axis of an array.
array operator*(const array &a, const array &b)
array operator+(const array &a, const array &b)
array operator||(const array &a, const array &b)
array not_equal(const array &a, const array &b, StreamOrDevice s={})
Returns the bool array with (a != b) element-wise.
array erf(const array &a, StreamOrDevice s={})
Computes the error function of the elements of an array.
array sqrt(const array &a, StreamOrDevice s={})
Square root the elements of an array.
array std(const array &a, bool keepdims, int ddof=0, StreamOrDevice s={})
Computes the standard deviation of the elements of an array.
array add(const array &a, const array &b, StreamOrDevice s={})
Add two arrays.
array round(const array &a, int decimals, StreamOrDevice s={})
Round a floating point number.
array conv1d(const array &input, const array &weight, int stride=1, int padding=0, int dilation=1, int groups=1, StreamOrDevice s={})
1D convolution with a filter
array bitwise_xor(const array &a, const array &b, StreamOrDevice s={})
Bitwise exclusive or.
array equal(const array &a, const array &b, StreamOrDevice s={})
Returns the bool array with (a == b) element-wise.
array zeros(const std::vector< int > &shape, Dtype dtype, StreamOrDevice s={})
Fill an array of the given shape with zeros.
array view(const array &a, const Dtype &dtype, StreamOrDevice s={})
array gather_qmm(const array &x, const array &w, const array &scales, const array &biases, std::optional< array > lhs_indices=std::nullopt, std::optional< array > rhs_indices=std::nullopt, bool transpose=true, int group_size=64, int bits=4, StreamOrDevice s={})
Compute matrix products with matrix-level gather.
array stop_gradient(const array &a, StreamOrDevice s={})
Stop the flow of gradients.
array scatter_prod(const array &a, const std::vector< array > &indices, const array &updates, const std::vector< int > &axes, StreamOrDevice s={})
Scatter and prod updates to given indices.
array slice_update(const array &src, const array &update, std::vector< int > start, std::vector< int > stop, std::vector< int > strides, StreamOrDevice s={})
Update a slice from the source array.
array cos(const array &a, StreamOrDevice s={})
Cosine of the elements of an array.
array operator>=(const array &a, const array &b)
Definition ops.h:347
array degrees(const array &a, StreamOrDevice s={})
Convert the elements of an array from Radians to Degrees.
array all(const array &a, bool keepdims, StreamOrDevice s={})
True if all elements in the array are true (or non-zero).
array tan(const array &a, StreamOrDevice s={})
Tangent of the elements of an array.
array eye(int n, int m, int k, Dtype dtype, StreamOrDevice s={})
Fill an array of the given shape (n,m) with ones in the specified diagonal k, and zeros everywhere el...
array identity(int n, Dtype dtype, StreamOrDevice s={})
Create a square matrix of shape (n,n) of zeros, and ones in the major diagonal.
array operator>>(const array &a, const array &b)
array minimum(const array &a, const array &b, StreamOrDevice s={})
Element-wise minimum between two arrays.
array prod(const array &a, bool keepdims, StreamOrDevice s={})
The product of all elements of the array.
array atleast_3d(const array &a, StreamOrDevice s={})
array operator<=(const array &a, const array &b)
Definition ops.h:375
array reciprocal(const array &a, StreamOrDevice s={})
The reciprocal (1/x) of the elements in an array.
array tri(int n, int m, int k, Dtype type, StreamOrDevice s={})
array flatten(const array &a, int start_axis, int end_axis=-1, StreamOrDevice s={})
Flatten the dimensions in the range [start_axis, end_axis] .
array isclose(const array &a, const array &b, double rtol=1e-5, double atol=1e-8, bool equal_nan=false, StreamOrDevice s={})
Returns a boolean array where two arrays are element-wise equal within the specified tolerance.
array operator|(const array &a, const array &b)
array topk(const array &a, int k, StreamOrDevice s={})
Returns topk elements of the flattened array.
array expm1(const array &a, StreamOrDevice s={})
Computes the expm1 function of the elements of an array.
array ones(const std::vector< int > &shape, Dtype dtype, StreamOrDevice s={})
Fill an array of the given shape with ones.
array abs(const array &a, StreamOrDevice s={})
Absolute value of elements in an array.
std::vector< array > meshgrid(const std::vector< array > &arrays, bool sparse=false, std::string indexing="xy", StreamOrDevice s={})
A vector of coordinate arrays from coordinate vectors.
array conjugate(const array &a, StreamOrDevice s={})
array tanh(const array &a, StreamOrDevice s={})
Hyperbolic Tangent of the elements of an array.
array quantized_matmul(const array &x, const array &w, const array &scales, const array &biases, bool transpose=true, int group_size=64, int bits=4, StreamOrDevice s={})
Quantized matmul multiplies x with a quantized matrix w.
array inner(const array &a, const array &b, StreamOrDevice s={})
Compute the inner product of two vectors.
array block_masked_mm(array a, array b, int block_size, std::optional< array > mask_out=std::nullopt, std::optional< array > mask_lhs=std::nullopt, std::optional< array > mask_rhs=std::nullopt, StreamOrDevice s={})
Compute matrix product with block masking.
array arctan2(const array &a, const array &b, StreamOrDevice s={})
Inverse tangent of the ratio of two arrays.
array number_of_elements(const array &a, std::vector< int > axes, bool inverted, Dtype dtype=int32, StreamOrDevice s={})
Extract the number of elements along some axes as a scalar array.
array conv3d(const array &input, const array &weight, const std::tuple< int, int, int > &stride={1, 1, 1}, const std::tuple< int, int, int > &padding={0, 0, 0}, const std::tuple< int, int, int > &dilation={1, 1, 1}, int groups=1, StreamOrDevice s={})
3D convolution with a filter
array log(const array &a, StreamOrDevice s={})
Natural logarithm of the elements of an array.
array sigmoid(const array &a, StreamOrDevice s={})
Element-wise logistic sigmoid of the array: 1 / (1 + exp(-x).
array squeeze(const array &a, const std::vector< int > &axes, StreamOrDevice s={})
Remove singleton dimensions at the given axes.
array greater_equal(const array &a, const array &b, StreamOrDevice s={})
Returns bool array with (a >= b) element-wise.
array expand_dims(const array &a, const std::vector< int > &axes, StreamOrDevice s={})
Add a singleton dimension at the given axes.
array isfinite(const array &a, StreamOrDevice s={})
array conv2d(const array &input, const array &weight, const std::pair< int, int > &stride={1, 1}, const std::pair< int, int > &padding={0, 0}, const std::pair< int, int > &dilation={1, 1}, int groups=1, StreamOrDevice s={})
2D convolution with a filter
array operator>(const array &a, const array &b)
Definition ops.h:333
array bitwise_and(const array &a, const array &b, StreamOrDevice s={})
Bitwise and.
std::vector< array > split(const array &a, int num_splits, int axis, StreamOrDevice s={})
Split an array into sub-arrays along a given axis.
array matmul(const array &a, const array &b, StreamOrDevice s={})
Matrix-matrix multiplication.
array logical_and(const array &a, const array &b, StreamOrDevice s={})
Logical and of two arrays.
array erfinv(const array &a, StreamOrDevice s={})
Computes the inverse error function of the elements of an array.
array divide(const array &a, const array &b, StreamOrDevice s={})
Divide two arrays.
array power(const array &a, const array &b, StreamOrDevice s={})
Raise elements of a to the power of b element-wise.
array maximum(const array &a, const array &b, StreamOrDevice s={})
Element-wise maximum between two arrays.
array reshape(const array &a, std::vector< int > shape, StreamOrDevice s={})
Reshape an array to the given shape.
array argmin(const array &a, bool keepdims, StreamOrDevice s={})
Returns the index of the minimum value in the array.
array var(const array &a, bool keepdims, int ddof=0, StreamOrDevice s={})
Computes the variance of the elements of an array.
array full(std::vector< int > shape, array vals, Dtype dtype, StreamOrDevice s={})
Fill an array of the given shape with the given value(s).
array softmax(const array &a, const std::vector< int > &axes, bool precise=false, StreamOrDevice s={})
Softmax of an array.
array sort(const array &a, StreamOrDevice s={})
Returns a sorted copy of the flattened array.
array max(const array &a, bool keepdims, StreamOrDevice s={})
The maximum of all elements of the array.
array pad(const array &a, const std::vector< int > &axes, const std::vector< int > &low_pad_size, const std::vector< int > &high_pad_size, const array &pad_value=array(0), const std::string mode="constant", StreamOrDevice s={})
Pad an array with a constant value.
array addmm(array c, array a, array b, const float &alpha=1.f, const float &beta=1.f, StreamOrDevice s={})
Compute D = beta * C + alpha * (A @ B)
array tril(array x, int k=0, StreamOrDevice s={})
array any(const array &a, bool keepdims, StreamOrDevice s={})
True if any elements in the array are true (or non-zero).
array outer(const array &a, const array &b, StreamOrDevice s={})
Compute the outer product of two vectors.
array hadamard_transform(const array &a, std::optional< float > scale=std::nullopt, StreamOrDevice s={})
Multiply the array by the Hadamard matrix of corresponding size.
array arcsin(const array &a, StreamOrDevice s={})
Arc Sine of the elements of an array.
array left_shift(const array &a, const array &b, StreamOrDevice s={})
Shift bits to the left.
array where(const array &condition, const array &x, const array &y, StreamOrDevice s={})
Select from x or y depending on condition.
array exp(const array &a, StreamOrDevice s={})
Exponential of the elements of an array.
array bitwise_or(const array &a, const array &b, StreamOrDevice s={})
Bitwise inclusive or.
array gather_mm(array a, array b, std::optional< array > lhs_indices=std::nullopt, std::optional< array > rhs_indices=std::nullopt, StreamOrDevice s={})
Compute matrix product with matrix-level gather.
array floor(const array &a, StreamOrDevice s={})
Floor the element of an array.
array conv_transpose3d(const array &input, const array &weight, const std::tuple< int, int, int > &stride={1, 1, 1}, const std::tuple< int, int, int > &padding={0, 0, 0}, const std::tuple< int, int, int > &dilation={1, 1, 1}, int groups=1, StreamOrDevice s={})
3D transposed convolution with a filter
array as_strided(array a, std::vector< int > shape, std::vector< size_t > strides, size_t offset, StreamOrDevice s={})
Create a view of an array with the given shape and strides.
array argsort(const array &a, StreamOrDevice s={})
Returns indices that sort the flattened array.
array array_equal(const array &a, const array &b, bool equal_nan, StreamOrDevice s={})
True if two arrays have the same shape and elements.
array isinf(const array &a, StreamOrDevice s={})
array less(const array &a, const array &b, StreamOrDevice s={})
Returns bool array with (a < b) element-wise.
array diagonal(const array &a, int offset=0, int axis1=0, int axis2=1, StreamOrDevice s={})
Extract a diagonal or construct a diagonal array.
array ones_like(const array &a, StreamOrDevice s={})
array negative(const array &a, StreamOrDevice s={})
Negate an array.
array linspace(double start, double stop, int num=50, Dtype dtype=float32, StreamOrDevice s={})
A 1D array of num evenly spaced numbers in the range [start, stop]
array remainder(const array &a, const array &b, StreamOrDevice s={})
Compute the element-wise remainder of division.
array arctan(const array &a, StreamOrDevice s={})
Arc Tangent of the elements of an array.
array conv_transpose1d(const array &input, const array &weight, int stride=1, int padding=0, int dilation=1, int groups=1, StreamOrDevice s={})
1D transposed convolution with a filter
std::vector< array > divmod(const array &a, const array &b, StreamOrDevice s={})
Compute the element-wise quotient and remainder.
array triu(array x, int k=0, StreamOrDevice s={})
array arccosh(const array &a, StreamOrDevice s={})
Inverse Hyperbolic Cosine of the elements of an array.
array tile(const array &arr, std::vector< int > reps, StreamOrDevice s={})
array nan_to_num(const array &a, float nan=0.0f, const std::optional< float > posinf=std::nullopt, const std::optional< float > neginf=std::nullopt, StreamOrDevice s={})
Replace NaN and infinities with finite numbers.
array min(const array &a, bool keepdims, StreamOrDevice s={})
The minimum of all elements of the array.
array operator%(const array &a, const array &b)
std::tuple< array, array, array > quantize(const array &w, int group_size=64, int bits=4, StreamOrDevice s={})
Quantize a matrix along its last axis.
array arctanh(const array &a, StreamOrDevice s={})
Inverse Hyperbolic Tangent of the elements of an array.
array repeat(const array &arr, int repeats, int axis, StreamOrDevice s={})
Repeat an array along an axis.
array gather(const array &a, const std::vector< array > &indices, const std::vector< int > &axes, const std::vector< int > &slice_sizes, StreamOrDevice s={})
Gather array entries given indices and slices.
std::vector< array > broadcast_arrays(const std::vector< array > &inputs, StreamOrDevice s={})
Broadcast a vector of arrays against one another.
array atleast_1d(const array &a, StreamOrDevice s={})
convert an array to an atleast ndim array
array swapaxes(const array &a, int axis1, int axis2, StreamOrDevice s={})
Swap two axes of an array.
array logical_not(const array &a, StreamOrDevice s={})
Logical not of an array.
array concatenate(const std::vector< array > &arrays, int axis, StreamOrDevice s={})
Concatenate arrays along a given axis.
array trace(const array &a, int offset, int axis1, int axis2, Dtype dtype, StreamOrDevice s={})
Return the sum along a specified diagonal in the given array.
array dequantize(const array &w, const array &scales, const array &biases, int group_size=64, int bits=4, StreamOrDevice s={})
Dequantize a matrix produced by quantize()
array transpose(const array &a, std::vector< int > axes, StreamOrDevice s={})
Permutes the dimensions according to the given axes.
array partition(const array &a, int kth, StreamOrDevice s={})
Returns a partitioned copy of the flattened array such that the smaller kth elements are first.
array take(const array &a, const array &indices, int axis, StreamOrDevice s={})
Take array slices at the given indices of the specified axis.
array operator^(const array &a, const array &b)
std::vector< array > depends(const std::vector< array > &inputs, const std::vector< array > &dependencies)
Implements the identity function but allows injecting dependencies to other arrays.
array arcsinh(const array &a, StreamOrDevice s={})
Inverse Hyperbolic Sine of the elements of an array.
array scatter_add(const array &a, const std::vector< array > &indices, const array &updates, const std::vector< int > &axes, StreamOrDevice s={})
Scatter and add updates to given indices.
array logsumexp(const array &a, bool keepdims, StreamOrDevice s={})
The logsumexp of all elements of the array.
array broadcast_to(const array &a, const std::vector< int > &shape, StreamOrDevice s={})
Broadcast an array to a given shape.
array scatter(const array &a, const std::vector< array > &indices, const array &updates, const std::vector< int > &axes, StreamOrDevice s={})
Scatter updates to the given indices.
array operator<<(const array &a, const array &b)
array slice(const array &a, std::vector< int > start, std::vector< int > stop, std::vector< int > strides, StreamOrDevice s={})
Slice an array.
array isposinf(const array &a, StreamOrDevice s={})
array cumsum(const array &a, int axis, bool reverse=false, bool inclusive=true, StreamOrDevice s={})
Cumulative sum of an array.
array operator-(const array &a)
array mean(const array &a, bool keepdims, StreamOrDevice s={})
Computes the mean of the elements of an array.
array sum(const array &a, bool keepdims, StreamOrDevice s={})
Sums the elements of an array.
array take_along_axis(const array &a, const array &indices, int axis, StreamOrDevice s={})
Take array entries given indices along the axis.
array argmax(const array &a, bool keepdims, StreamOrDevice s={})
Returns the index of the maximum value in the array.
array conv_transpose2d(const array &input, const array &weight, const std::pair< int, int > &stride={1, 1}, const std::pair< int, int > &padding={0, 0}, const std::pair< int, int > &dilation={1, 1}, int groups=1, StreamOrDevice s={})
2D transposed convolution with a filter
array sin(const array &a, StreamOrDevice s={})
Sine of the elements of an array.
array operator&&(const array &a, const array &b)
array cummax(const array &a, int axis, bool reverse=false, bool inclusive=true, StreamOrDevice s={})
Cumulative max of an array.
array operator<(const array &a, const array &b)
Definition ops.h:361
array atleast_2d(const array &a, StreamOrDevice s={})
array operator/(const array &a, const array &b)
array allclose(const array &a, const array &b, double rtol=1e-5, double atol=1e-8, bool equal_nan=false, StreamOrDevice s={})
True if the two arrays are equal within the specified tolerance.
array operator&(const array &a, const array &b)
array argpartition(const array &a, int kth, StreamOrDevice s={})
Returns indices that partition the flattened array such that the smaller kth elements are first.
array greater(const array &a, const array &b, StreamOrDevice s={})
Returns bool array with (a > b) element-wise.
array sinh(const array &a, StreamOrDevice s={})
Hyperbolic Sine of the elements of an array.
array multiply(const array &a, const array &b, StreamOrDevice s={})
Multiply two arrays.
array tensordot(const array &a, const array &b, const int axis=2, StreamOrDevice s={})
Returns a contraction of a and b over multiple dimensions.
array stack(const std::vector< array > &arrays, int axis, StreamOrDevice s={})
Stack arrays along a new axis.
array logaddexp(const array &a, const array &b, StreamOrDevice s={})
Log-add-exp of one elements in the array: log(exp(a) + exp(b)).
array right_shift(const array &a, const array &b, StreamOrDevice s={})
Shift bits to the right.
array zeros_like(const array &a, StreamOrDevice s={})
Definition allocator.h:7
void arange(const std::vector< array > &inputs, array &out, double start, double step)
Definition arange.h:24
Stream to_stream(StreamOrDevice s)
void copy(const array &src, array &dst, CopyType ctype)
constexpr Dtype int32
Definition dtype.h:67
constexpr Dtype float32
Definition dtype.h:71
bool operator==(const Device &lhs, const Device &rhs)
bool operator!=(const Device &lhs, const Device &rhs)
std::variant< std::monostate, Stream, Device > StreamOrDevice
Definition utils.h:14
Definition dtype.h:13