<commit_before>package breeze.linalg

import operators._
import scala.{specialized=>spec}
import breeze.storage.DenseStorage
import breeze.generic.CanMapValues
import support.{CanSlice, CanCopy}
import breeze.numerics.IntMath
import java.util.Arrays
import breeze.math.{Ring, Field}

/**
 *
 * @author dlwh
 */
final class DenseVector[@spec(Double, Int, Float, Long) E](val data: Array[E],
                                                         val offset: Int,
                                                         val stride: Int,
                                                         val length: Int) extends Vector[E] with DenseStorage[E] with VectorLike[E, DenseVector[E]] {
  def this(data: Array[E]) = this(data, 0, 1, data.length)
  def repr = this

  def apply(i: Int) = {
    if(i < 0 || i > size) throw new IndexOutOfBoundsException(i + " not in [0,"+size+")")
    rawApply(offset + i * stride)
  }

  def update(i: Int, v: E) {
    if(i < 0 || i > size) throw new IndexOutOfBoundsException(i + " not in [0,"+size+")")
    rawUpdate(offset + i * stride, v)
  }

  def activeIterator = iterator

  def activeValuesIterator = valuesIterator

  def activeKeysIterator = keysIterator

  override def equals(p1: Any) = p1 match {
    case x: DenseVector[_] =>
//      length == x.length && (( stride == x.stride
//        && offset == x.offset
//        && data.length == x.data.length
//        && ArrayUtil.equals(data, x.data)
//      )  ||  (
          valuesIterator sameElements x.valuesIterator
//        ))

    case _ => false
  }

  override def toString = {
    valuesIterator.mkString("DenseVector(",", ", ")")
  }
}



object DenseVector extends VectorConstructors[DenseVector]
                      with DenseVectorOps_Int
                      with DenseVectorOps_Float
                      with DenseVectorOps_Double
                      with DenseVectorOps_SparseVector_Double
                      with DenseVectorOps_SparseVector_Float
                      with DenseVectorOps_SparseVector_Int {
  def zeros[@spec(Double, Float, Int) V: ClassManifest](size: Int) = apply(new Array[V](size))
  def apply[@spec(Double, Float, Int) V](values: Array[V]) = new DenseVector(values)

    // concatenation
  /**
   * Horizontal concatenation of two or more row vectors into one matrix.
   * @throws IllegalArgumentException if vectors have different sizes
  def horzcat[V: ClassManifest](vectors: DenseVector[V]*): DenseMatrix[V] = {
    val size = vectors.head.size
    if (!(vectors forall (_.size == size)))
      throw new IllegalArgumentException("All vectors must have the same size!")
    val result = DenseMatrix.zeros[V](vectors.size, size)
    for ((v, col) <- vectors zip (0 until vectors.size))
      result(::, col) := v
    result
  }
   */

  /**
   * Vertical concatenation of two or more column vectors into one large vector.
   */
  def vertcat[V](vectors: DenseVector[V]*)(implicit canSet: BinaryUpdateOp[DenseVector[V], DenseVector[V], OpSet], vman: ClassManifest[V]): DenseVector[V] = {
    val size = vectors.foldLeft(0)(_ + _.size)
    val result = zeros[V](size)
    var offset = 0
    for (v <- vectors) {
      result(offset until (offset + v.size)) := v
      offset += v.size
    }
    result
  }
<commit_msg>DenseVector.ones<commit_after>package breeze.linalg

import operators._
import scala.{specialized=>spec}
import breeze.storage.DenseStorage
import breeze.generic.CanMapValues
import support.{CanSlice, CanCopy}
import breeze.numerics.IntMath
import java.util.Arrays
import breeze.math.{Semiring, Ring, Field}
import breeze.util.ArrayUtil

/**
 *
 * @author dlwh
 */
final class DenseVector[@spec(Double, Int, Float, Long) E](val data: Array[E],
                                                         val offset: Int,
                                                         val stride: Int,
                                                         val length: Int) extends Vector[E] with DenseStorage[E] with VectorLike[E, DenseVector[E]] {
  def this(data: Array[E]) = this(data, 0, 1, data.length)
  def repr = this

  def apply(i: Int) = {
    if(i < 0 || i > size) throw new IndexOutOfBoundsException(i + " not in [0,"+size+")")
    rawApply(offset + i * stride)
  }

  def update(i: Int, v: E) {
    if(i < 0 || i > size) throw new IndexOutOfBoundsException(i + " not in [0,"+size+")")
    rawUpdate(offset + i * stride, v)
  }

  def activeIterator = iterator

  def activeValuesIterator = valuesIterator

  def activeKeysIterator = keysIterator

  override def equals(p1: Any) = p1 match {
    case x: DenseVector[_] =>
//      length == x.length && (( stride == x.stride
//        && offset == x.offset
//        && data.length == x.data.length
//        && ArrayUtil.equals(data, x.data)
//      )  ||  (
          valuesIterator sameElements x.valuesIterator
//        ))

    case _ => false
  }

  override def toString = {
    valuesIterator.mkString("DenseVector(",", ", ")")
  }
}



object DenseVector extends VectorConstructors[DenseVector]
                      with DenseVectorOps_Int
                      with DenseVectorOps_Float
                      with DenseVectorOps_Double
                      with DenseVectorOps_SparseVector_Double
                      with DenseVectorOps_SparseVector_Float
                      with DenseVectorOps_SparseVector_Int {
  def zeros[@spec(Double, Float, Int) V: ClassManifest](size: Int) = apply(new Array[V](size))
  def apply[@spec(Double, Float, Int) V](values: Array[V]) = new DenseVector(values)
  def ones[@spec(Double, Float, Int) V: ClassManifest:Semiring](size: Int) = {
    val r = apply(new Array[V](size))
    assert(r.stride == 1)
    ArrayUtil.fill(r.data, r.offset, r.length, implicitly[Semiring[V]].one)
    r
  }

    // concatenation
  /**
   * Horizontal concatenation of two or more row vectors into one matrix.
   * @throws IllegalArgumentException if vectors have different sizes
  def horzcat[V: ClassManifest](vectors: DenseVector[V]*): DenseMatrix[V] = {
    val size = vectors.head.size
    if (!(vectors forall (_.size == size)))
      throw new IllegalArgumentException("All vectors must have the same size!")
    val result = DenseMatrix.zeros[V](vectors.size, size)
    for ((v, col) <- vectors zip (0 until vectors.size))
      result(::, col) := v
    result
  }
   */

  /**
   * Vertical concatenation of two or more column vectors into one large vector.
   */
  def vertcat[V](vectors: DenseVector[V]*)(implicit canSet: BinaryUpdateOp[DenseVector[V], DenseVector[V], OpSet], vman: ClassManifest[V]): DenseVector[V] = {
    val size = vectors.foldLeft(0)(_ + _.size)
    val result = zeros[V](size)
    var offset = 0
    for (v <- vectors) {
      result(offset until (offset + v.size)) := v
      offset += v.size
    }
    result
  }

{'fraction_non_alphanumeric': 0.12101161593883253, 'fraction_numerical': 0.0033818556094691956, 'mean_word_length': 2.5098039215686274, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2762243', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1996, 'n_words': 545}