{"record":{"id":"85fc9fb6d6a76aa5","repo":"stanfordnlp/CoreNLP","slug":"float-not-yet-supported-for-qn","errorCode":null,"errorMessage":"Float not yet supported for QN","messagePattern":"Float not yet supported for QN","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":859,"sourceCode":"    }\n    return d;\n  }\n\n  private double doEvaluation(double[] x) {\n    // Evaluate solution\n    if (evaluators == null) return Double.NEGATIVE_INFINITY;\n    double score = 0;\n    for (Evaluator eval:evaluators) {\n      if (!suppressTestPrompt && !quiet)\n        log.info(\"  Evaluating: \" + eval.toString());\n      score = eval.evaluate(x);\n    }\n    return score;\n  }\n\n  public float[] minimize(DiffFloatFunction function, float functionTolerance,\n      float[] initial) {\n    throw new UnsupportedOperationException(\"Float not yet supported for QN\");\n  }\n\n  @Override\n  public double[] minimize(DiffFunction function, double functionTolerance,\n      double[] initial) {\n    return minimize(function, functionTolerance, initial, -1);\n  }\n\n  @Override\n  public double[] minimize(DiffFunction dFunction, double functionTolerance,\n      double[] initial, int maxFunctionEvaluations) {\n    return minimize(dFunction, functionTolerance, initial,\n        maxFunctionEvaluations, null);\n  }\n\n  public double[] minimize(DiffFunction dFunction, double functionTolerance,\n      double[] initial, int maxFunctionEvaluations, QNInfo qn) {\n","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L841-L877","documentation":"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.","triggerScenarios":"Calling QNMinimizer.minimize(DiffFloatFunction, float, float[]) directly, or calling any code path that dispatches minimization to the float overload of a QNMinimizer instance.","commonSituations":"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.","solutions":["Implement the objective as a DiffFunction (double[] based) instead of DiffFloatFunction and call minimize(DiffFunction, double, double[]).","Use a different minimizer that supports floats, or convert the float parameters to double before optimizing and back afterwards.","Remove the DiffFloatFunction overload call site; if float support is required, contribute an implementation instead of relying on the stub."],"exampleFix":"// before\nQNMinimizer minimizer = new QNMinimizer();\nfloat[] result = minimizer.minimize(floatFunction, tol, floatInitial); // throws\n// after\nQNMinimizer minimizer = new QNMinimizer();\ndouble[] result = minimizer.minimize(doubleFunction, (double) tol, toDoubleArray(floatInitial));","handlingStrategy":"type-guard","validationCode":"if (function instanceof DiffFloatFunction && !(function instanceof DiffFunction)) {\n  throw new IllegalStateException(\"QNMinimizer requires a DiffFunction (double[]), not DiffFloatFunction\");\n}","typeGuard":"boolean isSupported = function instanceof DiffFunction; // float[] DiffFloatFunction is NOT supported","tryCatchPattern":"try {\n  result = minimizer.minimize(function, tol, initial);\n} catch (UnsupportedOperationException e) {\n  result = fallbackDoubleMinimizer.minimize(toDiffFunction(function), (double) tol, toDoubleArray(initial));\n}","preventionTips":["Always implement objectives as DiffFunction (double[]) for QNMinimizer.","Check the Minimizer interface docs: float overloads on QNMinimizer are stubs.","Add a unit test that calls minimize with your objective type."],"tags":["optimization","unsupported-operation","float"],"backgroundTag":"unsupported-operation","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"}