JagsSyntaxModel { public static String writeMatrix(Number[][] m, boolean jags) { int rows = m.length; int cols = m[0].length; String cells[] = new String[rows * cols]; for (int i = 0; i < cells.length; ++i) { cells[i] = writeNumber(jags ? m[i % rows][i / rows] : m[i / cols][i % cols], jags); } return "structure(" + (jags ? "" : ".Data = ") + "c(" + StringUtils.join(cells, ", ") + "), .Dim = c(" + writeNumber(rows, jags) + ", " + writeNumber(cols, jags) + "))"; } JagsSyntaxModel(Network network, Parameterization pmtz, boolean isJags); String initialValuesText(StartingValueGenerator generator); String analysisText(String prefix); CompiledTemplate readTemplate(String path); String modelText(); String scriptText(String prefix, int nchains, int tuning, int simulation); String dataText(); int getMaxArmCount(); Integer[][] getTreatmentMatrix(); Integer[][] getResponderMatrix(); Double[][] getMeanMatrix(); Double[][] getStdErrMatrix(); Integer[][] getSampleSizeMatrix(); Double[][] getDoubleMatrix(StudyTreatmentTransformer<Double> transformer); Integer[][] getIntegerMatrix(StudyTreatmentTransformer<Integer> transformer); void getMatrix(N[][] m, StudyTreatmentTransformer<N> transformer); static String writeNumber(Number x, boolean jags); static String writeMatrix(Number[][] m, boolean jags); static String writeVector(Number[] v, boolean jags); static String writeExpression(Map<NetworkParameter, Integer> pmtz, Transformer<NetworkParameter, String> transform);  }
@Test public void testIntMatrixColMajor() { Integer m[][] = { {1, 2, 3, 4}, {5, 6, 7, 8} }; assertEquals("structure(c(1L, 5L, 2L, 6L, 3L, 7L, 4L, 8L), .Dim = c(2L, 4L))", JagsSyntaxModel.writeMatrix(m, true)); }
@Test public void testIntMatrixRowMajor() { Integer m[][] = { {1, 2, 3, 4}, {5, 6, 7, 8} }; assertEquals("structure(.Data = c(1, 2, 3, 4, 5, 6, 7, 8), .Dim = c(2, 4))", JagsSyntaxModel.writeMatrix(m, false)); }