{"record":{"id":"0f521d335d21aa01","repo":"stanfordnlp/CoreNLP","slug":"input-array-with-uneven-columns","errorCode":null,"errorMessage":"Input array with uneven columns","messagePattern":"Input array with uneven columns","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/neural/ConvertModels.java","lineNumber":87,"sourceCode":"    List<List<List<Double>>> out = new ArrayList<>();\n\n    for (int i = 0; i < in.numSlices(); ++i) {\n      out.add(fromMatrix(in.getSlice(i)));\n    }\n\n    return out;\n  }\n\n  public static SimpleMatrix toMatrix(List<List<Double>> in) {\n    if (in.size() == 0) {\n      throw new IllegalArgumentException(\"Input array with 0 rows\");\n    }\n    if (in.get(0).size() == 0) {\n      throw new IllegalArgumentException(\"Input array with 0 columns\");\n    }\n    for (int i = 1; i < in.size(); ++i) {\n      if (in.get(i).size() != in.get(0).size()) {\n        throw new IllegalArgumentException(\"Input array with uneven columns\");\n      }\n    }\n\n    SimpleMatrix out = new SimpleMatrix(in.size(), in.get(0).size());\n    for (int i = 0; i < in.size(); ++i) {\n      List<Double> row = in.get(i);\n      for (int j = 0; j < row.size(); ++j) {\n        out.set(i, j, row.get(j));\n      }\n    }\n\n    return out;\n  }\n\n  public static SimpleTensor toTensor(List<List<List<Double>>> in) {\n    int numSlices = in.size();\n    SimpleMatrix[] slices = new SimpleMatrix[numSlices];\n    for (int i = 0; i < numSlices; ++i) {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/neural/ConvertModels.java#L69-L105","documentation":"ConvertModels.toMatrix validates that every row has the same length as row 0; a ragged List<List<Double>> throws IllegalArgumentException('Input array with uneven columns'). SimpleMatrix requires a dense rectangular shape.","triggerScenarios":"Calling toMatrix where some row i>0 has size != in.get(0).size(), e.g. inconsistent feature counts across word vectors or pair features.","commonSituations":"Hand-edited or partially-written model files, mixing feature sets from different model versions, or a bug in the code assembling rows.","solutions":["Pad or truncate all rows to a uniform length before conversion","Fix the feature-extraction code so every entry yields the same number of features","Validate row lengths in a pre-pass and report the offending row index"],"exampleFix":"// before\nSimpleMatrix m = ConvertModels.toMatrix(rows); // ragged\n// after\nint n = rows.get(0).size();\nfor (int i = 0; i < rows.size(); i++) {\n  if (rows.get(i).size() != n) { throw new IllegalStateException(\"row \" + i + \" has \" + rows.get(i).size() + \" cols, expected \" + n); }\n}\nSimpleMatrix m = ConvertModels.toMatrix(rows);","handlingStrategy":"validation","validationCode":"int expected = rows.get(0).size();\nfor (int i = 0; i < rows.size(); i++) {\n  if (rows.get(i).size() != expected) {\n    throw new IllegalArgumentException(\"row \" + i + \" has \" + rows.get(i).size() + \" columns, expected \" + expected);\n  }\n}","typeGuard":"static boolean isRectangular(java.util.List<java.util.List<Double>> rows) {\n  if (rows == null || rows.isEmpty()) return false;\n  int n = rows.get(0).size();\n  return rows.stream().allMatch(r -> r != null && r.size() == n);\n}","tryCatchPattern":"try {\n  SimpleMatrix m = ConvertModels.toMatrix(rows);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"uneven columns\")) {\n    throw new IllegalStateException(\"ragged feature table; regenerate the model\", e);\n  }\n  throw e;\n}","preventionTips":["Assert rectangularity when building List<List<Double>> tables","Never mix feature sets from different model versions in one table","Pad rows to a uniform length at assembly time if features can be absent"],"tags":["matrix","validation","shape","neural"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}