[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 22 01:05:57 PDT 2021


fhahn added a comment.

Thank you very much for working on this! Are you planning on implementing the new specification as well? It would probably be good to land the update to the spec in close succession to the implementation, to avoid confusing users.



================
Comment at: clang/docs/MatrixTypes.rst:279
+The number of constituent arrays must equal the number rows in the matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
----------------
SaurabhJha wrote:
> rjmccall wrote:
> > This is contradicted by your first example.  I think you want to say something like
> > 
> > > A value of matrix type `M` can be initialized with an initializer list:
> > >
> > > (examples)
> > >
> > > If the initializer list is empty, all elements of the matrix are zero-initialized.  Otherwise, the initializer list must consist of `M::rows` initializer lists, each of which must consist of `M::columns` expressions, each of which is used to initialize the corresponding element of the matrix (that is, `m[i][j]` is initialized by the `j`th expression of the `i`th initializer list in the initializer).  Element designators are not allowed.
> > 
> > That's assuming you want to allow `{}`, but I think that's probably a good idea.  At the very least, you already have to define how objects of static storage duration are zero-initialized, and having a way to do that explicitly always seems wise to me.
> That sounds great @rjmccall, thanks for your suggestions.
> 
> I think I got confused between whether to allow `{}` but as you suggested, I think we should.
That looks good, thanks! 

Another thing to consider is whether we would like to provide a convenient syntax to initialise all elements with an user-specified value, i.e. should we allow something like `m = {99};`, which would broadcast 99 to all elements of the matrix?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106005/new/

https://reviews.llvm.org/D106005



More information about the cfe-commits mailing list