Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAPHNE-#358]: DaphneDSL: Matrix literals #387

Merged
merged 3 commits into from
Jun 6, 2022

Conversation

akroviakov
Copy link
Collaborator

Implements Matrix literal for DaphneDSL.

  • A light bool type support for DenseMatrix is added (for print and reshape kernels).
  • Creates a DenseMatrix with shape (nx1) of type int64_t, double or bool inside DaphneDSLVisitor.
  • Usage example: x = [1, 2, 3] or x = [1.1, 2.2, 3.3] or x = [true, false, true].
  • Throws error in case of:
    • You try to create a matrix with mixed types (e.g., x = [1, 2.2, 3]).
    • You try to create an empty matrix: can't infer the type.
    • You use a not yet defined in ValueTypeUtils type (e.g., const char*).

Closes #358 .

@pdamme pdamme self-requested a review June 6, 2022 15:58
- Removed failure test case, because matrix literals with elements of different types shall ultimately work (should define the value type as the most general type).
- Avoiding space in test case tag, since it can be problematic on the console.
- Fixed indentation.
- Some more minor things.
Copy link
Collaborator

@pdamme pdamme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, @akroviakov, it looks very good to me. I've applied just a few minor changes for polishing. Matrix literals are a very useful feature. Having a basic support for them will simplify writing DaphneDSL scripts a lot :) .

I can imagine several follow-up issues relaxing some current constraints, e.g.:

  • Empty matrix literals could just assume double as the value type. The user can always cast that to any other value type like as.si64([]) (which will be zero-cost).
  • Allowing mixed element types by infering the common value type of the matrix via type promotion (see Type promotion in DaphneDSL #364).
  • Allowing complex expressions for the elements of a matrix literal. All elements might become known at compile-time through constant folding, then we could create a MatrixConstantOp in a compiler pass. However, when not all elements are known at compile-time, we could create DaphneIR ops to calculate them at runtime (will look like a matrix literal in DaphneDSL, but be executed differently).

BTW: The initial support for bool as a value type would not have been strictly required, but it doesn't hurt either. I'll leave a comment in the respective issues (#39, #40) ;) .

@pdamme pdamme merged commit 3358fcf into daphne-eu:main Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DaphneDSL: Matrix literals
2 participants