本文整理汇总了Python中sage.matrix.constructor.Matrix.set_block方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.set_block方法的具体用法?Python Matrix.set_block怎么用?Python Matrix.set_block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.set_block方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HarmonicCocycles
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import set_block [as 别名]
#.........这里部分代码省略.........
::
sage: C = HarmonicCocycles(X,4,prec = 20)
sage: B = C.basis()
sage: len(B) == X.dimension_harmonic_cocycles(4)
True
AUTHORS:
- Cameron Franc (2012-02-20)
- Marc Masdeu (2012-02-20)
"""
try: return self.__matrix
except AttributeError: pass
nV=len(self._V)
nE=len(self._E)
stab_conds=[]
S=self._X.get_edge_stabs()
p=self._X._p
d=self._k-1
for e in self._E:
try:
g=filter(lambda g:g[2],S[e.label])[0]
C=self._U.l_matrix_representation(self.embed_quaternion(g[0]))
C-=self._U.l_matrix_representation(Matrix(QQ,2,2,p**g[1]))
stab_conds.append([e.label,C])
except IndexError: pass
n_stab_conds=len(stab_conds)
self._M=Matrix(self._R,(nV+n_stab_conds)*d,nE*d,0,sparse=True)
for v in self._V:
for e in filter(lambda e:e.parity==0,v.leaving_edges):
C=sum([self._U.l_matrix_representation(self.embed_quaternion(x[0])) for x in e.links],Matrix(self._R,d,d,0))
self._M.set_block(v.label*d,e.label*d,C)
for e in filter(lambda e:e.parity==0,v.entering_edges):
C=sum([self._U.l_matrix_representation(self.embed_quaternion(x[0])) for x in e.opposite.links],Matrix(self._R,d,d,0))
self._M.set_block(v.label*d,e.opposite.label*d,C)
for kk in range(n_stab_conds):
v=stab_conds[kk]
self._M.set_block((nV+kk)*d,v[0]*d,v[1])
x1=self._M.right_kernel().matrix()
if x1.nrows() != self.rank():
raise RuntimeError, 'The computed dimension does not agree with the expectation. Consider increasing precision!'
K=[c for c in x1.rows()]
if not self._R.is_exact():
for ii in range(len(K)):
s=min([t.valuation() for t in K[ii]])
for jj in range(len(K[ii])):
K[ii][jj]=(p**(-s))*K[ii][jj]
self.__matrix=Matrix(self._R,len(K),nE*d,K)
self.__matrix.set_immutable()
return self.__matrix
def __apply_atkin_lehner(self,q,f):
r"""
This function applies an Atkin-Lehner involution to a harmonic cocycle
INPUT:
- ``q`` - an integer dividing the full level p*Nminus*Nplus
示例2: apply_Up
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import set_block [as 别名]
def apply_Up(self,c,group = None,scale = 1,parallelize = False,times = 0,progress_bar = False,method = 'naive', repslocal = None, Up_reps = None, steps = 1):
r"""
Apply the Up Hecke operator operator to ``c``.
"""
assert steps >= 1
V = self.coefficient_module()
R = V.base_ring()
gammas = self.group().gens()
if Up_reps is None:
Up_reps = self.S_arithgroup().get_Up_reps()
if repslocal is None:
try:
prec = V.base_ring().precision_cap()
except AttributeError:
prec = None
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
#.........这里部分代码省略.........