-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathpyIndexNotation.cpp
More file actions
1301 lines (970 loc) · 34.1 KB
/
pyIndexNotation.cpp
File metadata and controls
1301 lines (970 loc) · 34.1 KB
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
#include "pyIndexNotation.h"
#include "pybind11/operators.h"
#include "pybind11/stl.h"
#include "taco/util/intrusive_ptr.h"
#include "taco/index_notation/index_notation.h"
#include "taco/index_notation/index_notation_nodes_abstract.h"
#include "taco/index_notation/index_notation_nodes.h"
PYBIND11_DECLARE_HOLDER_TYPE(T, taco::util::IntrusivePtr<T>, true)
namespace taco{
namespace pythonBindings{
class PyIndexExprNode : public IndexExprNode{
public:
using IndexExprNode::IndexExprNode;
void accept(IndexExprVisitorStrict *visitor) const override {
PYBIND11_OVERLOAD_PURE(
void, /* Return type */
IndexExprNode, /* Parent class */
accept, /* Name of function in C++ (must match Python name) */
visitor /* Argument(s) */
)
}
};
static void defineIndexVar(py::module &m){
py::options options;
options.disable_function_signatures();
py::class_<taco::IndexVar>(m, "index_var", R"(
index_var(name)
Creates an index variable that can be used to access a :class:`pytaco.tensor`.
Makes an index variable with the name, name to access a dimension of a given tensor.
Parameters
-----------
name: str, optional
The name PyTaco assigns to the index_var created. If no name is specified, PyTaco generated its own name for the
index_var.
Attributes
------------
name
Examples
-----------
Index variables must be declared before use. So for example, if we need to make an index expression that adds two
matrices we would write:
>>> import pytaco as pt
>>> i, j = pt.index_var(), pt.index_var()
>>> t1 = pt.tensor([2, 2])
>>> t2 = pt.tensor([2, 2])
>>> t1.insert([1, 1], 100)
>>> add_expr = t1[i, j] + t2[i, j]
This can get cumbersome if we need a large number of :class:`pytaco.index_var` s so PyTaco provides a convenience
function to return a list of :class:`pytaco.index_var` s called :func:`pytaco.get_index_vars`.
This means line 2 above could be replaced by:
>>> i, j = pt.get_index_vars(2)
Notes
-------
Index variables with the same name cannot be used to access different dimensions of the same tensor. This is a feature
that taco currently does not support.
)")
.def(py::init<>())
.def(py::init<const std::string&>())
.def_property_readonly("name", &taco::IndexVar::getName, R"(
Returns the name of the :class:`pytaco.index_var`
)")
.def("__eq__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self == other;
}, py::is_operator())
.def("__ne__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self != other;
}, py::is_operator())
.def("__lt__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self < other;
}, py::is_operator())
.def("__le__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self <= other;
}, py::is_operator())
.def("__ge__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self >= other;
}, py::is_operator())
.def("__gt__", [](const taco::IndexVar& self, const taco::IndexVar& other) -> bool{
return self > other;
}, py::is_operator())
.def("__repr__", [](const taco::IndexVar& indexVar) -> std::string{
std::ostringstream o;
o << "IndexVar(" << indexVar << ")";
return o.str();
}, py::is_operator());
}
template<class T>
static void defineBinaryIndexExpr(py::module &m, const std::string& pyclassName){
py::class_<T, IndexExpr>(m, pyclassName.c_str())
.def(py::init<>())
.def(py::init<IndexExpr, IndexExpr>())
.def("get_a", &T::getA)
.def("get_b", &T::getB)
.def("__repr__", [](const T& expr) -> std::string{
std::ostringstream o;
o << "IndexExpr(" << expr << ")";
return o.str();
}, py::is_operator());
}
template<class T>
static void defineUnaryExpr(py::module &m, const std::string& pyclassName){
py::class_<T, IndexExpr>(m, pyclassName.c_str())
.def(py::init<>())
.def(py::init<IndexExpr>())
.def("get_a", &T::getA)
.def("__repr__", [](const T& expr) -> std::string{
std::ostringstream o;
o << "IndexExpr(" << expr << ")";
return o.str();
}, py::is_operator());
}
static void defineCast(py::module &m){
py::class_<Cast, IndexExpr>(m, "cast_c")
.def(py::init<IndexExpr, Datatype>())
.def("get_a", &Cast::getA)
.def("__repr__", [](const Cast& expr) -> std::string{
std::ostringstream o;
o << "IndexExpr(" << expr << ")";
return o.str();
}, py::is_operator());
}
static std::vector<IndexVar> getIndexVars(int n){
std::vector<IndexVar> vars;
for(int i = 0; i < n; ++i){
vars.emplace_back(IndexVar());
}
return vars;
}
static void defineReduction(py::module &m){
py::class_<Reduction, IndexExpr>(m, "reduction")
.def(py::init<>())
.def(py::init<IndexExpr, IndexVar, IndexExpr>())
.def("get_op", &Reduction::getOp)
.def("get_var", &Reduction::getVar)
.def("get_expr", &Reduction::getExpr)
.def("__repr__", [](const Reduction& expr) -> std::string{
std::ostringstream o;
o << "IndexExpr(" << expr << ")";
return o.str();
}, py::is_operator());
}
template<typename PyClass>
static void addIndexExprOps(PyClass &class_instance){
class_instance
.def("__add__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return self + other;
}, py::is_operator())
.def("__radd__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return other + self;
}, py::is_operator())
.def("__sub__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return self - other;
}, py::is_operator())
.def("__rsub__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return other - self;
}, py::is_operator())
.def("__mul__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return self * other;
}, py::is_operator())
.def("__rmul__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
return other * self;
}, py::is_operator())
.def("__div__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr cast = new CastNode(self, Float64);
return new DivNode(cast, other);
}, py::is_operator())
.def("__rdiv__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr cast = new CastNode(self, Float64);
return new DivNode(other, cast);
}, py::is_operator())
.def("__truediv__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr cast = new CastNode(self, Float64);
return new DivNode(cast, other);
}, py::is_operator())
.def("__rtruediv__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr cast = new CastNode(self, Float64);
return new DivNode(other, cast);
}, py::is_operator())
.def("__floordiv__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr div = new DivNode(self, other);
return new CastNode(div, Int64);
}, py::is_operator())
.def("__rfloordiv__", [](const IndexExpr &self, const IndexExpr &other) -> IndexExpr{
IndexExpr div = new DivNode(other, self);
return new CastNode(div, Int64);
}, py::is_operator())
.def("__pow__", [](const IndexExpr &self, const IndexExpr &other, py::object modulo) -> IndexExpr{
if(!modulo.is_none()){
throw py::value_error("Modulo not currently supported");
}
return pow(self, other);
}, py::is_operator(), py::arg("other"), py::arg() = py::none())
.def("__neg__", [](const IndexExpr &a) -> IndexExpr {
return -a;
}, py::is_operator())
.def("__gt__", >, py::is_operator())
.def("__lt__", <, py::is_operator())
.def("__ge__", >e, py::is_operator())
.def("__le__", <e, py::is_operator())
.def("__eq__", &eq, py::is_operator())
.def("__ne__", &neq, py::is_operator())
.def("__abs__", &abs, py::is_operator());
}
static void defineIndexExpr(py::module &m){
py::options options;
options.disable_function_signatures();
py::class_<IndexExprNode, PyIndexExprNode> pyNode(m, "IndexExprNode");
pyNode
.def(py::init<>())
.def("accept", &IndexExprNode::accept);
auto exprClass = py::class_<IndexExpr>(m, "index_expression", pyNode, R"(
index_expression(num)
Creates an Index Expression.
This direct invocation is only used to convert python ints and floats to index expressions. In all other cases, index
expression will be formed by accessing a tensor using :class:`~pytaco.index_var` s and different operations on that
access as seen in the :ref:`expr_funcs` section.
Note that in general, actually performing computations using index expressions require users to specify an output tensor
with the correct shape. Dimensions indexed by the same :class:`index_var` must have the same shape. As a result,
determining the output shape is easy once the expression has been written. See the examples section.
Parameters
-----------
num: int, float
The scalar value to use to make an index expression.
Attributes
------------
datatype
Examples
---------
>>> import pytaco as pt
>>> pt.index_expression(3)
IndexExpr(3)
Implicit conversion
>>> i, j = pt.get_index_vars(2)
>>> t = pt.tensor([3,3])
>>> t[i,j] = 10 # All values set to 10 since 10 implied to be index expr
Scalar access
>>> s = pt.tensor(100)
>>> scalar_expr = s[None] * t[i,j]
An example of determining the output shape using matrix multiply:
>>> a = pt.tensor([4, 2])
>>> b = pt.tensor([2, 10])
We can represent matrix multiply as ``C[i, j] = A[i, k] * B[k, j]``. Since we have the representation of the computation
and we know that dimensions indexed by the same index variable must have the same shape, we can construct C by letting
its first dimension have size ``A.shape[0]`` since both dimensions are indexed by ``i`` and letting its second dimension
have size B.shape[1] since ``j`` indexes both of those dimensions. This, we would contiue the above as follows:
>>> c = pt.tensor([a.shape[0], b.shape[1]])
Then we could write
>>> i, j, k = pt.get_index_vars(3)
>>> c[i, j] = a[i, k] * b[k, j]
Notes
-----
Construction index expressions in this way can largely be ignored since taco will implicitly convert python scalars to index
expressions.
Creating index expressions from 0 order tensors must be done by indexing the 0 order tensor with ``None``. This tells
taco that there are no dimensions to access.
The :func:`evaluate` function allows users to represent index notation as a string using parenthesis instead of
square brackets and not requiring that scalars be indexed with ``None``. This function can infer the output dimension
of the tensor given the input string but does not currently support all of the index expression functions available.
)")
.def(py::init<int64_t>())
.def(py::init<double>())
.def_property_readonly("datatype", &IndexExpr::getDataType, R"(
Returns the data type this expression will output after computation.
)")
.def("equals", (bool (*) (IndexExpr, IndexExpr)) &equals)
.def("__repr__", [](const IndexExpr &a) -> std::string {
std::ostringstream o;
if(a.defined()){
o << "IndexExpr(" << a << ")";
}else{
o << a;
}
return o.str();
}, py::is_operator());
py::implicitly_convertible<int64_t, IndexExpr>();
py::implicitly_convertible<double, IndexExpr>();
addIndexExprOps(exprClass);
defineBinaryIndexExpr<Add>(m, "add_c");
defineBinaryIndexExpr<Sub>(m, "sub_c");
defineBinaryIndexExpr<Mul>(m, "mul_c");
defineBinaryIndexExpr<Div>(m, "div_c");
defineUnaryExpr<Neg>(m, "neg_c");
defineCast(m);
}
static void defineAccess(py::module &m){
py::class_<Access, IndexExpr>(m, "Access")
.def(py::init<>())
.def(py::init<TensorVar, std::vector<IndexVar>>(), py::arg("tensorVar"), py::arg("indices") = py::list())
.def("tensor_var", &Access::getTensorVar)
.def("index_vars", &Access::getIndexVars);
}
void defineIndexNotation(py::module &m){
py::options options;
options.disable_function_signatures();
m.def("get_index_vars", &getIndexVars, R"(
get_index_vars(vars)
Creates a list of the number of index variables specified.
Parameters
----------
vars: int
The number of index variables to create.
See also
---------
:class:`~pytaco.index_var`
Returns
--------
index_variables: list
A list containing vars :class:`pytaco.index_var` s.
Examples
---------
We can create an arbitrary number of index variables easily as follows:
>>> import pytaco as pt
>>> list_of_vars = pt.get_index_vars(10)
>>> len(list_of_vars)
10
We can also immediately unpack the vars as follows:
>>> i, j, k = pt.get_index_vars(3)
)");
defineIndexVar(m);
defineIndexExpr(m);
defineAccess(m);
defineReduction(m);
m.def("remainder", &mod, R"(
remainder(e1, e2)
Return element wise remainder of division.
The sign of the result is always equivalent to the dividend.
Warnings
--------
This should not be confused with the python modulus operator.
This is equivalent to C's remainder.
Parameters
------------
e1: index_expression
The dividend expression
e2: index_expression
The divisor expression
Returns
---------
An expression representing the element-wise remainder of the input tensors.
Examples
----------
>>> import pytaco as pt
>>> rem = pt.remainder(5, 2)
>>> t = pt.tensor()
>>> t[None] = rem
>>> t[0]
1.0
)");
m.def("abs", &abs, R"(
abs(e1)
Return the element-wise absolute value of the index expression.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Examples
----------
>>> import pytaco as pt
>>> t = pt.as_tensor([-2, 0, 1])
>>> i = pt.index_var()
>>> abs_expr = pt.abs(t[i])
We can then assign this description to a tensor to actually perform the computation
>>> res_t = pt.tensor([3])
>>> res_t[i] = abs_expr
>>> res_t.to_array()
array([2., 0., 1.], dtype=float32)
The above tells taco to compute the absolute value expression and store it in the tensor res_t keeping the dimension
since ``i`` is specified in both the right hand side and the left hand side of the expression.
Returns
---------
abs_exp: index_expression
An index expression representing the element wise absolute value of its inputs.
)");
m.def("square", &square, R"(
square(e1)
Return the element-wise square value of the index expression.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Examples
----------
>>> import pytaco as pt
>>> t = pt.as_tensor([-2, 2, 1])
>>> i = pt.index_var()
>>> sq_expr = pt.square(t[i])
We can then assign this description to a tensor to actually perform the computation.
The code below tells taco to compute the square of each value, sum over all those values and store it in the tensor
res_t. Since ``i`` appears on the right hand side of the expression but not on the left, taco will take the sum of the
values produced.
>>> res_t = pt.tensor()
>>> res_t[None] = sq_expr
>>> res_t.to_array()
array(9., dtype=float32)
Returns
---------
sq_exp: index_expression
An index expression representing the element wise square of the input expression.
)");
m.def("cube", &cube, R"(
cube(e1)
Return the element-wise cube value of the index expression.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Examples
----------
The code below tells taco to compute the cube of each value, sum over all the j indices and store the result in res_t.
Since ``j`` appears on the right hand side of the expression but not on the left, taco will take the sum of the
values over the dimension indexed by j.
>>> import pytaco as pt
>>> t = pt.as_tensor([[-2, 2, 1], [2, 3, 1]])
>>> i, j = pt.get_index_vars(2)
>>> res_t = pt.tensor([t.shape[0]])
>>> res_t[i] = pt.cube(t[i, j])
>>> res_t.to_array()
array([ 1., 36.], dtype=float32)
Returns
---------
cube_exp: index_expression
An index expression representing the element wise cube of the input expression.
)");
m.def("sqrt", &sqrt, R"(
sqrt(e1)
Return the element-wise sqrt of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the square root.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Examples
----------
>>> import pytaco as pt
>>> t = pt.as_tensor([4, 16])
>>> i = pt.index_var()
>>> res_t = pt.tensor([t.shape[0]])
>>> res_t[i] = pt.sqrt(pt.cast(t[i], pt.float32))
>>> res_t.to_array()
array([2., 4.], dtype=float32)
Returns
---------
sqrt_exp: index_expression
An index expression representing the element wise square root of the input expression.
)");
m.def("cube_root", &cbrt, R"(
cube_root(e1)
Return the element-wise cube root of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
cbrt_expr: index_expression
An index expression representing the element wise cube root of the input expression.
)");
m.def("exp", &exp, R"(
exp(e1)
Calculate the exponential of all elements in an index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Examples
---------
We show computing the standard softmax function as an example.
>>> import pytaco as pt
>>> t = pt.as_tensor([[4, 0.3], [2, 7]])
>>> t = pt.as_type(t, pt.float32)
>>> exp_sum = pt.tensor([t.shape[0]], pt.dense)
>>> i, j = pt.get_index_vars(2)
>>> exp_sum[i] = pt.exp(t[i, j]) # sum across the rows and exp
>>> soft_max_t = pt.tensor(t.shape, pt.dense)
>>> soft_max_t[i, j] = pt.exp(t[i, j]) / exp_sum[i] # divide each row by its sum
>>> print(soft_max_t.to_array())
[[0.975873 0.02412702]
[0.00669285 0.9933072 ]]
Returns
---------
exp_expr: index_expression
An index expression representing the element wise exponent of the input expression.
)");
m.def("log", &log, R"(
log(e1)
Return the element-wise logarithm base e of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
log_expr: index_expression
An index expression representing the element wise base e logarithm of the input expression.
)");
m.def("log10", &log10, R"(
log10(e1)
Return the element-wise logarithm base 10 of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
log10_expr: index_expression
An index expression representing the element wise base 10 logarithm of the input expression.
)");
m.def("sin", &sin, R"(
sin(e1)
Return the element-wise sine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
sine_expr: index_expression
An index expression representing the element wise sine of the input expression.
)");
m.def("cos", &cos, R"(
cos(e1)
Return the element-wise cosine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
cosine_expr: index_expression
An index expression representing the element wise cosine of the input expression.
)");
m.def("tan", &tan, R"(
tan(e1)
Return the element-wise tangent of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
tangent_expr: index_expression
An index expression representing the element wise tangent of the input expression.
)");
m.def("asin", &asin, R"(
asin(e1)
Return the element-wise arcsine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
asin_expr: index_expression
An index expression representing the element wise arcsine of the input expression.
)");
m.def("acos", &acos, R"(
acos(e1)
Return the element-wise arccosine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
acos_expr: index_expression
An index expression representing the element wise arccosine of the input expression.
)");
m.def("atan", &atan, R"(
atan(e1)
Return the element-wise arc tangent of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
atan_expr: index_expression
An index expression representing the element wise arc tangent of the input expression.
)");
m.def("atan2", &atan2, R"(
atan2(e1)
Return the element-wise arc tangent of the index expression respecting quadrants.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
atan2_expr: index_expression
An index expression representing the element wise arc tangent of the input expression respecting quadrants.
)");
m.def("sinh", &sinh, R"(
sinh(e1)
Return the element-wise hyperbolic sine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
sinh_expr: index_expression
An index expression representing the element wise hyperbolic sine of the input expression.
)");
m.def("cosh", &cosh, R"(
cosh(e1)
Return the element-wise hyperbolic cosine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
cosh_expr: index_expression
An index expression representing the element wise hyperbolic cosine of the input expression.
)");
m.def("tanh", &tanh, R"(
tanh(e1)
Return the element-wise hyperbolic tangent of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
tanh_expr: index_expression
An index expression representing the element wise hyperbolic tangent of the input expression.
)");
m.def("asinh", &asinh, R"(
asinh(e1)
Return the element-wise hyperbolic arcsine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
asinh_expr: index_expression
An index expression representing the element wise hyperbolic arcsine of the input expression.
)");
m.def("acosh", &acosh, R"(
acosh(e1)
Return the element-wise hyperbolic arccosine of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
acosh_expr: index_expression
An index expression representing the element wise hyperbolic arccosine of the input expression.
)");
m.def("atanh", &atanh, R"(
atanh(e1)
Return the element-wise hyperbolic arc tangent of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
atanh_expr: index_expression
An index expression representing the element wise hyperbolic arc tangent of the input expression.
)");
m.def("logical_not", &Not, R"(
logical_not(e1)
Return the element-wise logical not of the index expression.
The index expression must have a floating point type. If necessary, a user may :func:`cast` the input expression before
applying the function as shown in :func:`sqrt`.
This must be assigned to a tensor for the computation to be performed.
Parameters
-----------
e1: index_expression
Input index expression
Returns
---------
logical_not_expr: index_expression
An index expression representing the element wise logical not of the input expression.
)");
m.def("pow", &pow, R"(
pow(e1, e2)
Computes e1**e2 element-wise.
Parameters
-----------
e1, e2: index_expressions
Input index expressions
Returns
---------