- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have learned that when you use matmul to multiply two matrices A and B as A*B, there is no restriction on the dimensions of the matrices. I want to admiss only matrices which fulfill the classical matrix multiplication criteria
no. of columns in A = no. of rows in B
If this criteria is violated, I want the compiler to throw a warning. How do I achieve this?
I'm using iFortan 18.0.1.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That is impossible to check at compile time: you can pass two matrices to a general routine and in that routine you multiply the matrices. How would you require the compiler to check that at that point the two matrices have the right sizes? The routine can be compiled independently and it is the call to that routine where the check has to be made.
What you can do alternatively is:
- Create a derived type that holds the matrix
- Define a matmul routine for specifically this derived type
That way you guarantee that only arguments of the mutually right size can be passed. You might try to make this a bit more general via parametrised types, but soon you will lose the strictness you require at compile time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well there are also intrinsic functions RANK, SHAPE and SIZE the can tell you all you need to know about and array if you need to so you could so some checks on the arrays at runtime before calling matmul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The standard places this restriction on the programmer, saying, "The size of the first (or only) dimension of MATRIX_B shall equal the size of the last (or only) dimension of MATRIX_A."; the compiler is not required to have the ability to check this. It might be a nice thing to add in the future under /check:shape, but traditionally the Intel compiler doesn't do that level of additional checking.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page