datasets.VectorInt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstat Show documentation
Show all versions of jstat Show documentation
Java Library for Statistical Analysis.
The newest version!
package datasets;
import datastructs.IVector;
import datastructs.RowType;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
import java.util.List;
public class VectorInt implements IVector {
/**
* Creates an vector with initial capacity of 10
*/
public VectorInt(){
this.data = new VectorStorage<>(10, 0);
}
/**
* Creates a vector of given size with entries initialized to val
*/
public VectorInt(int size, int val){
this.data = new VectorStorage<>(size, val);
}
/**
* Create a vector from the given double values
*/
public VectorInt(Integer... data){
this.data = new VectorStorage<>(data);
}
/**
* Creates a vector of given size with entries initialized to 0.0
*/
public VectorInt(int size){
this(size, 0);
}
/**
* Create a vector from another vector i.e. copy constructor
*/
public VectorInt(IVector data){
this(data.size(), 0);
this.set(data);
}
/**
* Create from the given Table and the given column name
*/
public VectorInt(Table table, String columnName){
this(table.doubleColumn(columnName));
}
/**
* Create a vector from the given DoubleColumn
*/
public VectorInt(DoubleColumn column){
this.data = new VectorStorage<>(column.size(), 0);
this.set(column);
}
@Override
public final RowType.Type getType(){return RowType.Type.INTEGER_VECTOR; }
/**
* Returns true if the vector is empty
*/
@Override
public boolean empty(){
return this.data.isEmpty();
}
/**
* Build a new instance of this class
*/
@Override
public IVector create(int size){
return new VectorInt(size, 0);
}
/**
* Build a new instance of this class
*/
@Override
public IVector create( Integer... value){
return new VectorInt(value);
}
@Override
public IVector create(){return new VectorInt();}
/**
* Resize the vector
*/
@Override
public final void resize(int size){
if(data == null){
this.data.create(size, 0);
}
else{
// nothing to do here if sizes are the same
if(size == data.size()){
return;
}
VectorStorage newVec = new VectorStorage(size, 0);
if(size > data.size()){
for(int i=0; i values){
if(values.size() != this.size()){
throw new IllegalArgumentException("Invalid Vector size: "+ values.size() + " != " + this.size());
}
for(int i=0; i getRawData(){
return data.getRawData();
}
/**
* The vector data
*/
VectorStorage data = null;
}