hpt-traits 0.1.3

An internal library defines tensor operator traits for hpt
Documentation
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
use hpt_common::error::base::TensorError;
use hpt_types::{dtype::TypeCommon, into_scalar::Cast, type_promote::NormalOut};
use std::borrow::BorrowMut;

use crate::tensor::CommonBounds;

/// A trait for tensor unary operations, the output must be a floating point tensor
pub trait FloatUnaryOps {
    /// output tensor type
    type Output;
    /// output tensor type for inplace operation
    type InplaceOutput;
    /// output tensor data type
    type OutputMeta: Send;
    /// Computes sine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.sin()?;
    /// ```
    #[track_caller]
    fn sin(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes cosine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.cos()?;
    /// ```
    #[track_caller]
    fn cos(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes sine and cosine element-wise.
    ///
    /// # Example
    #[track_caller]
    fn sincos(&self) -> std::result::Result<(Self::Output, Self::Output), TensorError>;

    /// Computes tangent element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.tan()?;
    /// ```
    #[track_caller]
    fn tan(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes arcsine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.asin()?;
    /// ```
    #[track_caller]
    fn asin(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes arccosine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.acos()?;
    /// ```
    #[track_caller]
    fn acos(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes arctangent element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.atan()?;
    /// ```
    #[track_caller]
    fn atan(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes hyperbolic sine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.sinh()?;
    /// ```
    #[track_caller]
    fn sinh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes hyperbolic cosine element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.cosh()?;
    /// ```
    #[track_caller]
    fn cosh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes hyperbolic tangent element-wise.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.tanh()?;
    /// ```
    #[track_caller]
    fn tanh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes the element-wise asinh of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.asinh()?;
    /// ```
    #[track_caller]
    fn asinh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes the element-wise acosh of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.acosh()?;
    /// ```
    #[track_caller]
    fn acosh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Computes the element-wise atanh of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.atanh()?;
    /// ```
    #[track_caller]
    fn atanh(&self) -> std::result::Result<Self::Output, TensorError>;

    /// sin method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sin`]
    #[track_caller]
    fn sin_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// cos method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`cos`]
    #[track_caller]
    fn cos_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// tan method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`tan`]
    #[track_caller]
    fn tan_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// asin method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`asin`]
    #[track_caller]
    fn asin_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// acos method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`acos`]
    #[track_caller]
    fn acos_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// atan method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`atan`]
    #[track_caller]
    fn atan_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// sinh method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sinh`]
    #[track_caller]
    fn sinh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// cosh method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`cosh`]
    #[track_caller]
    fn cosh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// tanh method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`tanh`]
    #[track_caller]
    fn tanh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// asinh method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`asinh`]
    #[track_caller]
    fn asinh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// acosh method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`acosh`]
    #[track_caller]
    fn acosh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// atanh method with output tensor, this method will write the result to the output tensor
    ///
    /// # See Also
    /// - [`atanh`]
    #[track_caller]
    fn atanh_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// sincos method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sincos`]
    #[track_caller]
    fn sincos_<U, O>(
        &self,
        outs: (U, O),
    ) -> std::result::Result<(Self::InplaceOutput, Self::InplaceOutput), TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>,
        O: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise exponential of the tensor.
    #[track_caller]
    fn exp(&self) -> std::result::Result<Self::Output, TensorError>;

    /// exp method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`exp`]
    #[track_caller]
    fn exp_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise base-2 exponential of the tensor.
    #[track_caller]
    fn exp2(&self) -> std::result::Result<Self::Output, TensorError>;

    /// exp2 method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`exp2`]
    #[track_caller]
    fn exp2_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise base-10 exponential of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.exp10()?;
    /// ```
    #[track_caller]
    fn exp10(&self) -> std::result::Result<Self::Output, TensorError>;

    /// exp10 method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`exp10`]
    #[track_caller]
    fn exp10_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise square root of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.sqrt()?;
    /// ```
    #[track_caller]
    fn sqrt(&self) -> std::result::Result<Self::Output, TensorError>;

    /// sqrt method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sqrt`]
    #[track_caller]
    fn sqrt_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise reciprocal of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.recip()?;
    /// ```
    #[track_caller]
    fn recip(&self) -> std::result::Result<Self::Output, TensorError>;

    /// recip method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`recip`]
    #[track_caller]
    fn recip_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise natural logarithm of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.ln()?;
    /// ```
    #[track_caller]
    fn ln(&self) -> std::result::Result<Self::Output, TensorError>;

    /// ln method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`ln`]
    #[track_caller]
    fn ln_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise base-2 logarithm of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.log2()?;
    /// ```
    #[track_caller]
    fn log2(&self) -> std::result::Result<Self::Output, TensorError>;

    /// log2 method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`log2`]
    #[track_caller]
    fn log2_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise base-10 logarithm of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.log10()?;
    /// ```
    #[track_caller]
    fn log10(&self) -> std::result::Result<Self::Output, TensorError>;

    /// log10 method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`log10`]
    #[track_caller]
    fn log10_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Continuously Differentiable Exponential Linear Unit (CELU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.celu(1.0)?;
    /// ```
    #[track_caller]
    fn celu<V: Cast<Self::OutputMeta>>(
        &self,
        alpha: V,
    ) -> std::result::Result<Self::Output, TensorError>;

    /// celu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`celu`]
    #[track_caller]
    fn celu_<V, U>(
        &self,
        alpha: V,
        out: U,
    ) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        V: Cast<Self::OutputMeta>,
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise sigmoid activation function of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.sigmoid()?;
    /// ```
    #[track_caller]
    fn sigmoid(&self) -> std::result::Result<Self::Output, TensorError>;

    /// sigmoid method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sigmoid`]
    #[track_caller]
    fn sigmoid_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Exponential Linear Unit (ELU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.elu(1.0)?;
    /// ```
    #[track_caller]
    fn elu<V: Cast<Self::OutputMeta>>(
        &self,
        alpha: V,
    ) -> std::result::Result<Self::Output, TensorError>;

    /// elu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`elu`]
    #[track_caller]
    fn elu_<V, U>(&self, alpha: V, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        V: Cast<Self::OutputMeta>,
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise error function (erf) of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.erf()?;
    /// ```
    fn erf(&self) -> std::result::Result<Self::Output, TensorError>;

    /// erf method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`erf`]
    #[track_caller]
    fn erf_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Gaussian Error Linear Unit (GELU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.gelu()?;
    /// ```
    #[track_caller]
    fn gelu(&self) -> std::result::Result<Self::Output, TensorError>;

    /// gelu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`gelu`]
    #[track_caller]
    fn gelu_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Scaled Exponential Linear Unit (SELU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.selu()?;
    /// ```
    #[track_caller]
    fn selu(&self) -> std::result::Result<Self::Output, TensorError>;

    /// selu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`selu`]
    #[track_caller]
    fn selu_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Hard Sigmoid activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.hard_sigmoid()?;
    /// ```
    #[track_caller]
    fn hard_sigmoid(&self) -> std::result::Result<Self::Output, TensorError>;

    /// hard_sigmoid method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`hard_sigmoid`]
    #[track_caller]
    fn hard_sigmoid_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Hard Swish activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.hard_swish()?;
    /// ```
    #[track_caller]
    fn hard_swish(&self) -> std::result::Result<Self::Output, TensorError>;

    /// hard_swish method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`hard_swish`]
    #[track_caller]
    fn hard_swish_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Softplus activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.softplus()?;
    /// ```
    #[track_caller]
    fn softplus(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Softplus method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`softplus`]
    #[track_caller]
    fn softplus_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Softsign activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.softsign()?;
    /// ```
    #[track_caller]
    fn softsign(&self) -> std::result::Result<Self::Output, TensorError>;

    /// softsign method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`softsign`]
    #[track_caller]
    fn softsign_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Mish activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.mish()?;
    /// ```
    #[track_caller]
    fn mish(&self) -> std::result::Result<Self::Output, TensorError>;

    /// mish method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`mish`]
    #[track_caller]
    fn mish_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise cube root of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.cbrt()?;
    /// ```
    #[track_caller]
    fn cbrt(&self) -> std::result::Result<Self::Output, TensorError>;

    /// cbrt method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`cbrt`]
    #[track_caller]
    fn cbrt_<U>(&self, out: U) -> std::result::Result<Self::InplaceOutput, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;
}

/// A trait for unary operations, the output must be the same type as the input.
pub trait NormalUaryOps
where
    Self: Sized,
{
    /// The output type of the unary operation.
    type Output;
    /// The output type of the inplace unary operation.
    type InplaceOutput;
    /// The output type of the unary operation.
    type OutputMeta;

    /// Computes the element-wise floor of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.floor()?;
    /// ```
    #[track_caller]
    fn floor(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Floor method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`floor`]: Computes the element-wise floor of the tensor.
    #[track_caller]
    fn floor_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise square of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.square()?;
    /// ```
    #[track_caller]
    fn square(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Square method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`square`]
    #[track_caller]
    fn square_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise absolute value of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.abs()?;
    /// ```
    #[track_caller]
    fn abs(&self) -> std::result::Result<Self::Output, TensorError>;

    /// abs method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`abs`]
    #[track_caller]
    fn abs_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise ceiling of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.ceil()?;
    /// ```
    #[track_caller]
    fn ceil(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Ceil method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`ceil`]
    #[track_caller]
    fn ceil_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise sign of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.sign()?;
    /// ```
    #[track_caller]
    fn sign(&self) -> std::result::Result<Self::Output, TensorError>;

    /// sign method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`sign`]
    #[track_caller]
    fn sign_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Clamps (limits) the values of the tensor between the specified `min` and `max`.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.clamp(0.0, 1.0)?;
    /// ```
    #[track_caller]
    fn clamp(
        &self,
        min: Self::OutputMeta,
        max: Self::OutputMeta,
    ) -> std::result::Result<Self::Output, TensorError>;

    /// clamp method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`clamp`]
    #[track_caller]
    fn clamp_<U>(
        &self,
        min: Self::OutputMeta,
        max: Self::OutputMeta,
        out: U,
    ) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise rounding of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.round()?;
    /// ```
    #[track_caller]
    fn round(&self) -> std::result::Result<Self::Output, TensorError>;

    /// round method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`round`]
    #[track_caller]
    fn round_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise negation (multiplying by -1) of the tensor.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.neg()?;
    /// ```
    #[track_caller]
    fn neg(&self) -> std::result::Result<Self::Output, TensorError>;

    /// Inplace Version of neg.
    ///
    /// # See Also
    ///
    /// - [`neg`]
    #[track_caller]
    fn neg_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Rectified Linear Unit (ReLU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.relu()?;
    /// ```
    #[track_caller]
    fn relu(&self) -> std::result::Result<Self::Output, TensorError>;

    /// relu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`relu`]
    #[track_caller]
    fn relu_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Leaky Rectified Linear Unit (Leaky ReLU) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.leaky_relu(0.01)?;
    /// ```
    #[track_caller]
    fn leaky_relu(&self, alpha: Self::OutputMeta)
        -> std::result::Result<Self::Output, TensorError>;

    /// leaky_relu method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`leaky_relu`]
    #[track_caller]
    fn leaky_relu_<U>(
        &self,
        alpha: Self::OutputMeta,
        out: U,
    ) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;

    /// Computes the element-wise Rectified Linear Unit 6 (ReLU6) activation function.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([10.0]);
    /// let b = a.relu6()?;
    /// ```
    #[track_caller]
    fn relu6(&self) -> std::result::Result<Self::Output, TensorError>;

    /// relu6 method with output tensor, this method will write the result to the output tensor
    /// # See Also
    /// - [`relu6`]
    #[track_caller]
    fn relu6_<U>(&self, out: U) -> std::result::Result<Self::Output, TensorError>
    where
        U: BorrowMut<Self::InplaceOutput>;
}

/// A trait for accumulative operations.
pub trait Cum
where
    Self: Sized,
    <<Self as Cum>::Meta as TypeCommon>::Vec: Send + Sync,
{
    /// The output type of the accumulative operation.
    type Meta: CommonBounds;
    /// The output type of the accumulative operation.
    type Output;
    /// Computes the cumulative sum of the elements in the tensor along a specified axis.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([1.0, 2.0, 3.0]);
    /// let b = a.cumsum(None)?;
    /// ```
    #[track_caller]
    fn cumsum(&self, axis: Option<i64>) -> std::result::Result<Self::Output, TensorError>
    where
        Self::Meta: NormalOut<Self::Meta, Output = Self::Meta>;

    /// Computes the cumulative product of the elements in the tensor along a specified axis.
    ///
    /// # Example
    /// ```rust
    /// let a = Tensor::<f32>::new([1.0, 2.0, 3.0]);
    /// let b = a.cumprod(None)?;
    /// ```
    #[track_caller]
    fn cumprod(&self, axis: Option<i64>) -> std::result::Result<Self::Output, TensorError>
    where
        Self::Meta: NormalOut<Self::Meta, Output = Self::Meta>;
}

/// A trait for contiguous operation
pub trait Contiguous: Sized {
    /// Returns the tensor as a contiguous tensor.
    ///
    /// # Note
    ///
    /// This function will return a contiguous tensor. If the tensor is already contiguous, it will return a clone of the tensor.
    ///
    /// If the tensor is a view tensor, it will return a new tensor with the same data but with a contiguous layout.
    #[track_caller]
    fn contiguous(&self) -> Result<Self, TensorError>;
}