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

package object skeres {
  // Readable renaming of SWIG-generated types.
  type DoublePointerPointer = SWIGTYPE_p_p_double
  type DoublePointer = SWIGTYPE_p_double
  type LossFunctionPointer = SWIGTYPE_p_ceres__LossFunction

  // Implicit conversions betwee pointer objects and
  // arrays or matrices.
  implicit def doublePointerPointerToBlockMatrix(p: DoublePointerPointer) = 
    BlockMatrix(p)

  implicit def doublePointerToRichDoubleArray(p: DoublePointer) = 
    RichDoubleArray(DoubleArray.frompointer(p))

  implicit def doubleArraytoRichDoubleArray(a: DoubleArray) = 
     RichDoubleArray(a)

  // Trivial loss function (we can't use null's directly).
  lazy val NullLossFunction: LossFunctionPointer = new TrivialLossFunction
}

import skeres._

// Enrichment of carrays.i's DoubleArray to
// get more convenient access and conversion
// back to pointer and to scala arrays. 
case class RichDoubleArray(a: DoubleArray) {
  def get(i: Int): Double = a.getitem(i)

  def set(i: Int, x: Double): Unit = a.setitem(i, x)

  def toPointer: DoublePointer = a.cast

  def toArray(length: Int): Array[Double] = {
    val aScala = Array.ofDim[Double](length)
    ArrayHelper.pointerToArray(a.toPointer, length, aScala)
    aScala
  }
}

// Convenient access to matrices represented as
// double**'s.
case class BlockMatrix(data: DoublePointerPointer) {
  def doubleArrayRow(i: Int) = DoubleArray.frompointer {
     BlockMatrixHelper.row(data, i)
  }
  def get(i: Int, j: Int) = doubleArrayRow(i).getitem(j)
  def set(i: Int, j: Int, x: Double) = doubleArrayRow(i).setitem(j, x)  
}
object BlockMatrix {
  @inline def isNull(data: DoublePointerPointer) =
    BlockMatrixHelper.isNull(data)
}

// Extension of LossFunction* that mimics a null pointer. 
class TrivialLossFunction extends LossFunctionPointer<commit_msg>Update skeres.scala<commit_after>package org.somelightprojections.skeres

import com.google.ceres._

package object skeres {
  // Readable renaming of SWIG-generated types.
  type DoublePointerPointer = SWIGTYPE_p_p_double
  type DoublePointer = SWIGTYPE_p_double

  // Implicit conversions betwee pointer objects and
  // arrays or matrices.
  implicit def doublePointerPointerToBlockMatrix(p: DoublePointerPointer) =
    BlockMatrix(p)

  implicit def doublePointerToRichDoubleArray(p: DoublePointer) =
    RichDoubleArray(DoubleArray.frompointer(p))

  implicit def doubleArraytoRichDoubleArray(a: DoubleArray) =
     RichDoubleArray(a)
}

import skeres._

// Enrichment of carrays.i's DoubleArray to
// get more convenient access and conversion
// back to pointer and to scala arrays.
case class RichDoubleArray(a: DoubleArray) {
  def get(i: Int): Double = a.getitem(i)

  def set(i: Int, x: Double): Unit = a.setitem(i, x)

  def toPointer: DoublePointer = a.cast

  // This method is very inefficient. Prefer using the get/set methods above in cost function
  // callbacks.
  // Use of this method is recommended only to return to Scala the result of the optimization.
  def toArray(length: Int): Array[Double] = {
    val aScala = Array.ofDim[Double](length)
    aScala.indices.foreach(i => aScala(i) = a.getitem(i))
    aScala
  }
}

// Convenient access to matrices represented as
// double**'s.
case class BlockMatrix(data: DoublePointerPointer) {
  def doubleArrayRow(i: Int) = DoubleArray.frompointer {
     BlockMatrixHelper.row(data, i)
  }
  def get(i: Int, j: Int) = doubleArrayRow(i).getitem(j)
  def set(i: Int, j: Int, x: Double) = doubleArrayRow(i).setitem(j, x)
}
object BlockMatrix {
  @inline def isNull(data: DoublePointerPointer) =
    BlockMatrixHelper.isNull(data)
}
{'fraction_non_alphanumeric': 0.09424225964149918, 'fraction_numerical': 0.0, 'mean_word_length': 4.408223201174743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4626355', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1148, 'n_words': 326}