@@ -3827,3 +3827,44 @@ def eye(n, m = None, dtype = None):
38273827 dtype = tf .dtypes .float32
38283828 return tf .eye (n , m , dtype = dtype )
38293829
3830+
3831+ def einsum (equation , * operands ):
3832+ """
3833+ Sums the product of the elements of the input operands along dimensions specified
3834+ using a notation based on the Einstein summation convention.
3835+
3836+ Parameters
3837+ ----------
3838+ equation : An attribute
3839+ represent the operation you want to do.
3840+ the value can contain only letters([a-z][A-Z]), commas(,), ellipsis(…), and arrow(->).
3841+ the letters represent inputs’s tensor dimension, commas(,)represent separate tensors, ellipsis(…) indicates
3842+ the tensor dimension that you do not care about, the left of the arrow(->) indicates the input tensors,
3843+ and the right of it indicates the desired output dimension.
3844+
3845+ operands : list
3846+ input tensor used for calculation. the data type of the tensor must be the same.
3847+
3848+ Returns
3849+ -------
3850+ Tensor, the shape of it can be obtained from the equation, and the data type is the same as input tensors.
3851+
3852+ Examples
3853+ ---------
3854+ >>> import tensorlayerx as tlx
3855+ >>> x = tlx.nn.Input((5,))
3856+ >>> y = tlx.nn.Input((4,))
3857+ >>> out = tlx.ops.einsum('i,j->ij', x, y)
3858+ >>> cal_enisum = tlx.ops.Einsum('i,j->ij')
3859+ >>> out = cal_enisum(x, y)
3860+ """
3861+ return tf .einsum (equation , * operands )
3862+
3863+
3864+ class Einsum (object ):
3865+ def __init__ (self , equation ):
3866+ super (Einsum , self ).__init__ ()
3867+ self .equation = equation
3868+
3869+ def __call__ (self , * args ):
3870+ return tf .einsum (self .equation , * args )
0 commit comments