本文整理汇总了Python中sage.matrix.constructor.Matrix.apply_map方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.apply_map方法的具体用法?Python Matrix.apply_map怎么用?Python Matrix.apply_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.apply_map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OCVnElement
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import apply_map [as 别名]
#.........这里部分代码省略.........
A=Matrix(self._parent._R,self._parent.dimension(),self._parent.dimension(),[[b._val[ii,0] for b in B] for ii in range(self._depth)])
tmp=A.solve_right(self._val)
return tmp
def _add_(self,y):
r"""
Add two elements.
"""
val=self._val+y._val
return self.__class__(self._parent,val, check = False)
def _sub_(self,y):
r"""
Subtract two elements.
"""
val=self._val-y._val
return self.__class__(self._parent,val, check = False)
def r_act_by(self,x):
r"""
Act on the right by a matrix.
"""
#assert(x.nrows()==2 and x.ncols()==2) #An element of GL2
return self._acted_upon_(x.adjoint(), False)
def _acted_upon_(self,x, right_action): # Act by x on the left
try:
x = x.matrix()
except AttributeError: pass
if right_action:
return self._acted_upon_(x.adjoint(), False)
else:
R = self._parent._R
A = self._parent._get_powers(x)
tmp = A * self._val
return self.__class__(self._parent, tmp, check = False)
def _neg_(self):
return self.__class__(self._parent,-self._val, check = False)
def _rmul_(self,a):
#assume that a is a scalar
return self.__class__(self._parent,a*self._val, check = False)
def _repr_(self):
r"""
Returns the representation of self as a string.
"""
R = PowerSeriesRing(self._parent._R,default_prec=self._depth,name='z')
z = R.gen()
s = str(sum([R(self._val[ii,0]*z**ii) for ii in range(self._depth)]))
return s
def __cmp__(self,other):
return cmp(self._val,other._val)
def __nonzero__(self):
return self._val!=0
def evaluate_at_poly(self,P,R = None,depth = None):
r"""
Evaluate ``self`` at a polynomial
"""
p = self._parent._p
if R is None:
try:
R = pushout(P.parent().base_ring(),self.parent().base_ring())
except AttributeError:
R = self.parent().base_ring()
if depth is None and hasattr(P,'degree'):
try:
depth = min([P.degree()+1,self._depth])
return sum(R(self._val[ii,0])*P[ii] for ii in xrange(depth))
except NotImplementedError: pass
return R(self._val[0,0])*P
else:
return sum(R(self._val[ii,0])*P[ii] for ii in xrange(depth))
def valuation(self,l=None):
r"""
The `l`-adic valuation of ``self``.
INPUT: a prime `l`. The default (None) uses the prime of the parent.
"""
if not self._parent.base_ring().is_exact():
if(not l is None and l!=self._parent._Rmod.prime()):
raise ValueError, "This function can only be called with the base prime"
l = self._parent._Rmod.prime()
return min([self._val[ii,0].valuation(l) for ii in range(self._depth)])
else:
return min([self._val[ii,0].valuation(l) for ii in range(self._depth)])
def reduce_mod(self, N = None):
if N is None:
N = self.parent()._pN
self._val = self._val.apply_map(lambda x: x % N)
return self
示例2: apply_Up
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import apply_map [as 别名]
#.........这里部分代码省略.........
repslocal = self.get_Up_reps_local(prec)
i = 0
if method == 'naive':
assert times == 0
G = self.S_arithgroup()
Gn = G.large_group()
if self.use_shapiro():
if self.coefficient_module().trivial_action():
def calculate_Up_contribution(lst, c, i, j):
return sum([c.evaluate_and_identity(tt) for sk, tt in lst])
else:
def calculate_Up_contribution(lst, c, i, j):
return sum([sk * c.evaluate_and_identity(tt) for sk, tt in lst])
input_vec = []
for j, gamma in enumerate(gammas):
for i, xi in enumerate(G.coset_reps()):
delta = Gn(G.get_coset_ti(set_immutable(xi * gamma.quaternion_rep))[0])
input_vec.append(([(sk, Gn.get_hecke_ti(g,delta)) for sk, g in zip(repslocal, Up_reps)], c, i, j))
vals = [[V.coefficient_module()(0,normalize=False) for xi in G.coset_reps()] for gamma in gammas]
if parallelize:
for inp, outp in parallel(calculate_Up_contribution)(input_vec):
vals[inp[0][-1]][inp[0][-2]] += outp
else:
for inp in input_vec:
outp = calculate_Up_contribution(*inp)
vals[inp[-1]][inp[-2]] += outp
ans = self([V(o) for o in vals])
else:
Gpn = G.small_group()
if self.trivial_action():
def calculate_Up_contribution(lst,c,num_gamma):
return sum([c.evaluate(tt) for sk, tt in lst], V(0,normalize=False))
else:
def calculate_Up_contribution(lst,c,num_gamma,pb_fraction=None):
i = 0
ans = V(0, normalize=False)
for sk, tt in lst:
ans += sk * c.evaluate(tt)
update_progress(i * pb_fraction, 'Up action')
return ans
input_vec = []
for j,gamma in enumerate(gammas):
input_vec.append(([(sk, Gpn.get_hecke_ti(g,gamma)) for sk, g in zip(repslocal, Up_reps)], c, j))
vals = [V(0,normalize=False) for gamma in gammas]
if parallelize:
for inp,outp in parallel(calculate_Up_contribution)(input_vec):
vals[inp[0][-1]] += outp
else:
for counter, inp in enumerate(input_vec):
outp = calculate_Up_contribution(*inp, pb_fraction=float(1)/float(len(repslocal) * len(input_vec)))
vals[inp[-1]] += outp
ans = self(vals)
if scale != 1:
ans = scale * ans
else:
assert method == 'bigmatrix'
verbose('Getting Up matrices...')
try:
N = len(V(0)._moments.list())
except AttributeError:
N = 1
nreps = len(Up_reps)
ngens = len(self.group().gens())
NN = ngens * N
A = Matrix(ZZ,NN,NN,0)
total_counter = ngens**2
counter = 0
iS = 0
for i,gi in enumerate(self.group().gens()):
ti = [tuple(self.group().get_hecke_ti(sk,gi).word_rep) for sk in Up_reps]
jS = 0
for ans in find_newans(self,repslocal,ti):
A.set_block(iS,jS,ans)
jS += N
if progress_bar:
counter +=1
update_progress(float(counter)/float(total_counter),'Up matrix')
iS += N
verbose('Computing 2^(%s)-th power of a %s x %s matrix'%(times,A.nrows(),A.ncols()))
for i in range(times):
A = A**2
if N != 0:
A = A.apply_map(lambda x: x % self._pN)
update_progress(float(i+1)/float(times),'Exponentiating matrix')
verbose('Done computing 2^(%s)-th power'%times)
if times > 0:
scale_factor = ZZ(scale).powermod(2**times,self._pN)
else:
scale_factor = ZZ(scale)
bvec = Matrix(R,NN,1,[o for b in c._val for o in b._moments.list()])
if scale_factor != 1:
bvec = scale_factor * bvec
valmat = A * bvec
appr_module = V.approx_module(N)
ans = self([V(appr_module(valmat.submatrix(row=i,nrows = N).list())) for i in xrange(0,valmat.nrows(),N)])
if steps <= 1:
return ans
else:
return self.apply_Up(ans, group = group,scale = scale,parallelize = parallelize,times = times,progress_bar = progress_bar,method = method, repslocal = repslocal, steps = steps -1)