package mikera.vectorz.impl;
import java.util.Arrays;
import mikera.vectorz.AVector;
import mikera.vectorz.Op;
import mikera.vectorz.util.IntArrays;
import mikera.vectorz.util.VectorzException;
/**
* Vector that addresses elements indexed into double[] array.
*
* Useful for sub-selections views of array data
*
* @author Mike
*/
public final class IndexedArrayVector extends BaseIndexedVector {
private static final long serialVersionUID = 3220750778637547658L;
private final double[] data;
private IndexedArrayVector(double[] source, int[] indexes) {
super(indexes);
this.data=source;
}
/**
* Wraps the specified indexes into a double[] array as an IndexedArrayVector
*
* The length of the vector will equal the number of indices provided.
*
* @param data
* @param indexes
* @return
*/
public static IndexedArrayVector wrap(double[] data, int[] indexes) {
return new IndexedArrayVector(data,indexes);
}
@Override
public final double get(int i) {
return data[indexes[i]];
}
@Override
public final double unsafeGet(int i) {
return data[indexes[i]];
}
@Override
public IndexedArrayVector selectView(int... inds) {
int[] ci=IntArrays.select(indexes,inds);
return replaceIndex(ci);
}
@Override
public final void set(int i, double value) {
data[indexes[i]]=value;
}
@Override
public final void unsafeSet(int i, double value) {
data[indexes[i]]=value;
}
@Override
public void addAt(int i, double value) {
data[indexes[i]]+=value;
}
@Override
public void applyOp(Op op) {
for (int i=0; i
Ads help maintain this website.