@Override public <T extends Matrix> T createLike() { return (T)new DMatrixSparseTriplet(numRows,numCols, nz_length); }
@Override public <T extends Matrix> T copy() { return (T)new DMatrixSparseTriplet(this); }
private DMatrixSparseTriplet readDSTR(int numRows, int numCols, int length) throws IOException { List<String> words; DMatrixSparseTriplet m = new DMatrixSparseTriplet(numRows,numCols,length); for (int i = 0; i < length; i++) { words = extractWords(); if( words.size() != 3 ) throw new IllegalArgumentException("Unexpected number of words on line "+getLineNumber()); int row = Integer.parseInt(words.get(0)); int col = Integer.parseInt(words.get(1)); double value = Double.parseDouble(words.get(2)); m.addItem(row,col,value); } return m; } }
public static DMatrixSparseTriplet convert(DMatrixRMaj src , DMatrixSparseTriplet dst , double tol ) { if( dst == null ) dst = new DMatrixSparseTriplet(src.numRows, src.numCols,src.numRows*src.numCols); else dst.reshape(src.numRows, src.numCols); int index = 0; for (int row = 0; row < src.numRows; row++) { for (int col = 0; col < src.numCols; col++) { double value = src.data[index++]; if( Math.abs(value) > tol ) dst.addItem(row,col,value); } } return dst; }
public static DMatrixSparseTriplet convert(DMatrixSparseCSC src , DMatrixSparseTriplet dst ) { if( dst == null ) dst = new DMatrixSparseTriplet(src.numRows, src.numCols, src.nz_length); else dst.reshape( src.numRows , src.numCols ); int i0 = src.col_idx[0]; for (int col = 0; col < src.numCols; col++) { int i1 = src.col_idx[col+1]; for (int i = i0; i < i1; i++) { int row = src.nz_rows[i]; dst.addItem(row,col, src.nz_values[i]); } i0 = i1; } return dst; } }
@Override public void process(double[] input, DMatrixSparseCSC jacobian) { jacobian.reshape(M,N,N); function.process(input,output0); // Use a triplet initially because it is less expensive to grow DMatrixSparseTriplet tmp = new DMatrixSparseTriplet(M,N,N); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; function.process(input,output1); for( int j = 0; j < M; j++ ) { double value = (output1[j] - output0[j])/h; if( Math.abs(value) > zeroTolerance ) tmp.set(j,i,value); } input[i] = x; } ConvertDMatrixStruct.convert(tmp,jacobian); }
@Override public void process(double[] input, DMatrixSparseCSC jacobian) { jacobian.reshape(M,N,N); function.process(input,output0); // Use a triplet initially because it is less expensive to grow DMatrixSparseTriplet tmp = new DMatrixSparseTriplet(M,N,N); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; function.process(input,output1); for( int j = 0; j < M; j++ ) { double value = (output1[j] - output0[j])/h; if( Math.abs(value) > zeroTolerance ) tmp.set(j,i,value); } input[i] = x; } ConvertDMatrixStruct.convert(tmp,jacobian); }
public static DMatrixSparseTriplet convert(DMatrix src , DMatrixSparseTriplet dst , double tol ) { if( dst == null ) dst = new DMatrixSparseTriplet(src.getNumRows(), src.getNumCols(), 1); else dst.reshape(src.getNumRows(), src.getNumCols()); for (int row = 0; row < src.getNumRows(); row++) { for (int col = 0; col < src.getNumCols(); col++) { double value = src.unsafe_get(row,col); if( Math.abs(value) > tol ) dst.addItem(row,col,value); } } return dst; }
DMatrixSparseTriplet tripletLeft = new DMatrixSparseTriplet(N,2*numCameras,1); DMatrixSparseTriplet tripletRight = new DMatrixSparseTriplet(N,2*numLandmarks,1);