@Test
/**
 * test that v^T M v == vec(M) vec(v v^T)
 */
public void testFlattenSquareMatrixByColumns() {

    double[][] matrixContents = {
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9},
    };
    double[] flattenedMatrixContents = {
            1, 4, 7, 2, 5, 8, 3, 6, 9,
    };
    double[] vectorContents = {
            1, 2, 3,
    };
    RealMatrix matrix = new BlockRealMatrix(matrixContents);
    RealVector vectorizedMatrix = AlgebraUtils.flattenMatrixByColumns(matrix);
    RealVector vector = new ArrayRealVector(vectorContents);
    assertEquals(vectorizedMatrix, new ArrayRealVector(flattenedMatrixContents));
    assertEquals(vector.dotProduct(matrix.operate(vector)), vectorizedMatrix.dotProduct(AlgebraUtils.flattenMatrixByColumns(vector.outerProduct(vector))));
}