daphne-project/daphne
Scalar inputs to `ctable` DaphneDSL built-in function
Aperta
#671 aperta il 27 feb 2024
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
xtofill(x, h, w)(wherehandware 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 theCTableOpthat checks if an argument is a scalar and if so, wraps it into aFillOp. - 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 theEwBinaryMatvs.EwBinaryMatScakernels for some inspiration). However, the convenience for users would currently be more important than this optimization.