<commit_before>package BIDMat

class SparseMat[@specialized(Double,Float) T]
(nr: Int, nc: Int, var nnz0:Int, var ir:Array[Int], val jc:Array[Int], val data:Array[T])
(implicit manifest:Manifest[T], numeric:Numeric[T]) extends Mat(nr, nc) {
  
  override def nnz = nnz0
  
  /*
   * Bounds-checked matrix access
   */	
  def apply(r0:Int, c0:Int):T = {
    val off = Mat.oneBased
    val r = r0 - off
    val c = c0 - off
    if (r < 0 || r >= nrows || c < 0 || c >= ncols) {
      throw new IndexOutOfBoundsException("("+(r+off)+","+(c+off)+") vs ("+nrows+","+ncols+")");
    } else {
      get_(r, c);
    }
  }
  /*
   * Internal (unchecked) accessor
   */
  def get_(r:Int, c:Int):T = {
    val ioff = Mat.ioneBased
    var ix = 0
    if (ir != null) {
    	ix = Mat.ibinsearch(r+ioff, ir, jc(c)-ioff, jc(c+1)-ioff)
    } else {
      ix = r+ioff - jc(c)
    }    
    if (ix >= 0) data(ix) else numeric.zero
  }	
  /*
   * Update a matrix value, m(r,c) = v
   */
  def update(r0:Int, c0:Int, v:T):T = {
  	val off = Mat.oneBased
    val r = r0 - off
    val c = c0 - off
    if (r < 0 || r >= nrows || c < 0 || c >= ncols) {
    	throw new IndexOutOfBoundsException("("+(r+off)+","+(c+off)+") vs ("+nrows+","+ncols+")");
    } else {
      set_(r, c, v);
    }
    v
  }
  /*
   * Internal (unchecked) setter
   */
  def set_(r:Int, c:Int, v:T) = {
    val ioff = Mat.ioneBased
    var ix = 0
    if (ir != null) {
    	ix = Mat.ibinsearch(r+ioff, ir, jc(c)-ioff, jc(c+1)-ioff)<commit_msg>added indexOf to DenseMat<commit_after>package BIDMat

class SparseMat[@specialized(Double,Float) T]
(nr: Int, nc: Int, var nnz0:Int, var ir:Array[Int], val jc:Array[Int], val data:Array[T])
(implicit manifest:Manifest[T], numeric:Numeric[T]) extends Mat(nr, nc) {
  
  override def nnz = nnz0
  
  /*
   * Bounds-checked matrix access
   */	
  def apply(r0:Int, c0:Int):T = {
    val off = Mat.oneBased
    val r = r0 - off
    val c = c0 - off
    if (r < 0 || r >= nrows || c < 0 || c >= ncols) {
      throw new IndexOutOfBoundsException("("+(r+off)+","+(c+off)+") vs ("+nrows+","+ncols+")");
    } else {
      get_(r, c);
    }
  }
  /*
   * Internal (unchecked) accessor
   */
  def get_(r:Int, c:Int):T = {
    val ioff = Mat.ioneBased
    var ix = 0
    if (ir != null) {
    	ix = Mat.ibinsearch(r+ioff, ir, jc(c)-ioff, jc(c+1)-ioff)
    } else {
      ix = r+ioff - jc(c)
    }    
    if (ix >= 0) data(ix) else numeric.zero
  }	
  
  def indexOf2(a:T):(Int, Int) = {
    val off = Mat.oneBased
    val ioff = Mat.ioneBased
    val i = data.indexOf(a)
    var j = 0
    while (jc(j)-ioff <= i) j += 1
    (ir(i) - ioff + off, j-1+off)
  }
  
  def indexOf(a:T):Int = {
  	val off = Mat.oneBased
    val (i,j) = indexOf2(a)
    i + (j-off)*nrows
  }
  /*
   * Update a matrix value, m(r,c) = v
   */
  def update(r0:Int, c0:Int, v:T):T = {
  	val off = Mat.oneBased
    val r = r0 - off
    val c = c0 - off
    if (r < 0 || r >= nrows || c < 0 || c >= ncols) {
    	throw new IndexOutOfBoundsException("("+(r+off)+","+(c+off)+") vs ("+nrows+","+ncols+")");
    } else {
      set_(r, c, v);
    }
    v
  }
  /*
   * Internal (unchecked) setter
   */
  def set_(r:Int, c:Int, v:T) = {
    val ioff = Mat.ioneBased
    var ix = 0
    if (ir != null) {
    	ix = Mat.ibinsearch(r+ioff, ir, jc(c)-ioff, jc(c+1)-ioff)
{'fraction_non_alphanumeric': 0.194335643266044, 'fraction_numerical': 0.012955709551069599, 'mean_word_length': 2.367139959432049, 'pattern_counts': {'":': 0, '<': 12, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3296345', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1425, 'n_words': 340}