{"record":{"id":"5c492352a77d0325","repo":"stanfordnlp/CoreNLP","slug":"input-arrays-must-have-equal-length","errorCode":null,"errorMessage":"Input arrays must have equal length!","messagePattern":"Input arrays must have equal length!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/math/ArrayMath.java","lineNumber":1727,"sourceCode":"   * significant, that is, the significance level.  This is computed by\n   * \"approximate randomization\".  The test statistic is the absolute\n   * difference between the means of the two arrays.  A randomized test\n   * statistic is computed the same way after initially randomizing the\n   * arrays by swapping each pair of elements with 50% probability.  For\n   * the given number of iterations, we generate a randomized test\n   * statistic and compare it to the actual test statistic.  The return\n   * value is the proportion of iterations in which a randomized test\n   * statistic was found to exceed the actual test statistic.\n   *\n   * @param A Outcome of one r.v.\n   * @param B Outcome of another r.v.\n   * @return Significance level by randomization\n   */\n  public static double sigLevelByApproxRand(double[] A, double[] B, int iterations) {\n    if (A.length == 0)\n      throw new IllegalArgumentException(\"Input arrays must not be empty!\");\n    if (A.length != B.length)\n      throw new IllegalArgumentException(\"Input arrays must have equal length!\");\n    if (iterations <= 0)\n      throw new IllegalArgumentException(\"Number of iterations must be positive!\");\n    double testStatistic = absDiffOfMeans(A, B, false); // not randomized\n    int successes = 0;\n    for (int i = 0; i < iterations; i++) {\n      double t =  absDiffOfMeans(A, B, true); // randomized\n      if (t >= testStatistic) successes++;\n    }\n    return (double) (successes + 1) / (double) (iterations + 1);\n  }\n\n  public static double sigLevelByApproxRand(int[] A, int[] B) {\n    return sigLevelByApproxRand(A, B, 1000);\n  }\n\n  public static double sigLevelByApproxRand(int[] A, int[] B, int iterations) {\n    if (A.length == 0)\n      throw new IllegalArgumentException(\"Input arrays must not be empty!\");","sourceCodeStart":1709,"sourceCodeEnd":1745,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/math/ArrayMath.java#L1709-L1745","documentation":"sigLevelByApproxRand pairs outcomes of two random variables element-wise, so A and B must have the same length. When A.length != B.length the pairing is impossible and an IllegalArgumentException(\"Input arrays must have equal length!\") is thrown before any computation.","triggerScenarios":"Calling sigLevelByApproxRand(double[] A, double[] B, int iterations) where A and B were collected over different instance sets — e.g. one system skipped or dropped instances, or metrics were filtered asymmetrically.","commonSituations":"Comparing two NLP system outputs where one pipeline produced fewer scores (failed parses, missing files), or mixing per-sentence and per-document metric arrays.","solutions":["Ensure both arrays are built over the exact same instances; align/filter them together before the call.","Verify the upstream evaluation loop emits one score per instance per system (check for silently skipped instances).","Add an assertion/log of A.length == B.length in the evaluation harness before running significance tests.","Catch IllegalArgumentException and flag the comparison as invalid rather than proceeding."],"exampleFix":"// before\ndouble p = ArrayMath.sigLevelByApproxRand(scoresA, scoresB, 1000);\n// after\nif (scoresA.length != scoresB.length) {\n  throw new IllegalStateException(\"misaligned evaluation arrays: \" + scoresA.length + \" vs \" + scoresB.length);\n}\ndouble p = ArrayMath.sigLevelByApproxRand(scoresA, scoresB, 1000);","handlingStrategy":"validation","validationCode":"if (a.length != b.length) {\n  throw new IllegalStateException(\"misaligned samples: \" + a.length + \" vs \" + b.length);\n}","typeGuard":null,"tryCatchPattern":"try {\n  p = ArrayMath.sigLevelByApproxRand(a, b, iterations);\n} catch (IllegalArgumentException e) {\n  // report misaligned evaluation arrays\n}","preventionTips":["Build paired outcome arrays in one loop so lengths match by construction","Check for silently skipped instances in per-system evaluation runs","Align instances by ID before collecting metric arrays","Log array lengths in evaluation reports for quick diagnosis"],"tags":["statistics","array-length","argument-validation","hypothesis-testing"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}