Package mikera.indexz

Examples of mikera.indexz.Index


  /**
   * Create a clone of this sparse indexed vector including the new indexes specified
   * Intended to allow fast subsequent modification
   */
  public final SparseIndexedVector cloneIncludingIndices(int [] ixs) {
    Index index=internalIndex();
    int[] nixs = IntArrays.mergeSorted(index.data,ixs);
    double[] data=internalData();
    int nl=nixs.length;
    double[] ndata=new double[nl];
    int si=0;
View Full Code Here


   * Copy only the sparse values in this vector to a target array. Other values in the target array are unchanged
   * @param array
   * @param offset
   */
  protected final void copySparseValuesTo(double[] array, int offset) {
    Index index=internalIndex();
    int[] ixs = index.data;
    double[] data=internalData();
    for (int i=0; i<data.length; i++) {
      int di=ixs[i];
      array[offset+di]=data[i];
View Full Code Here

  @Override
  public Vector nonSparseValues() {
    int n=hash.size();
    double[] vs=new double[n];
    Index index=nonSparseIndex();
    for (int i=0; i<n; i++) {
      vs[i]=hash.get(index.get(i));
    }
    return Vector.wrap(vs);
  }
View Full Code Here

    int[] in=new int[n];
    int di=0;
    for (Map.Entry<Integer,Double> e:hash.entrySet()) {
      in[di++]=e.getKey();
    }
    Index result=Index.wrap(in);
    result.sort();
    return result;
  }
View Full Code Here

    return hash.containsKey(i);
  }

  @Override
  public void add(ASparseVector v) {
    Index ind=v.nonSparseIndex();
    int n=ind.length();
    for (int i=0; i<n; i++) {
      int ii=ind.get(i);
      addAt(ii,v.unsafeGet(ii));
    }
  }
View Full Code Here

  // standard implementations
 
  @Override
  public double dotProduct(AVector v) {
    double result=0.0;
    Index ni=nonSparseIndex();
    for (int i=0; i<ni.length(); i++) {
      int ii=ni.get(i);
      result+=unsafeGet(ii)*v.unsafeGet(ii);
    }   
    return result;
  }
View Full Code Here

 
  public boolean equals(ASparseVector v) {
    if (v==this) return true;
    if (v.length!=length) return false;
   
    Index ni=nonSparseIndex();
    for (int i=0; i<ni.length(); i++) {
      int ii=ni.get(i);
      if (unsafeGet(ii)!=v.unsafeGet(ii)) return false;
    }
   
    Index ri=v.nonSparseIndex();
    for (int i=0; i<ri.length(); i++) {
      int ii=ri.get(i);
      if (unsafeGet(ii)!=v.unsafeGet(ii)) return false;
    }
   
    return true;
  }
View Full Code Here

    return super.equals(v);
  }

  @Override
  public boolean hasUncountable() {
    Index ni = nonSparseIndex();
    for(int i=0; i<ni.length(); i++) {
      int ii = ni.get(i);
      if (Double.isNaN(unsafeGet(ii)) || Double.isInfinite(unsafeGet(ii))) {
        return true;
      }
    }
    return false;
View Full Code Here

     * Returns the sum of all the elements raised to a specified power
     * @return
     */
    @Override
    public double elementPowSum(double p) {
        Index ni = nonSparseIndex();
        double result = 0;
        for(int i=0; i<ni.length(); i++) {
            int ii = ni.get(i);
            result += Math.pow(unsafeGet(ii), p);
        }
        return result;
    }
View Full Code Here

     * Returns the sum of the absolute values of all the elements raised to a specified power
     * @return
     */
    @Override
    public double elementAbsPowSum(double p) {
        Index ni = nonSparseIndex();
        double result = 0;
        for(int i=0; i<ni.length(); i++) {
            int ii = ni.get(i);
            result += Math.pow(Math.abs(unsafeGet(ii)), p);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of mikera.indexz.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.