Add a sparse matrix :math:`X` to :py:class:`cspmatrix`.
349821
def _iadd_spmatrix(self, X, alpha = 1.0):
        
        assert self.is_factor is False, "cannot add spmatrix to a cspmatrix factor"

        n = self.symb.n
        snptr = self.symb.snptr
        snode = self.symb.snode
        relptr = self.symb.relptr
        snrowidx = self.symb.snrowidx
        sncolptr = self.symb.sncolptr
        blkptr = self.symb.blkptr
        blkval = self.blkval

        if self.symb.p is not None:
            Xp = tril(perm(symmetrize(X),self.symb.p))
        else:
            Xp = tril(X)
        cp, ri, val = Xp.CCS

        # for each block ...
        for k in range(self.symb.Nsn):
            nn = snptr[k+1]-snptr[k]
            na = relptr[k+1]-relptr[k]
            nj = nn + na

            r = list(snrowidx[sncolptr[k]:sncolptr[k+1]])
            # copy cols from A to block
            for i in range(nn):
                j = snode[snptr[k]+i]
                offset = blkptr[k] + nj*i
                # extract correct indices and add values
                I = [offset + r.index(idx) for idx in ri[cp[j]:cp[j+1]]]

                blkval[I] += alpha*val[cp[j]:cp[j+1]]
        return
801886
def _M2_sparse_sym(Xvar, mask_X, Yvar, mask_Y, weights=None, column_selection=None):
    
    assert len(mask_X) == len(mask_Y), 'X and Y need to have equal sizes for symmetrization'

    if column_selection is None:
        mask_Xk = mask_X
        mask_Yk = mask_Y
        Xvark = Xvar
        Yvark = Yvar
    else:
        mask_Xk = mask_X[column_selection]
        mask_Yk = mask_Y[column_selection]
        Xvark = Xvar[:, _filter_variable_indices(mask_X, column_selection)]
        Yvark = Yvar[:, _filter_variable_indices(mask_Y, column_selection)]

    Cxxyy = np.zeros((len(mask_X), len(mask_Yk)))
    Cxxyy[np.ix_(mask_X, mask_Xk)] = _M2_dense(Xvar, Xvark, weights=weights)
    Cxxyy[np.ix_(mask_Y, mask_Yk)] += _M2_dense(Yvar, Yvark, weights=weights)

    Cxyyx = np.zeros((len(mask_X), len(mask_Yk)))
    Cxy = _M2_dense(Xvar, Yvark, weights=weights)
    Cyx = _M2_dense(Yvar, Xvark, weights=weights)
    Cxyyx[np.ix_(mask_X, mask_Yk)] = Cxy
    Cxyyx[np.ix_(mask_Y, mask_Xk)] += Cyx

    return Cxxyy, Cxyyx
756220
public static FloatMatrix normalizeRows(FloatMatrix x) {
                FloatMatrix temp = new FloatMatrix(x.columns);
		for (int r = 0; r < x.rows; r++)
			x.putRow(r, normalize(x.getRow(r, temp)));
		return x;
	}
1161229
public static SparseMatrix fromMatrixMarket(InputStream is) throws IOException {
        return Matrix.fromMatrixMarket(is).to(Matrices.SPARSE);
    }
1143022
def _init_matrix(self, data, index, columns, dtype=None):
        
        data = prep_ndarray(data, copy=False)
        index, columns = self._prep_index(data, index, columns)
        data = {idx: data[:, i] for i, idx in enumerate(columns)}
        return self._init_dict(data, index, columns, dtype)
441798
def concatenate(self, tpl, axis=None):
        
        if axis is None:
            raise NotImplementedError(
                'Sparse tensor concatenation without axis argument is not supported'
            )
        T = self
        for i in range(1, len(tpl)):
            T = _single_concatenate(T, tpl[i], axis=axis)
        return T
606916
def write_sparse_npz(E, filename, compressed = False):
    ''' '''
    E = E.tocsc()
    scipy.sparse.save_npz(filename, E, compressed = compressed)
480378
def convert_inputs_to_sparse_if_necessary(lhs, rhs):
    '''
    
    '''
    if not sp.issparse(lhs) or not sp.issparse(rhs):
        if sparse_is_desireable(lhs, rhs):
            if not sp.issparse(lhs):
                lhs = sp.csc_matrix(lhs)
                #print "converting lhs into sparse matrix"
            if not sp.issparse(rhs):
                rhs = sp.csc_matrix(rhs)
                #print "converting rhs into sparse matrix"
    return lhs, rhs
188114
def augment_tensor(matrix, ndim=None):
    
    s = matrix.shape
    if ndim is None:
        ndim = s[0]+1
    arr = N.identity(ndim)
    arr[:s[0],:s[1]] = matrix
    return arr
994844
private void addToJacobian(DMatrix tripplet, int col , double a[], double b[], DMatrixRMaj R ) {
		set(tripplet,jacRowX,col+0,a[0]*R.data[0] + a[1]*R.data[3] + a[2]*R.data[6]);
		set(tripplet,jacRowX,col+1,a[0]*R.data[1] + a[1]*R.data[4] + a[2]*R.data[7]);
		set(tripplet,jacRowX,col+2,a[0]*R.data[2] + a[1]*R.data[5] + a[2]*R.data[8]);

		set(tripplet,jacRowY,col+0,b[0]*R.data[0] + b[1]*R.data[3] + b[2]*R.data[6]);
		set(tripplet,jacRowY,col+1,b[0]*R.data[1] + b[1]*R.data[4] + b[2]*R.data[7]);
		set(tripplet,jacRowY,col+2,b[0]*R.data[2] + b[1]*R.data[5] + b[2]*R.data[8]);
	}
1184650
public Matrix add(double c, ExecutorService threadPool)
    {
        Matrix toReturn = getThisSideMatrix(null);
        toReturn.mutableAdd(c, threadPool);
        return toReturn;
    }
1088241
def to_networkx(self, directed=None):
    ''''''
    import networkx as nx
    directed = directed if directed is not None else self.is_directed()
    cls = nx.DiGraph if directed else nx.Graph
    adj = self.matrix()
    if ss.issparse(adj):
      return nx.from_scipy_sparse_matrix(adj, create_using=cls())
    return nx.from_numpy_matrix(adj, create_using=cls())
1238289
def array2d(X, dtype=None, order=None, copy=False):
    """"""
    if sp.issparse(X):
        raise TypeError('A sparse matrix was passed, but dense data '
                        'is required. Use X.toarray() to convert to dense.')
    X_2d = np.asarray(np.atleast_2d(X), dtype=dtype, order=order)
    _assert_all_finite(X_2d)
    if X is X_2d and copy:
        X_2d = safe_copy(X_2d)
    return X_2d
928010
private void fillOsubMatrix( Coordinate[] controlPoints, GeneralMatrix L ) {
        int controlPointsNum = controlPoints.length;
        for( int i = controlPointsNum; i < (controlPointsNum + 3); i++ ) {
            for( int j = controlPointsNum; j < (controlPointsNum + 3); j++ ) {
                L.setElement(i, j, 0);
            }
        }
    }
795936
def set_centralized_sparse(self, A):
        
        if self.myid != 0:
            return

        A = A.tocoo()
        n = A.shape[0]
        assert A.shape == (n, n), "Expected a square matrix."
        self.set_shape(n)
        self.set_centralized_assembled(A.row+1, A.col+1, A.data)
1027917
def _expand_vector(self,x):
        '''
        
        '''
        x = np.atleast_2d(x)
        x_expanded = np.zeros((x.shape[0],self.space.model_dimensionality))
        x_expanded[:,np.array(self.noncontext_index).astype(int)]  = x
        x_expanded[:,np.array(self.context_index).astype(int)]  = self.context_value
        return x_expanded
1188623
def llt(L):
    

    assert isinstance(L, cspmatrix) and L.is_factor is True, "L must be a cspmatrix factor"

    n = L.symb.n
    snpost = L.symb.snpost
    snptr = L.symb.snptr
    chptr = L.symb.chptr
    chidx = L.symb.chidx

    relptr = L.symb.relptr
    relidx = L.symb.relidx
    blkptr = L.symb.blkptr
    blkval = L.blkval

    stack = []

    for k in snpost:

        nn = snptr[k+1]-snptr[k]       # |Nk|
        na = relptr[k+1]-relptr[k]     # |Ak|
        nj = na + nn

        # compute [I; L_{Ak,Nk}]*D_k*[I;L_{Ak,Nk}]'; store in F
        blas.trmm(blkval, blkval, side = "R", m = na, n = nn, ldA = nj,\
                  ldB = nj, offsetA = blkptr[k], offsetB = blkptr[k]+nn)
        F = matrix(0.0, (nj, nj))
        blas.syrk(blkval, F, n = nj, k = nn, offsetA = blkptr[k], ldA = nj)

        # if supernode k has any children, subtract update matrices 
        for _ in range(chptr[k],chptr[k+1]):
            Ui, i = stack.pop()
            frontal_add_update(F, Ui, relidx, relptr, i)

        # if supernode k is not a root node, push update matrix onto stack
        if na > 0:
            Uk = matrix(0.0,(na,na))
            lapack.lacpy(F, Uk, m = na, n = na, uplo = 'L', offsetA = nn*nj+nn, ldA = nj)
            stack.append((Uk,k))

        # copy leading Nk columns of F to blkval
        lapack.lacpy(F, blkval, m = nj, n = nn, ldA = nj, uplo = 'L',\
                     ldB = nj, offsetB = blkptr[k])

    L._is_factor = False

    return