I am working on a computer program (in CUDA C++) that solves issues related to triangular matrices. I can not find a way to correctly index the triangular matrix entries.
Let's assume I have a $N$x$N$ lower triangular matrix.
The maximum number of nonzero entries in such a matrix is $Q = N ( N + 1 ) / 2$.
The program generates a set $W = \{ 0, 1, 2, 3, ..., Q - 1 \}$ to work with.
My responsibility is to map set $W$ into a set of pairs { matrix row, matrix column }
I have those two expressions:
$n = \frac {i}{N}$
$m = i - n * N$
where:
- $i \in W$
- $n$ is a row index, $n \in N^0$
- $m$ is a column index. $m \in N^0$
(I know that $m$ should be equal to $0$ but we are working with natural numbers. In this case, it works as a "round down to the nearest whole number" function.)
let's assume $N = 4$
Those two expressions generate a set of pairs $\{ n, m\}$ from the set $W$:
$$ \begin{matrix} \{0,0\} & \{0,1\} & \{2,0\} & -\\ \{1,0\} & \{1,1\} & \{2,1\} & -\\ \{2,0\} & \{2,1\} & - & -\\ \{3,0\} & \{3,1\} & - & -\\ \end{matrix} $$
(Shown as a matrix to help visualize the issue.)
As you can see this is not a triangular matrix.
Question:
Is there a way to generate a set of pairs $\{ n, m\}$ from the set $W$, which would look like this (for $N = 4$):
$$ \begin{matrix} \{0,0\} & - & - & - \\ \{1,0\} & \{1,1\} & - & - \\ \{2,0\} & \{2,1\} & \{2,2\} & - \\ \{3,0\} & \{3,1\} & \{3,2\} & \{3,3\} \\ \end{matrix} $$