symmetr.tensors module
Defines a symbolic tensor class.
All the tensors that are symmetrized use this class.
- class symmetr.tensors.GenericTensor(dim1, dim2, ind_types=None)[source]
Bases:
objectThis class cannot be directly used by itself. Classed that inherit from this class must define __getitem__, __setitem__ and copy0.
- __dict__ = mappingproxy({'__module__': 'symmetr.tensors', '__firstlineno__': 234, '__doc__': '\nThis class cannot be directly used by itself.\nClassed that inherit from this class must define __getitem__, __setitem__\nand copy0.\n', '__init__': <function GenericTensor.__init__>, '__len__': <function GenericTensor.__len__>, '__add__': <function GenericTensor.__add__>, '__sub__': <function GenericTensor.__sub__>, '__mul__': <function GenericTensor.__mul__>, '__div__': <function GenericTensor.__div__>, '__radd__': <function GenericTensor.__radd__>, '__rsub__': <function GenericTensor.__rsub__>, '__rmul__': <function GenericTensor.__rmul__>, '__neg__': <function GenericTensor.__neg__>, '__iter__': <function GenericTensor.__iter__>, 'reduce': <function GenericTensor.reduce>, 'convert': <function GenericTensor.convert>, 'def_trans': <function GenericTensor.def_trans>, 'use_numpy_mode': <function GenericTensor.use_numpy_mode>, 'transform': <function GenericTensor.transform>, 'is_even': <function GenericTensor.is_even>, 'def_metric': <function GenericTensor.def_metric>, 'reverse_index': <function GenericTensor.reverse_index>, 'raise_index': <function GenericTensor.raise_index>, 'lower_index': <function GenericTensor.lower_index>, 'is_contravar': <function GenericTensor.is_contravar>, 'is_covar': <function GenericTensor.is_covar>, '__static_attributes__': ('G', 'Gi', 'P_trans', 'T_comp', 'T_trans', 'dim1', 'dim2', 'ind_trans', 'ind_types', 'inds', 'permute_inds', 'trans_type'), '__dict__': <attribute '__dict__' of 'GenericTensor' objects>, '__weakref__': <attribute '__weakref__' of 'GenericTensor' objects>, '__annotations__': {}})
- __firstlineno__ = 234
- __init__(dim1, dim2, ind_types=None)[source]
Creates a symbolic tensor.
- Parameters:
dim1 (int) – How many values can each index have.
dim2 (int) – How many indeces are there in the tensor.
ind_types (optinal[tuple]) – Specifies whether individual indeces are covariant or contravariant. 1 specifies contravariant and -1 covariant. If not specified all the indeces are assumed contravariant.
- __module__ = 'symmetr.tensors'
- __static_attributes__ = ('G', 'Gi', 'P_trans', 'T_comp', 'T_trans', 'dim1', 'dim2', 'ind_trans', 'ind_types', 'inds', 'permute_inds', 'trans_type')
- convert(T, in_place=True)[source]
Return the tensor transormed by coordinate transformation matrix T.
- Parameters:
T (matrix) – Coordinate transformation matrix. T transforms from A to B, ie Tx_A = x_B.
- Returns:
the transformed tensor
- Return type:
ten_T (tensor)
- class symmetr.tensors.NumTensor(kind, dim1, dim2, name='x', ind_types=None)[source]
Bases:
GenericTensor- __annotations__ = {}
- __firstlineno__ = 1013
- __hash__ = None
- __init__(kind, dim1, dim2, name='x', ind_types=None)[source]
Creates a symbolic tensor represented by a matrix.
This is only possible for linear tensors, that is tensors such that every element is a linear combination of symbolic variables
- Parameters:
kind – Sets what kind of tensor. ‘s’ for symbolic, 0 for zero tensor
dim1 (int) – How many values can each index have.
dim2 (int) – How many indeces are there in the tensor.
name (optional[str]) – Name of the symbolic variables. Defaults to ‘x’.
ind_types (optinal[tuple]) – Specifies whether individual indeces are covariant or contravariant. 1 specifies contravariant and -1 covariant. If not specified all the indeces are assumed contravariant.
- __module__ = 'symmetr.tensors'
- __static_attributes__ = ('G', 'Gi', 'name', 't')
- class symmetr.tensors.Tensor(kind, dim1, dim2, name='x', ind_types=None)[source]
Bases:
GenericTensorCreates a symbolic tensor.
- Usage:
- Use by t=tensor(‘s’,dim1,dim2), where ‘s’ means the tensor should be symbolic, dim2 is the number of indeces
of the tensor, dim1 is the number of values each index can have.
By default variables will be called x### for a different variable name, Run with tensor(‘s’,dim1,dim2,’name’). For nonsymbolic zero tensor, run tensor(0,dim1,dim2). Print by print t Write out element of the tensor by t[1,2,3] or t[(1,2,3)] for example Assign a value to element: t[1,2,3] = 0. Sum or substract two tensors: t1+t2. Multiply by a number or symbolic variable: t*2. Loop over all elements, following will print all elements for example. Note that the loop is over indeces, not elements!
- for i in t:
print t[i]
- If you need to use the symbolic variables use t.x[index], for example for x011, use t.x[0,1,1] (or t.x[(0,1,1)]).
You can do for example t[0,0,0] = t.x[1,1,1], then t[0,0,0] will be equal to x111. You can also access x011 by t[‘x011’].
- __annotations__ = {}
- __firstlineno__ = 540
- __hash__ = None
- __init__(kind, dim1, dim2, name='x', ind_types=None)[source]
Creates a symbolic tensor.
- Parameters:
kind – Sets what kind of tensor. ‘s’ for symbolic, 0 for zero tensor
dim1 (int) – How many values can each index have.
dim2 (int) – How many indeces are there in the tensor.
name (optional[str]) – Name of the symbolic variables. Defaults to ‘x’.
ind_types (optinal[tuple]) – Specifies whether individual indeces are covariant or contravariant. 1 specifies contravariant and -1 covariant. If not specified all the indeces are assumed contravariant.
- __module__ = 'symmetr.tensors'
- __static_attributes__ = ('name', 't', 'v', 'x')
- static load(inp)[source]
Loads the Tensor from either a dictionary or a file. :param inp: can be either the filename or the dictionary
- pprint(print_format=None, latex=False, no_newline=False, ind_types=False, remove_zeros=False, ret=False)[source]
- class symmetr.tensors.matrix(kind, dim1, name='x')[source]
Bases:
Tensor- __annotations__ = {}
- __firstlineno__ = 1252
- __init__(kind, dim1, name='x')[source]
Creates a symbolic tensor.
- Parameters:
kind – Sets what kind of tensor. ‘s’ for symbolic, 0 for zero tensor
dim1 (int) – How many values can each index have.
dim2 (int) – How many indeces are there in the tensor.
name (optional[str]) – Name of the symbolic variables. Defaults to ‘x’.
ind_types (optinal[tuple]) – Specifies whether individual indeces are covariant or contravariant. 1 specifies contravariant and -1 covariant. If not specified all the indeces are assumed contravariant.
- __module__ = 'symmetr.tensors'
- __static_attributes__ = ()