<commit_before>package scalaxy.reified.test

import org.junit._
import org.junit.Assert._

import scala.reflect.runtime.universe
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe.TypeTag

import scalaxy.reified._
import scalaxy.reified.internal.Optimizer

class ReifiedTest extends TestUtils {

  // Conflicts with value -> function conversion?
  @Test
  def testImplicitValueConversion {
    import scala.language.implicitConversions

    val v = 2
    val r = reify(10 + v)
    val i: Int = r.value
    assertEquals(12, i)
  }

  @Test
  def testImplicitFunctionConversion {
    import scala.language.implicitConversions

    val v = 2
    val r = reify((x: Int) => x + v)

    val f: Int => Int = r.value
    val rf: ReifiedFunction1[Int, Int] = r
    val ff: Int => Int = rf.value

    val rr = r.compose(r)
    val rrf: ReifiedFunction1[Int, Int] = rr

    assertEquals(12, f(10))
  }

  import scalaxy.generic.Generic

  // case class GenericPolynomial[A: Generic: TypeTag](coefficients: A*) {
  //   import scalaxy.generic._
  //   def computeGenericPolynomial(coefficients: List[A]): ReifiedValue[A => A] = coefficients match {
  //     case Nil =>
  //       reify((x: A) => zero[A])
  //     case c :: others =>
  //       val sub = computeGenericPolynomial(others)
  //       reify((x: A) => c + x * sub(x))
  //   }
  //   lazy val function: ReifiedValue[A => A] = computeGenericPolynomial(coefficients.toList)
  // }

  def computeNumericPolynomial[A: Numeric: TypeTag](coefficients: List[A]): ReifiedValue[A => A] = coefficients match {
    case Nil =>
      reify((x: A) => implicitly[Numeric[A]].zero)
    case c :: others =>
      import Numeric.Implicits._
      val sub = computeNumericPolynomial(others)
      reify((x: A) => c + x * sub(x))
  }
  case class NumericPolynomial[A: Numeric: TypeTag](coefficients: A*) {
    lazy val function: ReifiedValue[A => A] = computeNumericPolynomial(coefficients.toList)
  }

  // @Ignore
  // @Test
  // def testGenericPolynomial {
  //   val p = GenericPolynomial[Double](1, 2, 3, 4)
  //   val r = p.function
  //   val f = r.value
  //   val fc = r.compile()()
  //   for (x <- 0 until 10) {
  //     assertEquals(f(x), fc(x))
  //   }
  // }

  @Test
  def testNumericPolynomial {
    val p = NumericPolynomial[Double](1, 2, 3, 4)
    val r = p.function
    val f = r.value
    println("testNumericPolynomial: " + Optimizer.optimize(r.expr()._1.tree))
    val fc = r.compile()()
    for (x <- 0 until 10) {
      assertEquals(f(x), fc(x), 0)
    }
  }

}
<commit_msg>Reified: fix text<commit_after>package scalaxy.reified.test

import org.junit._
import org.junit.Assert._

import scala.reflect.runtime.universe
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe.TypeTag

import scalaxy.reified._
import scalaxy.reified.internal.Optimizer

class ReifiedTest extends TestUtils {

  // Conflicts with value -> function conversion?
  @Test
  def testImplicitValueConversion {
    import scala.language.implicitConversions

    val v = 2
    val r = reify(10 + v)
    val i: Int = r.value
    assertEquals(12, i)
  }

  @Test
  def testImplicitFunctionConversion {
    import scala.language.implicitConversions

    val v = 2
    val r = reify((x: Int) => x + v)

    val f: Int => Int = r.value
    val rf: ReifiedFunction1[Int, Int] = r
    val ff: Int => Int = rf.value

    val rr = r.compose(r)
    val rrf: ReifiedFunction1[Int, Int] = rr

    assertEquals(12, f(10))
  }

  import scalaxy.generic.Generic

  // case class GenericPolynomial[A: Generic: TypeTag](coefficients: A*) {
  //   import scalaxy.generic._
  //   def computeGenericPolynomial(coefficients: List[A]): ReifiedValue[A => A] = coefficients match {
  //     case Nil =>
  //       reify((x: A) => zero[A])
  //     case c :: others =>
  //       val sub = computeGenericPolynomial(others)
  //       reify((x: A) => c + x * sub(x))
  //   }
  //   lazy val function: ReifiedValue[A => A] = computeGenericPolynomial(coefficients.toList)
  // }

  def computeNumericPolynomial[A: Numeric: TypeTag](coefficients: List[A]): ReifiedValue[A => A] = coefficients match {
    case Nil =>
      reify((x: A) => implicitly[Numeric[A]].zero)
    case c :: others =>
      import Numeric.Implicits._
      val sub = computeNumericPolynomial(others)
      reify((x: A) => c + x * sub(x))
  }
  case class NumericPolynomial[A: Numeric: TypeTag](coefficients: A*) {
    lazy val function: ReifiedValue[A => A] = computeNumericPolynomial(coefficients.toList)
  }

  // @Ignore
  // @Test
  // def testGenericPolynomial {
  //   val p = GenericPolynomial[Double](1, 2, 3, 4)
  //   val r = p.function
  //   val f = r.value
  //   val fc = r.compile()()
  //   for (x <- 0 until 10) {
  //     assertEquals(f(x), fc(x))
  //   }
  // }

  @Test
  def testNumericPolynomial {
    val p = NumericPolynomial[Double](1, 2, 3, 4)
    val r = p.function
    val f = r.value
    // println("testNumericPolynomial: " + Optimizer.optimize(r.expr()._1.tree))
    val fc = r.compile()()
    for (x <- 0 until 10) {
      assertEquals(f(x), fc(x), 0)
    }
  }

}

{'fraction_non_alphanumeric': 0.13895926719937635, 'fraction_numerical': 0.010914051841746248, 'mean_word_length': 2.7790868924889542, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '2888198', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1800, 'n_words': 430}