- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A is a 4x4 matrix loaded as a short 2x8 matrix. i want to multiply a constant (identity) matrix C WithA and store results in B. Advice how i can go about it especially thatA isin pointer format. Code below shows my intentions.
tom.cpp file
void tom::multiply(void* btr)
{
short*A =(short*)btr;
int j,i;
short C[4][4]={1,1,1,1,2,1,-1,-2,1,-1,-1,1,1,-2,2,-1};
short B[4][4];
for (i=0; i<4; ++i)
for (j=0; j<4; ++j)
{
B
for (k=0; k<4; ++k)
B
}
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use #defines and #ifdefs to customize the unrolling in the event that C changes.
#define C_00 1
#define C_01 1
...
#define C_33 -1
#if (C_00 == 1)
B[0][0] = A[0][0];
#elif (C_00 == -1)
B[0][0] = -A[0][0];
#else
B[0][0] = A[0][0] * C_00;
#endif
*** Note,
Experiment without the #if using only
B[0][0] = A[0][0] * C_00;
...
as the compiler may optimize out the *1 and *-1
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As for the short * A getting converted to A
Also,can void * pass 2-D array, if it passes, I thought it will pass 1-D array like (1*16), or void * parameter should be changed to something like short * btr[], or btr[][4].
Or, Aindexed in form of something like A[i*4+j]?? is there other method with minimal change of semantics?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Milind,
The original poster had
short* A = (short*)btr;
so I can only assume the btr points to a contiguous array of 16 shorts (1D array)
Had this been
short** A = (short**)btr;
then this would have been an array of pointers to 1D arrays of 4 shorts
This would be inefficient programming but may be what is required
Assuming
short* A = (short*)btr;
The user would have to convert the logical (pseudo code) A
#define foobar(X,i,j) X[i*4+j]
foobar(B,2,3) += foobar(A,3,2) * C_23; // something like this
Change the macro name to something you find suitable.
Jim Dempsey

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