<commit_before>package org.somelightprojections.skeres
import ceres._
import skeres._

// Concrete cost functor: cost(x) = 10.0 - x
class CostFunctor extends CostFunction {
  mutableParameterBlockSizes.add(1)
  setNumResiduals(1)

  override def evaluate(
    parameters: DoublePointerPointer,
    residuals: DoublePointer,
    jacobians: DoublePointerPointer
  ): Boolean = {
    val x = parameters.get(0, 0)
    residuals.set(0, 10.0 - x)
    if (!BlockMatrix.isNull(jacobians)) {
      jacobians.set(0, 0, -1.0)
    }
    true
  }
}

object HelloWorld {
  // Load the swig-wrapped C++ DLL.
  System.loadLibrary("skeres");

  val numRuns = 1

  def main(args: Array[String]): Unit = {
    ceres.initGoogleLogging("HelloWorld")
    (1 to numRuns).foreach {_ => 
      val x = solve
    }
  }

  def solve: Vector[Double] = {
    val initialX = 0.5
    val x = new DoubleArray(1)
    x.set(0, initialX)

    val problemOptions = new Problem.Options
    // Can't let native ceres code take ownership (and try to delete) Scala
    // objects.
    problemOptions.setCostFunctionOwnership(Ownership.DO_NOT_TAKE_OWNERSHIP)
    problemOptions.setLossFunctionOwnership(Ownership.DO_NOT_TAKE_OWNERSHIP)

    val problem = new Problem(problemOptions)

    val cost = new CostFunctor
    problem.addResidualBlock(cost, NullLossFunction, x.toPointer)

    val solverOptions = new Solver.Options
    solverOptions.setMinimizerProgressToStdout(true)

    val summary = new Solver.Summary

    ceres.solve(solverOptions, problem, summary)

    println(summary.briefReport)
    println(s"x : $initialX -> ${x.get(0)}")
    x.toArray(1).toVector
  }
}<commit_msg>Update HelloWorld.scala<commit_after>package org.somelightprojections.skeres

import com.google.ceres._
import skeres._

// Concrete cost functor: cost(x) = 10.0 - x
class CostFunctor extends CostFunction {
  mutableParameterBlockSizes.add(1)
  setNumResiduals(1)

  override def evaluate(
    parameters: DoublePointerPointer,
    residuals: DoublePointer,
    jacobians: DoublePointerPointer
  ): Boolean = {
    val x = parameters.get(0, 0)
    residuals.set(0, 10.0 - x)
    if (!BlockMatrix.isNull(jacobians)) {
      jacobians.set(0, 0, -1.0)
    }
    true
  }
}

object HelloWorld {
  val numRuns = 1

  def main(args: Array[String]): Unit = {
    ceres.initGoogleLogging("HelloWorld")
    val initialX = 0.5
    (1 to numRuns).foreach {_ =>
      val x = solve(initialX)
      println(s"x : $initialX -> ${x(0)}")
    }
  }

  def solve(initialX: Double): Vector[Double] = {
    val x = new DoubleArray(1)
    x.set(0, initialX)

    val problemOptions = new Problem.Options
    problemOptions.setCostFunctionOwnership(Ownership.DO_NOT_TAKE_OWNERSHIP)
    problemOptions.setLossFunctionOwnership(Ownership.DO_NOT_TAKE_OWNERSHIP)

    val problem = new Problem(problemOptions)

    val cost = new CostFunctor
    val loss = PredefinedLossFunctions.trivialLoss
    problem.addResidualBlock(cost, loss, x.toPointer)

    val solverOptions = new Solver.Options
    solverOptions.setMinimizerProgressToStdout(true)

    val summary = new Solver.Summary

    ceres.solve(solverOptions, problem, summary)

    println(summary.briefReport)
    x.toArray(1).toVector
  }
}
{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.014290152221186705, 'mean_word_length': 3.5034965034965033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '258511', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1074, 'n_words': 230}