Esempio n. 1
0
 def callback(key):
     table = ctx.tabulation_manager[key]
     if len(table.shape) == 1:
         # Cellwise constant
         row = table
     else:
         table = ctx.index_selector(lambda i: as_gem(table.array[i]),
                                    mt.restriction)
         row = gem.partial_indexed(table, (ctx.point_index,))
     return gem.Indexed(row, (argument_index,))
Esempio n. 2
0
    def callback(key):
        table = ctx.tabulation_manager[key]
        if len(table.shape) == 1:
            # Cellwise constant
            row = table
            if numpy.count_nonzero(table.array) <= 2:
                assert row.shape == vec.shape
                return reduce(gem.Sum,
                              [gem.Product(gem.Indexed(row, (i,)), gem.Indexed(vec, (i,)))
                               for i in range(row.shape[0])],
                              gem.Zero())
        else:
            table = ctx.index_selector(lambda i: as_gem(table.array[i]),
                                       mt.restriction)
            row = gem.partial_indexed(table, (ctx.point_index,))

        r = ctx.index_cache[terminal.ufl_element()]
        return gem.IndexSum(gem.Product(gem.Indexed(row, (r,)),
                                        gem.Indexed(vec, (r,))), r)
Esempio n. 3
0
def test_as_gem():
    with pytest.raises(ValueError):
        gem.as_gem([1, 2])

    assert gem.as_gem(1) == gem.Literal(1)