|
Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING
Author |
Message |
Marvin Odo #1 / 4
|
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING
I have these functions that I am trying to write. void fill_zero(int *mat); void read_matrix(int *mat); void add(int *mat1, int *mat2, int *mat3); void multiply(int *mat1, int *mat2, int *mat3); void print(int *mat1, int *mat2, int *mat3); 1.The problem is how do multiply the matrices without using array indexing. How do a read and store the data for two matrices without using array indexing. The matrices to be read are 3x3. My main problem is the array indexing. Any help will be much appreciated. Thank you
|
Sat, 03 Sep 2005 14:05:21 GMT |
|
 |
Thomas Stege #2 / 4
|
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING
Quote:
> I have these functions that I am trying to write. > void fill_zero(int *mat); > void read_matrix(int *mat); > void add(int *mat1, int *mat2, int *mat3); > void multiply(int *mat1, int *mat2, int *mat3); > void print(int *mat1, int *mat2, int *mat3); > 1.The problem is how do multiply the matrices without using array indexing. > How do a read and store the data for two matrices without using array > indexing. > The matrices to be read are 3x3. > My main problem is the array indexing.
Depends what you mean with array indexing. Theoretically speaking, whenever you look something up in a table using an index you are indexing. If you mean without using the index operator [] then you have to use pointer arithmetic. Something like *(mat1 + i + 3 * j) might do the trick. But it is ugly ugly ugly. -- Thomas.
|
Sat, 03 Sep 2005 15:55:19 GMT |
|
 |
CBFalcone #3 / 4
|
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING
Quote:
> I have these functions that I am trying to write. > void fill_zero(int *mat); > void read_matrix(int *mat); > void add(int *mat1, int *mat2, int *mat3); > void multiply(int *mat1, int *mat2, int *mat3); > void print(int *mat1, int *mat2, int *mat3); > 1.The problem is how do multiply the matrices without using array indexing. > How do a read and store the data for two matrices without using array > indexing. > The matrices to be read are 3x3. > My main problem is the array indexing.
Start with a better interface. Somewhere you have defined the storage those matN pointers point to, with say an xdim and a ydim. Pass those values in your function calls. Then the function has the information needed to process the values. ex: void fill_zero(int *mat, size_t xdim, size_t ydim); I wouldn't worry about whether or not you use array indexing. The compiler can probably optimize the code quite nicely by itself, and if it can't you can then worry about it without affecting any other code. --
Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!
|
Sun, 04 Sep 2005 00:44:20 GMT |
|
 |
Kevin Hand #4 / 4
|
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING
Quote:
> I have these functions that I am trying to write. > void fill_zero(int *mat); > void read_matrix(int *mat); > void add(int *mat1, int *mat2, int *mat3); > void multiply(int *mat1, int *mat2, int *mat3); > void print(int *mat1, int *mat2, int *mat3); > 1.The problem is how do multiply the matrices without using array indexing. > How do a read and store the data for two matrices without using array > indexing.
What is wrong with using "array indexing"? Is this just an artificial limitation you made for yourself to make the task harder, or is this some kind a homework assignment? If it is homework, ask the teacher questions. If it is an artificial limitation, then why? The answers to these questions will help us understand more of what/why you are doing this, and will probably lead to a more useful answer. Quote: > The matrices to be read are 3x3. > My main problem is the array indexing. > Any help will be much appreciated. > Thank you
|
Sun, 04 Sep 2005 04:15:34 GMT |
|
|
|