-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathcore.cairo
3287 lines (3212 loc) · 105 KB
/
core.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use array::{ArrayTrait, SpanTrait};
use serde::Serde;
use option::OptionTrait;
use alexandria_data_structures::array_ext::{SpanTraitExt};
use orion::operators::tensor::helpers::{len_from_shape, check_shape};
use orion::numbers::{i8, i32, NumberTrait};
#[derive(Copy, Drop)]
struct Tensor<T> {
shape: Span<usize>,
data: Span<T>,
}
//Implement TensorSerde
impl TensorSerde<T, impl TSerde: Serde<T>, impl TDrop: Drop<T>> of Serde<Tensor<T>> {
fn serialize(self: @Tensor<T>, ref output: Array<felt252>) {
self.shape.serialize(ref output);
self.data.serialize(ref output);
}
fn deserialize(ref serialized: Span<felt252>) -> Option<Tensor<T>> {
let shape: Span<usize> = Serde::<Span<usize>>::deserialize(ref serialized)?;
let data: Span<T> = Serde::<Span<T>>::deserialize(ref serialized)?;
Option::Some(Tensor { shape, data })
}
}
/// Trait
///
/// new - Returns a new tensor with the given shape and data.
/// reshape - Returns a new tensor with the specified target shape and the same data as the input tensor.
/// flatten - Flattens the input tensor into a 2D tensor.
/// transpose - Returns a new tensor with the axes rearranged according to the given permutation.
/// at - Retrieves the value at the specified indices of a Tensor.
/// ravel_index - Converts a multi-dimensional index to a one-dimensional index.
/// unravel_index - Converts a one-dimensional index to a multi-dimensional index.
/// equal - Check if two tensors are equal element-wise.
/// greater - Check if each element of the first tensor is greater than the corresponding element of the second tensor.
/// greater_equal - Check if each element of the first tensor is greater than or equal to the corresponding element of the second tensor.
/// less - Check if each element of the first tensor is less than the corresponding element of the second tensor.
/// less_equal - Check if each element of the first tensor is less than or equal to the corresponding element of the second tensor.
/// or - Computes the logical OR of two tensors element-wise.
/// xor - Computes the logical XOR of two tensors element-wise.
/// stride - Computes the stride of each dimension in the tensor.
/// onehot - Produces one-hot tensor based on input.
/// min - Returns the minimum value in the tensor.
/// max - Returns the maximum value in the tensor.
/// reduce_sum - Reduces a tensor by summing its elements along a specified axis.
/// argmax - Returns the index of the maximum value along the specified axis.
/// argmin - Returns the index of the minimum value along the specified axis.
/// cumsum - Performs cumulative sum of the input elements along the given axis.
/// matmul - Performs matrix product of two tensors.
/// exp - Computes the exponential of all elements of the input tensor.
/// log - Computes the natural log of all elements of the input tensor.
/// abs - Computes the absolute value of all elements in the input tensor.
/// neg - Computes the negation of all elements in the input tensor.
/// ceil - Rounds up the value of each element in the input tensor.
/// sqrt - Computes the square root of all elements of the input tensor.
/// sin - Computes the sine of all elements of the input tensor.
/// cos - Computes the cosine of all elements of the input tensor.
/// atan - Computes the arctangent (inverse of tangent) of all elements of the input tensor.
/// asin - Computes the arcsine (inverse of sine) of all elements of the input tensor.
/// acos - Computes the arccosine (inverse of cosine) of all elements of the input tensor.
/// sinh - Computes the hyperbolic sine of all elements of the input tensor.
/// tanh - Computes the hyperbolic tangent of all elements of the input tensor.
/// cosh - Computes the hyperbolic cosine of all elements of the input tensor.
/// asinh - Computes the inverse hyperbolic sine of all elements of the input tensor.
/// acosh - Computes the inverse hyperbolic cosine of all elements of the input tensor.
/// slice - Produces a slice of the input tensor along multiple axes.
/// concat - Concatenate a list of tensors into a single tensor.
/// quantize_linear - Quantizes a Tensor to i8 using linear quantization.
/// dequantize_linear - Dequantizes an i8 Tensor using linear dequantization.
/// gather - Gather entries of the axis dimension of data.
/// nonzero - Produces indices of the elements that are non-zero (in row-major order - by dimension).
/// squeeze - Removes dimensions of size 1 from the shape of a tensor.
/// unsqueeze - Inserts single-dimensional entries to the shape of an input tensor.
/// sign - Calculates the sign of the given input tensor element-wise.
/// clip - Clip operator limits the given input within an interval.
///
trait TensorTrait<T> {
/// # tensor.new
///
/// ```rust
/// fn new(shape: Span<usize>, data: Span<T>) -> Tensor<T>;
/// ```
///
/// Returns a new tensor with the given shape and data.
///
/// ## Args
///
/// * `shape`(`Span<usize>`) - A span representing the shape of the tensor.
/// * `data` (`Span<T>`) - A span containing the array of elements.
///
/// ## Panics
///
/// * Panics if the shape and data length are incompatible.
///
/// ## Returns
///
/// A new `Tensor<T>` instance.
///
/// ## Examples
///
/// Let's create new u32 Tensors.
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{
/// TensorTrait, // we import the trait
/// Tensor, // we import the type
/// U32Tensor // we import the implementation.
/// };
///
/// // 1D TENSOR
/// fn tensor_1D() -> Tensor<u32> {
/// let tensor = TensorTrait::new(shape: array![3].span(), data: array![0, 1, 2].span());
///
/// return tensor;
/// }
///
/// // 2D TENSOR
/// fn tensor_2D() -> Tensor<u32> {
/// let tensor = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span());
///
/// return tensor;
/// }
///
/// // 3D TENSOR
/// fn tensor_3D() -> Tensor<u32> {
/// let tensor = TensorTrait::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// return tensor;
/// }
/// ```
///
fn new(shape: Span<usize>, data: Span<T>) -> Tensor<T>;
/// # tensor.at
///
/// ```rust
/// fn at(self: @Tensor<T>, indices: Span<usize>) -> T;
/// ```
///
/// Retrieves the value at the specified indices of a Tensor.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `indices`(`Span<usize>`) - The indices to access element of the Tensor.
///
/// ## Panics
///
/// * Panics if the number of indices provided don't match the number of dimensions in the tensor.
///
/// ## Returns
///
/// The `T` value at the specified indices.
///
/// # Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
///
/// fn at_example() -> u32 {
/// let tensor = TensorTrait::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `at` function as follows.
/// return tensor.at(indices: array![0, 1, 1].span());
/// }
/// >>> 3
/// ```
///
fn at(self: @Tensor<T>, indices: Span<usize>) -> T;
/// # tensor.min
///
/// ```rust
/// fn min(self: @Tensor<T>) -> T;
/// ```
///
/// Returns the minimum value in the tensor.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
///
/// ## Returns
///
/// The minimum `T` value in the tensor.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn min_example() -> u32 {
/// let tensor = TensorTrait::new(
/// shape: array![2, 2, 2].span(),
/// data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `min` function as follows.
/// return tensor.min();
/// }
/// >>> 0
/// ```
///
fn min(self: @Tensor<T>) -> T;
/// # tensor.max
///
/// ```rust
/// fn max(self: @Tensor<T>) -> T;
/// ```
///
/// Returns the maximum value in the tensor.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
///
/// ## Returns
///
/// The maximum `T` value in the tensor.
///
/// Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn max_example() -> u32 {
/// let tensor = TensorTrait::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `max` function as follows.
/// return tensor.max();
/// }
/// >>> 7
/// ```
///
fn max(self: @Tensor<T>) -> T;
/// # tensor.stride
///
/// ```rust
/// fn stride(self: @Tensor<T>) -> Span<usize>;
/// ```
///
/// Computes the stride of each dimension in the tensor.
///
/// ## Args
/// * `self`(`@Tensor<T>`) - The input tensor.
///
/// ## Returns
///
/// A span of usize representing the stride for each dimension of the tensor.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn stride_example() -> Span<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `stride` function as follows.
/// return tensor.stride();
/// }
/// >>> [4,2,1]
/// ```
///
fn stride(self: @Tensor<T>) -> Span<usize>;
/// # tensor.ravel_index
///
/// ```rust
/// fn ravel_index(self: @Tensor<T>, indices: Span<usize>) -> usize;
/// ```
///
/// Converts a multi-dimensional index to a one-dimensional index.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `indices`(`Span<usize>`) - The indices of the Tensor to ravel.
///
/// ## Panics
///
/// * Panics if the indices are out of bounds of the Tensor shape.
///
/// ## Returns
///
/// The index corresponding to the given indices.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn ravel_index_example() -> usize {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `ravel_index` function as follows.
/// return tensor.ravel_index(indices: array![1, 3, 0].span());
/// }
/// >>> 10
/// // This means that the value of indices [1,3,0]
/// // of a multidimensional array can be found at index 10 of Tensor.data.
/// ```
///
fn ravel_index(self: @Tensor<T>, indices: Span<usize>) -> usize;
/// # tensor.unravel_index
///
/// ```rust
/// fn unravel_index(self: @Tensor<T>, index: usize) -> Span<usize>;
/// ```
///
/// Converts a one-dimensional index to a multi-dimensional index.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `indices`(`Span<usize>`) - The index to unravel.
///
/// ## Panics
///
/// * Panics if the index is out of bounds of the Tensor shape.
///
/// ## Returns
///
/// The unraveled indices corresponding to the given index.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn unravel_index_example() -> Span<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `unravel_index` function as follows.
/// return tensor.unravel_index(3);
/// }
/// >>> [0,1,1]
/// // This means that the value of index 3 of Tensor.data
/// // can be found at indices [0,1,1] in multidimensional representation.
/// ```
///
fn unravel_index(self: @Tensor<T>, index: usize) -> Span<usize>;
/// # tensor.reshape
///
/// ```rust
/// fn reshape(self: @Tensor<T>, target_shape: Span<usize>) -> Tensor<T>;
/// ```
///
/// Returns a new tensor with the specified target shape and the same data as the input tensor.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `target_shape`(Span<usize>) - A span containing the target shape of the tensor.
///
/// ## Panics
///
/// * Panics if the target shape is incompatible with the input tensor's data.
///
/// ## Returns
///
/// A new `Tensor<T>` with the specified target shape and the same data.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn reshape_tensor_example() -> Tensor<u32> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `reshape` function as follows.
/// return tensor.reshape(target_shape: array![2, 4].span());
/// }
/// >>> [[0,1,2,3], [4,5,6,7]]
/// ```
///
fn reshape(self: @Tensor<T>, target_shape: Span<usize>) -> Tensor<T>;
/// # tensor.transpose
///
/// ```rust
/// fn transpose(self: @Tensor<T>, axes: Span<usize>) -> Tensor<T>;
/// ```
///
/// Returns a new tensor with the axes rearranged according to the given permutation.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `axes`(`Span<usize>`) - The usize elements representing the axes to be transposed.
///
/// ## Panics
///
/// * Panics if the length of the axes array is not equal to the rank of the input tensor.
///
/// ## Returns
///
/// A `Tensor<T>` instance with the axes reordered according to the given permutation.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn transpose_tensor_example() -> Tensor<u32> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `transpose` function as follows.
/// return tensor.transpose(axes: array![1, 2, 0].span());
/// }
/// >>> [[[0,4],[1,5]],[[2,6],[3,7]]]
/// ```
///
fn transpose(self: @Tensor<T>, axes: Span<usize>) -> Tensor<T>;
/// ## tensor.reduce_sum
///
/// ```rust
/// fn reduce_sum(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
/// ```
///
/// Reduces a tensor by summing its elements along a specified axis.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `axis`(`usize`) - The dimension to reduce.
/// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1.
///
/// ## Panics
///
/// * Panics if axis is not in the range of the input tensor's dimensions.
///
/// ## Returns
///
/// A new `Tensor<T>` instance with the specified axis reduced by summing its elements.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn reduce_sum_example() -> Tensor<u32> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
/// );
///
/// // We can call `reduce_sum` function as follows.
/// return tensor.reduce_sum(axis: 0, keepdims: false);
/// }
/// >>> [[4,6],[8,10]]
/// ```
///
fn reduce_sum(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
/// # tensor.argmax
///
/// ```rust
/// fn argmax(self: @Tensor<T>, axis: usize, keepdims: Option<bool>, select_last_index: Option<bool>) -> Tensor<usize>;
/// ```
///
/// Returns the index of the maximum value along the specified axis.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `axis`(`usize`) - The axis along which to compute the argmax.
/// * `keepdims`(`Option<bool>`) - If true, retains reduced dimensions with length 1. Defaults to true.
/// * `select_last_index`(`Option<bool>`) - If true, the index of the last occurrence of the maximum value is returned. Defaults to false.
///
/// ## Panics
///
/// * Panics if axis is not in the range of the input tensor's dimensions.
///
/// ## Returns
///
/// A new `Tensor<T>` instance containing the indices of the maximum values along the specified axis.
///
/// ## Examples
///
/// Case 1: argmax with default parameters
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmax_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmax` function as follows.
/// return tensor.argmax(axis: 2, keepdims: Option::None(()), select_last_index: Option::None(()));
/// }
/// >>> [[[1,1],[0,0]]]
/// ```
/// Case 2: argmax with keepdims set to false
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmax_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmax` function as follows.
/// return tensor
/// .argmax(axis: 2, keepdims: Option::Some(false), select_last_index: Option::None(()));
/// }
/// >>> [[1,1],[0,0]]
/// ```
///
/// Case 3: argmax with select_last_index set to true
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmax_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmax` function as follows.
/// return tensor
/// .argmax(axis: 2, keepdims: Option::None(()), select_last_index: Option::Some(true));
/// }
/// >>> [[[1,1],[1,1]]]
/// ```
///
fn argmax(
self: @Tensor<T>, axis: usize, keepdims: Option<bool>, select_last_index: Option<bool>
) -> Tensor<usize>;
/// # tensor.argmin
///
/// ```rust
/// fn argmin(self: @Tensor<T>, axis: usize, keepdims: Option<bool>, select_last_index: Option<bool>) -> Tensor<usize>;
/// ```
///
/// Returns the index of the minimum value along the specified axis.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
/// * `axis`(`usize`) - The axis along which to compute the argmin.
/// * `keepdims`(`Option<bool>`) - If true, retains reduced dimensions with length 1. Defaults to true.
/// * `select_last_index`(`Option<bool>`) - If true, the index of the last occurrence of the minimum value is returned. Defaults to false.
///
/// ## Panics
///
/// * Panics if axis is not in the range of the input tensor's dimensions.
///
/// ## Returns
///
/// A new `Tensor<T>` instance containing the indices of the minimum values along the specified axis.
///
/// ## Examples
///
/// Case 1: argmin with default parameters
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmin_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmin` function as follows.
/// return tensor.argmin(axis: 2, keepdims: Option::None(()), select_last_index: Option::None(()));
/// }
/// >>> [[[0,0],[0,0]]]
///
/// ```
/// Case 2: argmin with keepdims set to false
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmin_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmin` function as follows.
/// return tensor
/// .argmin(axis: 2, keepdims: Option::Some(false), select_last_index: Option::None(()));
/// }
/// >>> [[0,0],[0,0]]
/// ```
///
/// Case 3: argmin with select_last_index set to true
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn argmin_example() -> Tensor<usize> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 4, 5, 5].span(),
/// );
///
/// // We can call `argmin` function as follows.
/// return tensor
/// .argmin(axis: 2, keepdims: Option::None(()), select_last_index: Option::Some(true));
/// }
/// >>> [[[0,0],[1,1]]]
/// ```
///
fn argmin(
self: @Tensor<T>, axis: usize, keepdims: Option<bool>, select_last_index: Option<bool>
) -> Tensor<usize>;
/// # tensor.matmul
///
/// ```rust
/// fn matmul(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<T>;
/// ```
///
/// Performs matrix product of two tensors.
/// The behavior depends on the dimensionality of the tensors as follows:
/// * If both tensors are 1-dimensional, the dot product is returned.
/// * If both arguments are 2-dimensional, the matrix-matrix product is returned.
/// * If the first argument is 1-dimensional and the second argument is 2-dimensional, a 1 is prepended to its dimension for the purpose of the matrix multiply. After the matrix multiply, the prepended dimension is removed.
/// * If the first argument is 2-dimensional and the second argument is 1-dimensional, the matrix-vector product is returned.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - the first tensor to be multiplied
/// * `other`(`@Tensor<T>`) - the second tensor to be multiplied
///
/// ## Panics
///
/// * Panics if the dimension of the tensors is higher than two.
///
/// ## Returns
///
/// A new `Tensor<T>` resulting from the matrix multiplication.
///
/// ## Examples
///
/// Case 1: Dot product of two vectors (1D \* 1D)
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn dot_product_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(shape: array![3].span(), data: array![0, 1, 2].span(),);
///
/// let tensor_2 = TensorTrait::<u32>::new(shape: array![3].span(), data: array![0, 1, 2].span(),);
///
/// // We can call `matmul` function as follows.
/// return tensor_1.matmul(@tensor_2);
/// }
/// >>> [5]
/// ```
///
/// Case 2: Matrix multiplication (2D \* 2D)
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn matrix_mul_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![2, 2].span(), data: array![244, 99, 109, 162].span()
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(
/// shape: array![2, 2].span(), data: array![151, 68, 121, 170].span()
/// );
///
/// // We can call `matmul` function as follows.
/// return tensor_1.matmul(@tensor_2);
/// }
/// >>> [[48823, 33422],[36061, 34952]]
/// ```
///
/// Case 3: Matrix-Vector multiplication (2D x 1D)
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn matrix_vec_mul_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(shape: array![3].span(), data: array![0, 1, 2].span(),);
///
/// // We can call `matmul` function as follows.
/// return tensor_1.matmul(@tensor_2);
/// }
/// >>> [5,14,23]
/// ```
///
fn matmul(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<T>;
/// # tensor.exp
///
/// ```rust
/// fn exp(self: @Tensor<T>) -> Tensor<T>;
/// ```
///
/// Computes the exponential of all elements of the input tensor.
/// $$
/// y_i=e^{x_i}
/// $$
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
///
/// ## Returns
///
/// Returns a new tensor in `T` with the exponential of the elements of the input tensor.
///
/// ## Type Constraints
///
/// Constrain input and output types to fixed point tensors.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor};
/// use orion::numbers::{FP8x23, FixedTrait};
///
/// fn exp_example() -> Tensor<FP8x23> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2].span(),
/// data: array![
/// FixedTrait::new_unscaled(0, false),
/// FixedTrait::new_unscaled(1, false),
/// FixedTrait::new_unscaled(2, false),
/// FixedTrait::new_unscaled(3, false),
/// ]
/// );
///
/// // We can call `exp` function as follows.
/// return tensor.exp();
/// }
/// >>> [[8388608,22802594],[61983844,168489688]]
/// // The fixed point representation of
/// // [[1, 2.718281],[7.38905, 20.085536]]
/// ```
///
fn exp(self: @Tensor<T>) -> Tensor<T>;
/// # tensor.log
///
/// ```rust
/// fn log(self: @Tensor<T>) -> Tensor<T>;
/// ```
///
/// Computes the natural log of all elements of the input tensor.
/// $$
/// y_i=log({x_i})
/// $$
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The input tensor.
///
/// ## Returns
///
/// Returns a new tensor in `T` with the natural log of the elements of the input tensor.
///
/// ## Type Constraints
///
/// Constrain input and output types to fixed point tensors.
///
/// ## Examples
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor};
/// use orion::numbers::{FP8x23, FixedTrait};
///
/// fn log_example() -> Tensor<FP8x23> {
/// let tensor = TensorTrait::<u32>::new(
/// shape: array![2, 2].span(),
/// data: array![
/// FixedTrait::new_unscaled(0, false),
/// FixedTrait::new_unscaled(1, false),
/// FixedTrait::new_unscaled(2, false),
/// FixedTrait::new_unscaled(100, false),
/// ]
/// );
///
/// // We can call `log` function as follows.
/// return tensor.log();
/// }
/// >>> [[0, 5814538, 9215825, 38630966]]
/// // The fixed point representation of
/// /// [[0, 0.693147, 1.098612, 4.605170]]
/// ```
///
fn log(self: @Tensor<T>) -> Tensor<T>;
/// #tensor.equal
///
/// ```rust
/// fn equal(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
/// ```
///
/// Check if two tensors are equal element-wise.
/// The input tensors must have either:
/// * Exactly the same shape
/// * The same number of dimensions and the length of each dimension is either a common length or 1.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The first tensor to be equated
/// * `other`(`@Tensor<T>`) - The second tensor to be equated
///
/// ## Panics
///
/// * Panics if the shapes are not equal or broadcastable
///
/// ## Returns
///
/// A new `Tensor<usize>` of booleans (1 if equal, 0 otherwise) with the same shape as the broadcasted inputs.
///
/// ## Examples
///
/// Case 1: Compare tensors with same shape
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn eq_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 9, 1, 5].span(),
/// );
///
/// // We can call `equal` function as follows.
/// return tensor_1.equal(@tensor_2);
/// }
/// >>> [1,1,1,1,1,0,0,0]
/// ```
///
/// Case 2: Compare tensors with different shapes
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn eq_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(shape: array![3].span(), data: array![0, 1, 2].span(),);
///
/// // We can call `equal` function as follows.
/// return tensor_1.equal(@tensor_2);
/// }
/// >>> [1,1,1,0,0,0,0,0,0]
/// ```
///
fn equal(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
/// #tensor.greater
///
/// ```rust
/// fn greater(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
/// ```
///
/// Check if each element of the first tensor is greater than the corresponding element of the second tensor.
/// The input tensors must have either:
/// * Exactly the same shape
/// * The same number of dimensions and the length of each dimension is either a common length or 1.
///
/// ## Args
///
/// * `self`(`@Tensor<T>`) - The first tensor to be compared
/// * `other`(`@Tensor<T>`) - The second tensor to be compared
///
/// ## Panics
///
/// * Panics if the shapes are not equal or broadcastable
///
/// ## Returns
///
/// A new `Tensor<usize>` of booleans (0 or 1) with the same shape as the broadcasted inputs.
///
/// ## Examples
///
/// Case 1: Compare tensors with same shape
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn greater_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 9, 1, 5].span(),
/// );
///
/// // We can call `greater` function as follows.
/// return tensor_1.greater(@tensor_2);
/// }
/// >>> [0,0,0,0,0,0,0,1,1]
/// ```
///
/// Case 2: Compare tensors with different shapes
///
/// ```rust
/// use array::{ArrayTrait, SpanTrait};
///
/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
///
/// fn greater_example() -> Tensor<usize> {
/// let tensor_1 = TensorTrait::<u32>::new(
/// shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
/// );
///
/// let tensor_2 = TensorTrait::<u32>::new(shape: array![3].span(), data: array![0, 1, 2].span(),);
///
/// // We can call `greater` function as follows.
/// return tensor_1.greater(@tensor_2);
/// }
/// >>> [0,0,0,1,1,1,1,1,1]
/// ```
///
fn greater(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
/// #tensor.greater_equal
///
/// ```rust
/// fn greater_equal(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
/// ```
///
/// Check if each element of the first tensor is greater than or equal to the corresponding element of the second tensor.
/// The input tensors must have either:
/// * Exactly the same shape
/// * The same number of dimensions and the length of each dimension is either a common length or 1.
///