stanfordnlp/CoreNLP · error · java.lang.UnsupportedOperationException

Float not yet supported for QN

Error message

Float not yet supported for QN

What it means

QNMinimizer only implements quasi-Newton minimization for double-precision functions. The float[] overload of minimize() declared for DiffFloatFunction is a stub and always throws UnsupportedOperationException. It exists only to satisfy the Minimizer interface for floats.

Solutions

  1. Implement the objective as a DiffFunction (double[] based) instead of DiffFloatFunction and call minimize(DiffFunction, double, double[]).
  2. Use a different minimizer that supports floats, or convert the float parameters to double before optimizing and back afterwards.
  3. Remove the DiffFloatFunction overload call site; if float support is required, contribute an implementation instead of relying on the stub.

Example fix

// before
QNMinimizer minimizer = new QNMinimizer();
float[] result = minimizer.minimize(floatFunction, tol, floatInitial); // throws
// after
QNMinimizer minimizer = new QNMinimizer();
double[] result = minimizer.minimize(doubleFunction, (double) tol, toDoubleArray(floatInitial));
Defensive patterns

Strategy: type-guard

Validate before calling

if (function instanceof DiffFloatFunction && !(function instanceof DiffFunction)) {
  throw new IllegalStateException("QNMinimizer requires a DiffFunction (double[]), not DiffFloatFunction");
}

Type guard

boolean isSupported = function instanceof DiffFunction; // float[] DiffFloatFunction is NOT supported

Try / catch

try {
  result = minimizer.minimize(function, tol, initial);
} catch (UnsupportedOperationException e) {
  result = fallbackDoubleMinimizer.minimize(toDiffFunction(function), (double) tol, toDoubleArray(initial));
}

Prevention

When it happens

Trigger: Calling QNMinimizer.minimize(DiffFloatFunction, float, float[]) directly, or calling any code path that dispatches minimization to the float overload of a QNMinimizer instance.

Common situations: Training or optimizing a model whose objective function was implemented against DiffFloatFunction (e.g. 32-bit pipelines in CoreNLP-based code); usually a mismatch between the function type the user implemented and the minimizer chosen.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/85fc9fb6d6a76aa5. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/optimization/QNMinimizer.java:859

    }
    return d;
  }

  private double doEvaluation(double[] x) {
    // Evaluate solution
    if (evaluators == null) return Double.NEGATIVE_INFINITY;
    double score = 0;
    for (Evaluator eval:evaluators) {
      if (!suppressTestPrompt && !quiet)
        log.info("  Evaluating: " + eval.toString());
      score = eval.evaluate(x);
    }
    return score;
  }

  public float[] minimize(DiffFloatFunction function, float functionTolerance,
      float[] initial) {
    throw new UnsupportedOperationException("Float not yet supported for QN");
  }

  @Override
  public double[] minimize(DiffFunction function, double functionTolerance,
      double[] initial) {
    return minimize(function, functionTolerance, initial, -1);
  }

  @Override
  public double[] minimize(DiffFunction dFunction, double functionTolerance,
      double[] initial, int maxFunctionEvaluations) {
    return minimize(dFunction, functionTolerance, initial,
        maxFunctionEvaluations, null);
  }

  public double[] minimize(DiffFunction dFunction, double functionTolerance,
      double[] initial, int maxFunctionEvaluations, QNInfo qn) {

View on GitHub (pinned to 1b7edd19c4)