def test_solve_int64_umfpack(self):
        # Solve with UMFPACK: double precision, int64 indices
        a = _to_int64(self.a.astype('d'))

        b = self.b
        x = um.spsolve(a, b)
        assert_allclose(a*x, b)
Beispiel #2
0
    def test_solve_int64_umfpack(self):
        # Solve with UMFPACK: double precision, int64 indices
        a = _to_int64(self.a.astype('d'))

        b = self.b
        x = um.spsolve(a, b)
        assert_allclose(a * x, b)
Beispiel #3
0
def umfpack_linsolve(A, b):
    """

    :param A:
    :param b:
    :return:
    """
    return spsolve(A, b)
Beispiel #4
0
    def _linear_umfpack_solver(A, B):
        """
        Solve Ax = B with UMFPAXK library.

        spsolve needs A to be a square matrix, if not, solve A.T @ A @ x = A.T @ B instead.

        Parameters:
            A (scipy.sparse.csr_matrix): sparse 2d matrix
            B (scipy.sparse.csr_matrix): sparse 2d matrix

        Returns:
            X (scipy.sparse.csr_matrix): X
        """
        if A.shape[0] != A.shape[1]:
            t = A.transpose()
            A = t.dot(A)
            B = t.dot(B)
        return umfpack.spsolve(A, B)
Beispiel #5
0
 def test_solve_sparse_rhs(self):
     # Solve with UMFPACK: double precision, sparse rhs
     a = self.a.astype('d')
     b = csc_matrix(self.b).T
     x = um.spsolve(a, b)
     assert_allclose(a * x, self.b)
Beispiel #6
0
 def test_solve_umfpack(self):
     # Solve with UMFPACK: double precision
     a = self.a.astype('d')
     b = self.b
     x = um.spsolve(a, b)
     assert_allclose(a * x, b)
Beispiel #7
0
 print A.shape
 print "\n"
 xe = numpy.ones(A.shape[1])  #genero xe di soli 1
 print "xe:"
 print xe
 print "\n"
 b = A * xe  #calcolo b
 print "b:"
 print b
 print "\n"
 ####################################################################################################################
 #scikit-umfpack
 A = A.tocsc(
 )  #coo_matrix.tocsc()Return a copy of this matrix in Compressed Sparse Column format -> Questo mi serve per adattare la matrice alla libreria
 start = time.time()  #Start Time
 x = umfpack.spsolve(A, b)
 print "scikit-umfpack {"
 print "\n"
 print "Memory (kiloBytes):"
 print process.memory_info(
 ).rss  # Stampo la memoria utilizzata per il calcolo della soluzione del sistema  -> kiloBytes
 print "\n"
 end = time.time()  #Stop Time
 time = end - start
 error = linalg.norm(x - xe) / linalg.norm(xe)  #calcolo l'errore
 print "Time:"
 print time
 print "\n"
 print "Error:"
 print error
 print "\n"
 def test_solve_sparse_rhs(self):
     # Solve with UMFPACK: double precision, sparse rhs
     a = self.a.astype('d')
     b = csc_matrix(self.b).T
     x = um.spsolve(a, b)
     assert_allclose(a*x, self.b)
 def test_solve_umfpack(self):
     # Solve with UMFPACK: double precision
     a = self.a.astype('d')
     b = self.b
     x = um.spsolve(a, b)
     assert_allclose(a*x, b)
Beispiel #10
0
def fill_depth_colorization(imgRgb=None, imgDepthInput=None, alpha=1):
    imgIsNoise = imgDepthInput == 0
    maxImgAbsDepth = np.max(imgDepthInput)
    imgDepth = imgDepthInput / maxImgAbsDepth
    imgDepth[imgDepth > 1] = 1
    (H, W) = imgDepth.shape
    numPix = H * W
    indsM = np.arange(numPix).reshape((W, H)).transpose()
    knownValMask = (imgIsNoise == False).astype(int)
    grayImg = skimage.color.rgb2gray(imgRgb)
    winRad = 1
    len_ = 0
    absImgNdx = 0
    len_window = (2 * winRad + 1)**2
    len_zeros = numPix * len_window

    cols = np.zeros(len_zeros) - 1
    rows = np.zeros(len_zeros) - 1
    vals = np.zeros(len_zeros) - 1
    gvals = np.zeros(len_window) - 1

    for j in range(W):
        for i in range(H):
            nWin = 0
            for ii in range(max(0, i - winRad), min(i + winRad + 1, H)):
                for jj in range(max(0, j - winRad), min(j + winRad + 1, W)):
                    if ii == i and jj == j:
                        continue

                    rows[len_] = absImgNdx
                    cols[len_] = indsM[ii, jj]
                    gvals[nWin] = grayImg[ii, jj]

                    len_ = len_ + 1
                    nWin = nWin + 1

            curVal = grayImg[i, j]
            gvals[nWin] = curVal
            c_var = np.mean((gvals[:nWin + 1] - np.mean(gvals[:nWin + 1]))**2)

            csig = c_var * 0.6
            mgv = np.min((gvals[:nWin] - curVal)**2)
            if csig < -mgv / np.log(0.01):
                csig = -mgv / np.log(0.01)

            if csig < 2e-06:
                csig = 2e-06

            gvals[:nWin] = np.exp(-(gvals[:nWin] - curVal)**2 / csig)
            gvals[:nWin] = gvals[:nWin] / sum(gvals[:nWin])
            vals[len_ - nWin:len_] = -gvals[:nWin]

            # Now the self-reference (along the diagonal).
            rows[len_] = absImgNdx
            cols[len_] = absImgNdx
            vals[len_] = 1  # sum(gvals(1:nWin))

            len_ = len_ + 1
            absImgNdx = absImgNdx + 1

    vals = vals[:len_]
    cols = cols[:len_]
    rows = rows[:len_]
    A = scipy.sparse.csr_matrix((vals, (rows, cols)), (numPix, numPix))

    rows = np.arange(0, numPix)
    cols = np.arange(0, numPix)
    vals = (knownValMask * alpha).transpose().reshape(numPix)
    G = scipy.sparse.csr_matrix((vals, (rows, cols)), (numPix, numPix))

    A = A + G
    b = np.multiply(vals.reshape(numPix), imgDepth.flatten('F'))

    # print ('Solving system..')

    new_vals = spsolve(A, b)
    new_vals = np.reshape(new_vals, (H, W), 'F')

    # print ('Done.')

    denoisedDepthImg = new_vals * maxImgAbsDepth

    output = denoisedDepthImg.reshape((H, W)).astype('float32')

    output = np.multiply(output, (1 - knownValMask)) + imgDepthInput

    return output