package edu.emory.mathcs.csparsej.tdouble;
import edu.emory.mathcs.csparsej.tdouble.Dcs_common.Dcs;
public class Dcs_CSToTriplet {
public static Dcs cs_CSToTriplet(Dcs A) {
int p, j, m, n, nzmax, nz, Ap[], Ai[];
double Ax[];
if (A == null) {
System.out.print("(null)\n");
return null;
}
m = A.m; // number of rows
n = A.n; // number of columns
Ap = A.p; // column pointers (size n+1) or col indices (size nzmax)
Ai = A.i; // row indices, size nzmax
Ax = A.x; // numerical values, size nzmax
nzmax = A.nzmax;
nz = A.nz;
if (nz > 0) {
System.out.println("Matrix not in compressed column form");
return null;
}
// allocate a triplet matrix
Dcs tripletDcs = Dcs_util.cs_spalloc(m, n, nzmax, false, true);
for (j = 0; j < n; j++) { // for all columns
for (int row = Ap[j]; row < Ap[j + 1]; row++) {
// triplet is: row, j, Ax[row]
double value = Ax[row];
System.out.println("row = "+row+", col = "+j+", value = "+value);
Dcs_entry.cs_entry(tripletDcs, row, j, value);
}
}
return tripletDcs;
}
}