Beispiel #1
0
def test_sparse_csc(uniform_sel):
    sparse_csc = gen_sparse_matrix(M, D, np.float32, 0.01).transpose_csc()
    centers = uniform_sel.select(sparse_csc, None, 5)
    assert centers.size() == (5, M), "UniformSel did not output correct size"
    assert centers.is_csc is True, "UniformSel did not preserve sparsity correctly"
    assert centers.dtype == sparse_csc.dtype
    assert centers.device == sparse_csc.device
Beispiel #2
0
def test_sparse_csr(uniform_sel):
    sparse_csr = gen_sparse_matrix(M, D, np.float32, 0.01)
    centers = uniform_sel.select(sparse_csr, None, 100)
    assert centers.size() == (100, D), "UniformSel did not output correct size"
    assert centers.is_csr is True, "UniformSel did not preserve sparsity correctly"
    assert centers.dtype == sparse_csr.dtype
    assert centers.device == sparse_csr.device
Beispiel #3
0
 def s_B(self):
     B = gen_sparse_matrix(m,
                           self.sparse_dim,
                           np.float64,
                           density=self.sparse_density,
                           seed=14)
     Bd = torch.from_numpy(B.to_scipy().todense())
     return B, Bd
Beispiel #4
0
 def s_A(self):
     A = gen_sparse_matrix(n,
                           self.sparse_dim,
                           np.float64,
                           density=self.sparse_density,
                           seed=14)
     Ad = torch.from_numpy(A.to_scipy().todense())
     return A, Ad
Beispiel #5
0
def test_sparse_csc():
    uniform_sel = UniformSelector(np.random.default_rng(0), num_centers=5)
    sparse_csc = gen_sparse_matrix(M, D, np.float32, 0.01).transpose_csc()
    centers: falkon.sparse.SparseTensor = uniform_sel.select(sparse_csc, None)
    assert centers.size() == (5, M), "UniformSel did not output correct size"
    assert centers.is_csc is True, "UniformSel did not preserve sparsity correctly"
    assert centers.dtype == sparse_csc.dtype
    assert centers.device == sparse_csc.device
    centers, idx = uniform_sel.select_indices(sparse_csc, None)
    assert centers.device == idx.device
    assert idx.dtype == torch.long
    assert len(idx) == centers.shape[0]
Beispiel #6
0
def test_sparse_csr(uniform_sel):
    sparse_csr = gen_sparse_matrix(M, D, np.float32, 0.01)
    centers: falkon.sparse.SparseTensor = uniform_sel.select(sparse_csr, None)
    assert centers.size() == (num_centers,
                              D), "UniformSel did not output correct size"
    assert centers.is_csr is True, "UniformSel did not preserve sparsity correctly"
    assert centers.dtype == sparse_csr.dtype
    assert centers.device == sparse_csr.device
    centers, idx = uniform_sel.select_indices(sparse_csr, None)
    assert centers.device == idx.device
    assert idx.dtype == torch.long
    assert len(idx) == centers.shape[0]
Beispiel #7
0
def s_B():
    m, d, density = 550, 20000, 1e-4
    B = gen_sparse_matrix(m, d, np.float64, density=density, seed=14)
    Bd = torch.from_numpy(B.to_scipy().todense())
    return B, Bd
Beispiel #8
0
def s_A():
    n, d, density = 500, 20000, 1e-4
    A = gen_sparse_matrix(n, d, np.float64, density=density, seed=14)
    Ad = torch.from_numpy(A.to_scipy().todense())
    return A, Ad
Beispiel #9
0
def s_A():
    A = gen_sparse_matrix(s_n, s_d, np.float64, density=density, seed=14)
    Ad = torch.from_numpy(A.to_scipy().todense())
    return A, Ad
Beispiel #10
0
def s_B():
    B = gen_sparse_matrix(s_m, s_d, np.float64, density=density, seed=14)
    Bd = torch.from_numpy(B.to_scipy().todense())
    return B, Bd