maybe its too late, maybe its something with my brain, but I’cant find
solution to my problem.
If anyone could help me I’ll be very thankful!
Ive got symmetric matrix like below and I need to be able to get to
the right value using two addressing schemes: [row, column] and
like that (both row/column and sequence index provided) :
(drawing in ascii sucks ;)
mat dim is 5 in above example.
inside cells are indices of elements (values stored in matrix doesnt
matter in this context) numeration is zero based.
row0, col0 is index 0
row0, col1 is index 1
row2,col3 is index 10 and so on.
If provided with row and col its easy to find index -
for this matrix of dimension 5 the equation is:
(row*(9-row))/2 + col
so for ex inserting to above equation row = 2, col = 3 give us:
(2*(9-2))/2+3 = 14/2 + 3 = 10 which is right index.
But… i need the oposite and I cannot find formula :( :(
Provided with index I need to find col and row:
like for index 10 the correct answer would be row 2 and col 3.
Why I need that?
I’m provided with symmetric matrices stored in flat array like that:
(for example above, array is of 15 lenght)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
- i have an info on matrix dimension (in that case: 5).
In my program every thread is assigned an index and has to evaluate
col and row.
Each thread only knows about matrix dim and his index, so for ex:
thread x receives index 8 and knows that matdim is 5 - it has to
outputs row = 1 and col =4 (again look at picture above) - thats all!
The trick is it has to be without thread divergence, no ifs and loops (or a least same for every thread) - It
has to be simple formula like the one for row,col into index above but
index -> row, col
Address translation from row,col into index is trivial,
the opposite is like brick wall for me now
(it should be simple since translations in both ways are unique)
Please help - thanks a lot!