<commit_before>package baseCode.dataStructure.matrix;

import cern.colt.function.DoubleFunction;
import cern.colt.list.DoubleArrayList;
import cern.colt.list.IntArrayList;
import cern.colt.matrix.DoubleMatrix1D;
import cern.colt.matrix.DoubleMatrix2D;
import cern.colt.matrix.impl.RCDoubleMatrix2D;

/**
 * A row-compressed 1D matrix. The only deviation from the contract of DoubleMatrix1D is in apply(), which only operates
 * on the non-empty elements. This implementation has a highly optimized dot product computer. If you need to compute
 * the dot product of a RCDoubleMatrix1D with another DoubleMatrix1D, call zDotProduct on this, not on the other. This
 * is because getQuick() and setQuick() are not very fast for this.
 * <hr>
 * <p>
 * Copyright (c) 2004 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class RCDoubleMatrix1D extends DoubleMatrix1D {

   protected IntArrayList indexes;
   protected DoubleArrayList values;

   /**
    * 
    * @param values
    */
   public RCDoubleMatrix1D( double[] values ) {
      this( values.length );
      assign( values );
   }


   /**
    * 
    * @param length
    */
   public RCDoubleMatrix1D( int length ) {
      setUp( length );
      this.indexes = new IntArrayList( length );
      this.values = new DoubleArrayList( length );
   }

   /**
    * @param indexes These MUST be in sorted order.
    * @param values These MuST be in the same order as the indexes, meaning that indexes[0] is the column for values[0].
    */
   public RCDoubleMatrix1D( IntArrayList indexes, DoubleArrayList values ) {
      int s = indexes.get(indexes.size() - 1) + 1;
      setUp( s  );
      this.indexes = indexes;
      this.values = values;
   }

   /*
    * (non-Javadoc)
    * 
    * @see cern.colt.matrix.DoubleMatrix1D#getQuick(int)
    */
   public double getQuick( int index ) {

      int location = indexes.binarySearch( index );

      if ( location >= 0 ) {
         return values.get( location );
      }
      return 0.0;
   }

   /*
    * (non-Javadoc)
    * 
    * @see cern.colt.matrix.DoubleMatrix1D#like(int)
    */
   public DoubleMatrix1D like( int s ) {
      return new RCDoubleMatrix1D( s );
   }

   /*<commit_msg>protected against zero-size rows.<commit_after>package baseCode.dataStructure.matrix;

import cern.colt.function.DoubleFunction;
import cern.colt.list.DoubleArrayList;
import cern.colt.list.IntArrayList;
import cern.colt.matrix.DoubleMatrix1D;
import cern.colt.matrix.DoubleMatrix2D;
import cern.colt.matrix.impl.RCDoubleMatrix2D;

/**
 * A row-compressed 1D matrix. The only deviation from the contract of DoubleMatrix1D is in apply(), which only operates
 * on the non-empty elements. This implementation has a highly optimized dot product computer. If you need to compute
 * the dot product of a RCDoubleMatrix1D with another DoubleMatrix1D, call zDotProduct on this, not on the other. This
 * is because getQuick() and setQuick() are not very fast for this.
 * <hr>
 * <p>
 * Copyright (c) 2004 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class RCDoubleMatrix1D extends DoubleMatrix1D {

   protected IntArrayList indexes;
   protected DoubleArrayList values;

   /**
    * 
    * @param values
    */
   public RCDoubleMatrix1D( double[] values ) {
      this( values.length );
      assign( values );
   }


   /**
    * 
    * @param length
    */
   public RCDoubleMatrix1D( int length ) {
      setUp( length );
      this.indexes = new IntArrayList( length );
      this.values = new DoubleArrayList( length );
   }

   /**
    * @param indexes These MUST be in sorted order.
    * @param values These MuST be in the same order as the indexes, meaning that indexes[0] is the column for values[0].
    */
   public RCDoubleMatrix1D( IntArrayList indexes, DoubleArrayList values ) {
      int k = indexes.size();
      int s = 0;
      if ( k > 0 ) {
         s = indexes.get( k - 1 ) + 1;
      }
      
      setUp( s  );
      this.indexes = indexes;
      this.values = values;
   }

   /*
    * (non-Javadoc)
    * 
    * @see cern.colt.matrix.DoubleMatrix1D#getQuick(int)
    */
   public double getQuick( int index ) {

      int location = indexes.binarySearch( index );

      if ( location >= 0 ) {
         return values.get( location );
      }
      return 0.0;
   }

   /*
    * (non-Javadoc)
    * 
    * @see cern.colt.matrix.DoubleMatrix1D#like(int)
    */
   public DoubleMatrix1D like( int s ) {
      return new RCDoubleMatrix1D( s );
   }

   /*
{'fraction_non_alphanumeric': 0.1021493463328163, 'fraction_numerical': 0.012408597385331266, 'mean_word_length': 2.696969696969697, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, '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': '4623517', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1384, 'n_words': 420}