daphne-project/daphne

Scalar inputs to `ctable` DaphneDSL built-in function

Aperta

#671 aperta il 27 feb 2024

 (0 commenti) (0 reazioni) (0 assegnatari)C++ (84 fork)auto 404
good first issue

Metriche repository

Star
 (80 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

DaphneDSL's ctable() built-in function takes two column matrices as input (there can be additional parameters, see the docs), e.g., ctable([1, 2, 3], [2, 3, 1]). Not too unfrequently, one of these column matrices contains just the same value, e.g., ctable([1, 2, 3], [1, 1, 1]) or ctable([1, 2, 3], fill(1, 3, 1)). For convenience, it would be great if we could pass just a scalar in such cases, e.g., ctable([1, 2, 3], 1).

Hints:

  • The simplest approach would be, informally speaking, to rewrite a scalar input x to fill(x, h, w) (where h and w are the shape of the other input). This should not be done in the parser, since both the data type (scalar/matrix) of the argument and the shape of the other argument may not be known yet. They may be known only after property inference and constant propagation in the DAPHNE compiler. Thus, a good idea would be to write a canonicalization of the CTableOp that checks if an argument is a scalar and if so, wraps it into a FillOp.
  • At the time of this writing, all existing canonicalization rewrites in DAPHNE reside in src/ir/daphneir/DaphneDialect.cpp, see there for some examples.
  • That simple approach is fine from a user point-of-view, but unnecessarily materializes a potentially large matrix of constant value. Thus, one could optionally adapt the ctable-kernel to accept scalar inputs (see the EwBinaryMat vs. EwBinaryMatSca kernels for some inspiration). However, the convenience for users would currently be more important than this optimization.

Guida contributor