Skip to content

Commit e8ff24b

Browse files
committed
Optimize zany-mapping matvec
1 parent 24c6952 commit e8ff24b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

finat/physically_mapped.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,18 @@ def basis_evaluation(self, order, ps, entity=None, coordinate_mapping=None):
270270
M = self.basis_transformation(coordinate_mapping)
271271
# we expect M to be sparse with O(1) nonzeros per row
272272
# for each row, get the column index of each nonzero entry
273-
csr = [[j for j in range(M.shape[1]) if not isinstance(M.array[i, j], gem.Zero)]
273+
csr = [[j for j in range(M.shape[1]) if not isinstance(M[i, j], gem.Zero)]
274274
for i in range(M.shape[0])]
275275

276276
def matvec(table):
277277
# basis recombination using hand-rolled sparse-dense matrix multiplication
278-
table = [gem.partial_indexed(table, (j,)) for j in range(M.shape[1])]
278+
ii = gem.indices(len(table.shape)-1)
279+
phi = [gem.Indexed(table, (j, *ii)) for j in range(M.shape[1])]
279280
# the sum approach is faster than calling numpy.dot or gem.IndexSum
280-
expressions = [sum(M.array[i, j] * table[j] for j in js) for i, js in enumerate(csr)]
281+
expressions = [gem.ComponentTensor(sum(M[i, j] * phi[j] for j in js), ii)
282+
for i, js in enumerate(csr)]
281283
val = gem.ListTensor(expressions)
284+
# val = M @ table
282285
return gem.optimise.aggressive_unroll(val)
283286

284287
result = super().basis_evaluation(order, ps, entity=entity)

gem/gem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ def __new__(cls, aggregate, multiindex):
689689
ll = tuple(rep.get(k, k) for k in kk)
690690
return Indexed(C, ll)
691691

692-
# Simplify Constant and ListTensor
692+
# Simplify Literal and ListTensor
693693
if isinstance(aggregate, (Constant, ListTensor)):
694694
if all(isinstance(i, int) for i in multiindex):
695695
# All indices fixed

0 commit comments

Comments
 (0)