Java Vector vectorIndexToUpperTriangularIndices(int numberOfRows, int index)

Here you can find the source of vectorIndexToUpperTriangularIndices(int numberOfRows, int index)

Description

vector Index To Upper Triangular Indices

License

Open Source License

Parameter

Parameter Description
numberOfRows The number of rows of the matrix
index The index on the row-major vector

Return

The corresponding row and column indices on the matrix

Declaration

public static int[] vectorIndexToUpperTriangularIndices(int numberOfRows, int index) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from ww  w.j a v  a2 s  .co  m*/
     * @brief Transforms an index to its corresponding upper triangular indices
     *        Let A = {
     *          {11, 12, 13, 14},
     *          {21, 22, 23, 24},
     *          {31, 32, 33, 34},
     *          {41, 42, 43, 44}
     *        }
     *        be an array and b = {12, 13, 14, 23, 24, 34} be the row-major representation of the
     *        upper triangular part of A, excluding the main diagonal. This method will translate
     *        indices on vector b, to indices on matrix A.
     *
     * @param numberOfRows
     *     The number of rows of the matrix
     * @param index
     *     The index on the row-major vector
     *
     * @return The corresponding row and column indices on the matrix
     *
     * @sa upperTriangularIndicesToVectorIndex
     */
    public static int[] vectorIndexToUpperTriangularIndices(int numberOfRows, int index) {
        int rowIndex = 0;
        int columnIndex;

        while (index >= numberOfRows - 1 - rowIndex) {
            index -= numberOfRows - 1 - rowIndex;
            rowIndex++;
        }
        columnIndex = rowIndex + 1 + index;

        return (new int[] { rowIndex, columnIndex });
    }
}

Related

  1. vectorAbsoluteValue(double X, double Y, double Z)
  2. vectorCos(int[] d1, int[] d2)
  3. vectorDiff(final double[] vecOne, final double[] vecTwo)
  4. vectorDir(int vert, int horiz)
  5. vectorDistance(double[] vec1, double[] vec2, double power)
  6. vectorKLDivergence(double v1[], double v2[])
  7. vectorL2Norm(double[] v)
  8. vectorLog10(double v1[])
  9. vectorMagnitude4D(float[][][][] vec4D)