// version 1.0.0 14Feb2018 // Notes: matrices are long vectors with row-major storage // The i,j element of an r x c matrix is // the (i-1)*r + (j-1) element of the of the vector // under zero-base indexing import com.stata.sfi.*; public class MyMatrix { int r, c, TotalSize ; double[] mat ; public MyMatrix(int rows, int cols) { r = rows ; c = cols ; TotalSize = rows*cols ; mat = new double[TotalSize] ; for(int i = 0; i0) { SFIToolkit.errorln("cannot create Stata matrix " + smname) ; return(rc_st) ; } for(i=0; i0) { msg = "{err}cannot access Stata matrix " + smname ; SFIToolkit.errorln(msg) ; return(rc_st) ; } } } return(rc_st) ; } double getValue(int i, int j) { return( mat[i*r+j]) ; } // Store val into (i,j)th element void storeValue(int i, int j, double val) { mat[i*r+j] = val ; } // Increment (i,j)th element by val void incrementByValue(int i, int j, double val) { mat[i*r+j] += val ; } }