Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 85823db7 authored by hhakim's avatar hhakim
Browse files

Add pure python prototype for BLOCKDIAG projector.

parent 79d3897f
Branches
No related tags found
No related merge requests found
......@@ -379,4 +379,33 @@ class normlin(proj_gen):
"""
self.constraint = ConstraintReal('normlin', shape[0], shape[1], s, normalized, pos)
class blockdiag: # (proj_gen):
def __init__(self, shape, m_vec, n_vec):
self.m_vec = m_vec
self.n_vec = n_vec
self.shape = shape
if(m_vec[-1] != shape[0]): raise ValueError("The last index of (row"
" offsets) m_vec"
" must be equal to"
" shape[0]")
if(n_vec[-1] != shape[1]): raise ValueError("The last index of (column"
" offsets) n_vec"
" must be equal to"
" shape[1]")
def __call__(self, M):
if(M.shape != self.shape): raise ValueError('The dimension of the '
'projector and matrix must '
'agree.')
M_ = np.zeros(M.shape)
m_ = 0
n_ = 0
for i,(m,n) in enumerate(zip(self.m_vec, self.n_vec)):
print("i=", i, "m=", m, "n=", n)
M_[m_:m,n_:n] = M[m_:m,n_:n]
m_ = m
n_ = n
return M_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment