本文整理汇总了Python中sage.tensor.modules.free_module_tensor.FreeModuleTensor.__call__方法的典型用法代码示例。如果您正苦于以下问题:Python FreeModuleTensor.__call__方法的具体用法?Python FreeModuleTensor.__call__怎么用?Python FreeModuleTensor.__call__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.tensor.modules.free_module_tensor.FreeModuleTensor
的用法示例。
在下文中一共展示了FreeModuleTensor.__call__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from sage.tensor.modules.free_module_tensor import FreeModuleTensor [as 别名]
# 或者: from sage.tensor.modules.free_module_tensor.FreeModuleTensor import __call__ [as 别名]
def __call__(self, *arg):
r"""
Redefinition of :meth:`FreeModuleTensor.__call__` to allow for a single
argument (module element).
EXAMPLES:
Call with a single argument: return a module element::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M', start_index=1)
sage: e = M.basis('e')
sage: a = M.automorphism([[-1,0,0],[0,1,2],[0,1,3]], name='a')
sage: v = M([2,1,4], name='v')
sage: s = a.__call__(v) ; s
Element a(v) of the Rank-3 free module M over the Integer Ring
sage: s.display()
a(v) = -2 e_1 + 9 e_2 + 13 e_3
sage: s == a(v)
True
sage: s == a.contract(v)
True
Call with two arguments (:class:`FreeModuleTensor` behaviour): return a
scalar::
sage: b = M.linear_form(name='b')
sage: b[:] = 7, 0, 2
sage: a.__call__(b,v)
12
sage: a(b,v) == a.__call__(b,v)
True
sage: a(b,v) == s(b)
True
Identity map with a single argument: return a module element::
sage: id = M.identity_map()
sage: s = id.__call__(v) ; s
Element v of the Rank-3 free module M over the Integer Ring
sage: s == v
True
sage: s == id(v)
True
sage: s == id.contract(v)
True
Identity map with two arguments (:class:`FreeModuleTensor` behaviour):
return a scalar::
sage: id.__call__(b,v)
22
sage: id(b,v) == id.__call__(b,v)
True
sage: id(b,v) == b(v)
True
"""
from .free_module_tensor import FiniteRankFreeModuleElement
if len(arg) > 1:
# The automorphism acting as a type-(1,1) tensor on a pair
# (linear form, module element), returning a scalar:
if self._is_identity:
if len(arg) != 2:
raise TypeError("wrong number of arguments")
linform = arg[0]
if linform._tensor_type != (0,1):
raise TypeError("the first argument must be a linear form")
vector = arg[1]
if not isinstance(vector, FiniteRankFreeModuleElement):
raise TypeError("the second argument must be a module" +
" element")
return linform(vector)
else: # self is not the identity automorphism:
return FreeModuleTensor.__call__(self, *arg)
# The automorphism acting as such, on a module element, returning a
# module element:
vector = arg[0]
if not isinstance(vector, FiniteRankFreeModuleElement):
raise TypeError("the argument must be an element of a free module")
if self._is_identity:
return vector
basis = self.common_basis(vector)
t = self._components[basis]
v = vector._components[basis]
fmodule = self._fmodule
result = vector._new_instance()
for i in fmodule.irange():
res = 0
for j in fmodule.irange():
res += t[[i,j]]*v[[j]]
result.set_comp(basis)[i] = res
# Name of the output:
result._name = None
if self._name is not None and vector._name is not None:
result._name = self._name + "(" + vector._name + ")"
# LaTeX symbol for the output:
result._latex_name = None
if self._latex_name is not None and vector._latex_name is not None:
result._latex_name = self._latex_name + r"\left(" + \
vector._latex_name + r"\right)"
#.........这里部分代码省略.........