<commit_before>package opencl.generator

import apart.arithmetic.Var
import ir._
import ir.ast._
import opencl.executor.{Execute, Executor}
import opencl.ir._
import opencl.ir.pattern._
import org.junit.Assert._
import org.junit.{Ignore, AfterClass, BeforeClass, Test}

object TestTuple {
  @BeforeClass def before() {
    Executor.loadLibrary()
    println("Initialize the executor")
    Executor.init()
  }

  @AfterClass def after() {
    println("Shutdown the executor")
    Executor.shutdown()
  }
}

class TestTuple {
  @Test def VECTOR_NEG_PAIR() {
    val inputSize = 1024
    val inputArray = Array.fill(inputSize * 2)(util.Random.nextInt(5).toFloat)

    val gold = inputArray.map(-_)

    val negPair = UserFun("pair", "x", "{ x._0 = -x._0; x._1 = -x._1; return x; }",
      TupleType(Float, Float), TupleType(Float, Float))

    val f = fun(ArrayType(TupleType(Float, Float), Var("N")), (input) =>
      Join() o MapWrg(
        Join() o  MapLcl(MapSeq(fun(x => negPair(x)))) o Split(4)<commit_msg>Added failing test case (MAKE_TUPLE) to TestTuple<commit_after>package opencl.generator

import apart.arithmetic.Var
import ir._
import ir.ast._
import opencl.executor.{Execute, Executor}
import opencl.ir._
import opencl.ir.pattern._
import org.junit.Assert._
import org.junit.{Ignore, AfterClass, BeforeClass, Test}

object TestTuple {
  @BeforeClass def before() {
    Executor.loadLibrary()
    println("Initialize the executor")
    Executor.init()
  }

  @AfterClass def after() {
    println("Shutdown the executor")
    Executor.shutdown()
  }
}

class TestTuple {

   @Test def  MAKE_TUPLE() {
    val inputSize = 1024
    val inArrA = Array.fill(inputSize)(util.Random.nextInt(5).toFloat)
    val inArrB = Array.fill(inputSize)(util.Random.nextInt(5).toFloat)
    val gold = inArrA.zip(inArrB).map{case (a,b) => Array(a, b)}.flatten

    val N = Var("N")
    val f = fun(
      ArrayType(Float, N),
      ArrayType(Float, N),
      (a,b) => {
        toGlobal(MapGlb(idFF)) $ Zip(a, b)
      }
    )

    val (output: Array[Float], runtime) = Execute(inputSize)(f, inArrA, inArrB)
    
    assertArrayEquals(gold, output, 0.0f)
    println("output(0) = " + output(0))
    println("runtime = " + runtime)
  }
  
  @Test def VECTOR_NEG_PAIR() {
    val inputSize = 1024
    val inputArray = Array.fill(inputSize * 2)(util.Random.nextInt(5).toFloat)

    val gold = inputArray.map(-_)

    val negPair = UserFun("pair", "x", "{ x._0 = -x._0; x._1 = -x._1; return x; }",
      TupleType(Float, Float), TupleType(Float, Float))

    val f = fun(ArrayType(TupleType(Float, Float), Var("N")), (input) =>
      Join() o MapWrg(
        Join() o  MapLcl(MapSeq(fun(x => negPair(x)))) o Split(4)
{'fraction_non_alphanumeric': 0.14977810650887574, 'fraction_numerical': 0.011834319526627219, 'mean_word_length': 3.4710743801652892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1678166', 'n_tokens_mistral': 992, 'n_tokens_neox': 947, 'n_words': 217}