def massmatrix_rowcols(complex, k): """ Compute the row and column arrays in the COO format of the Whitney form mass matrix """ simplices = complex[-1].simplices num_simplices = simplices.shape[0] p = complex.complex_dimension() if k == p: #top dimension rows = arange(num_simplices, dtype=simplices.dtype) cols = arange(num_simplices, dtype=simplices.dtype) return rows, cols k_faces = [tuple(x) for x in combinations(range(p + 1), k + 1)] faces_per_simplex = len(k_faces) num_faces = num_simplices * faces_per_simplex faces = empty((num_faces, k + 1), dtype=simplices.dtype) for n, face in enumerate(k_faces): for m, i in enumerate(face): faces[n::faces_per_simplex, m] = simplices[:, i] #faces.sort() #we can't assume that the p-simplices are sorted indices = simplex_array_searchsorted(complex[k].simplices, faces) rows = tile(indices.reshape((-1, 1)), (faces_per_simplex, )).flatten() cols = tile(indices.reshape((-1, faces_per_simplex)), (faces_per_simplex, )).flatten() return rows, cols
def massmatrix_rowcols(complex,k): """ Compute the row and column arrays in the COO format of the Whitney form mass matrix """ simplices = complex[-1].simplices num_simplices = simplices.shape[0] p = complex.complex_dimension() if k == p: #top dimension rows = arange(num_simplices,dtype=simplices.dtype) cols = arange(num_simplices,dtype=simplices.dtype) return rows,cols k_faces = [tuple(x) for x in combinations(range(p+1),k+1)] faces_per_simplex = len(k_faces) num_faces = num_simplices*faces_per_simplex faces = empty((num_faces,k+1),dtype=simplices.dtype) for n,face in enumerate(k_faces): for m,i in enumerate(face): faces[n::faces_per_simplex,m] = simplices[:,i] #faces.sort() #we can't assume that the p-simplices are sorted indices = simplex_array_searchsorted(complex[k].simplices,faces) rows = tile(indices.reshape((-1,1)),(faces_per_simplex,)).flatten() cols = tile(indices.reshape((-1,faces_per_simplex)),(faces_per_simplex,)).flatten() return rows,cols
def test_simple2(self): s = array([[0,1],[0,2],[1,2],[1,3],[1,4],[3,4]]) v = array([[1,2],[0,2],[3,4]]) result = simplex_array_searchsorted(s,v) expected = array([2,1,5]) assert_equal(result,expected)
def test_simple1(self): s = array([[0],[1],[4],[6],[7],[10]]) v = array([[6],[10],[0]]) result = simplex_array_searchsorted(s,v) expected = array([3,5,0]) assert_equal(result,expected)
def test_random(self): for n_row in [1,2,3,10,100,200]: for n_col in [1,2,3,4,5]: s = arange(n_row*n_col).reshape((n_row,n_col)) for n_searches in [1,2,3,n_row,2*n_row]: expected = random.randint(0,n_row,n_searches) v = s[expected,:] result = simplex_array_searchsorted(s,v) assert_equal(result,expected)