Java Matrix Transpose transpose(int[][][] as, int A, int[][][] ast)

Here you can find the source of transpose(int[][][] as, int A, int[][][] ast)

Description

create transpose of sparse matrix

License

Common Public License

Parameter

Parameter Description
as a parameter

Declaration


public static void transpose(int[][][] as, int A, int[][][] ast) 

Method Source Code

//package com.java2s;
//License from project: Common Public License 

import java.util.HashMap;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**/*w  w  w .  j  a v a  2s.  c  o m*/
     * create transpose of sparse matrix
     * 
     * @param as
     * @param [out] ast transpose
     */

    public static void transpose(int[][][] as, int A, int[][][] ast) {
        int M = as[0].length;
        Map<Integer, Integer>[] x = new Map[A];
        for (int m = 0; m < M; m++) {
            for (int n = 0; n < as[0][m].length; n++) {
                int ii = as[0][m][n];
                if (x[ii] == null) {
                    x[ii] = new HashMap<Integer, Integer>();
                }
                x[ii].put(m, as[1][m][n]);
            }
        }
        map2sparse(x, ast);
    }

    /**
     * create a sparse array from the map
     * 
     * @param x
     * @param [out] xs
     */
    public static void map2sparse(Map<Integer, Integer>[] x, int[][][] xs) {
        // now fill the sparse array
        for (int i = 0; i < x.length; i++) {
            if (x[i] != null) {
                xs[0][i] = new int[x[i].size()];
                xs[1][i] = new int[x[i].size()];
                int j = 0;
                for (Entry<Integer, Integer> e : x[i].entrySet()) {
                    xs[0][i][j] = e.getKey();
                    xs[1][i][j] = e.getValue();
                    j++;
                }
            } else {
                xs[0][i] = new int[0];
            }
        }
    }
}

Related

  1. transpose(float[][] data)
  2. transpose(int N, double src[][])
  3. transpose(int[][] input)
  4. transpose(int[][] M)
  5. transpose(int[][] matrix)
  6. transpose(long[] a, double offset)
  7. transpose(Object[][] matrix)
  8. transpose(Object[][] matrix)
  9. transpose2d(Object[][] array)