public class Vec extends Keyed
A distributed vector has a count of elements, an element-to-chunk mapping, a Java type (mostly determines rounding on store and display), and functions to directly load elements without further indirections. The data is compressed, or backed by disk or both. *Writing* to elements may throw if the backing data is read-only (file backed).
Vec Key format is: Key. VEC - byte, 0 - byte, 0 - int, normal Key bytes. DVec Key format is: Key.DVEC - byte, 0 - byte, chunk# - int, normal Key bytes.The main API is at, set, and isNA:
double at ( long row ); // Returns the value expressed as a double. NaN if missing. long at8 ( long row ); // Returns the value expressed as a long. Throws if missing. boolean isNA( long row ); // True if the value is missing. set( long row, double d ); // Stores a double; NaN will be treated as missing. set( long row, long l ); // Stores a long; throws if l exceeds what fits in a double & any floats are ever set. setNA( long row ); // Sets the value as missing.Note this dangerous scenario: loading a missing value as a double, and setting it as a long:
set(row,(long)at(row)); // Danger!The cast from a Double.NaN to a long produces a zero! This code will replace a missing value with a zero.
| Modifier and Type | Class and Description |
|---|---|
static class |
Vec.VectorGroup
Class representing the group of vectors.
|
static class |
Vec.Writer
More efficient way to write randomly to a Vec - still slow, but much
faster than Vec.set().
|
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String[] |
_domain
Enum/factor/categorical names.
|
protected boolean |
_isString
String flag
|
protected boolean |
_isUUID
UUID flag
|
protected byte |
_time
Time parse, index into Utils.TIME_PARSE, or -1 for not-a-time
|
static int |
CHUNK_SZ
Chunk size.
|
static int |
KEY_PREFIX_LEN |
| Modifier | Constructor and Description |
|---|---|
|
Vec(Key key,
long[] espc)
Main default constructor; requires the caller understand Chunk layout
already, along with count of missing elements.
|
|
Vec(Key key,
long[] espc,
java.lang.String[] domain) |
|
Vec(Key key,
long[] espc,
java.lang.String[] domain,
boolean hasUUID,
boolean hasString,
byte time) |
protected |
Vec(Key key,
Vec v) |
| Modifier and Type | Method and Description |
|---|---|
Vec |
align(Vec vec)
Always makes a copy of the given vector which shares the same
group.
|
double |
at(long i)
Fetch element the slow way, as a double.
|
long |
at16h(long i) |
long |
at16l(long i)
Fetch element the slow way, as a long.
|
long |
at8(long i)
Fetch element the slow way, as a long.
|
ValueString |
atStr(ValueString vstr,
long i) |
double |
base() |
long[] |
bins()
Histogram bins.
|
int |
cardinality()
Returns cardinality for enum domain or -1 for other types.
|
protected boolean |
checkMissing(int cidx,
Value val) |
Chunk |
chunkForChunkIdx(int cidx)
The Chunk for a chunk#.
|
Chunk |
chunkForRow(long i)
The Chunk for a row#.
|
protected Value |
chunkIdx(int cidx)
Get a Chunk's Value by index.
|
Key |
chunkKey(int cidx)
Get a Chunk Key from a chunk-index.
|
static Key |
chunkKey(Key veckey,
int cidx) |
int |
chunkLen(int cidx)
Number of rows in chunk.
|
java.lang.String[] |
domain()
Return an array of domains.
|
boolean |
equals(java.lang.Object o) |
java.lang.String[] |
factors() |
static Key |
getVecKey(Key key)
Get a Vec Key from Chunk Key, without loading the Chunk
|
Vec.VectorGroup |
group()
Get the group this vector belongs to.
|
int |
hashCode() |
boolean |
isConst()
Is the column constant.
|
boolean |
isEnum()
Is the column a factor/categorical/enum? Note: all "isEnum()" columns
are are also "isInt()" but not vice-versa.
|
boolean |
isInt()
Is all integers?
|
boolean |
isNA(long row)
Fetch the missing-status the slow way.
|
boolean |
isString() |
boolean |
isTime()
Whether or not this column parsed as a time, and if so what pattern was used.
|
boolean |
isUUID() |
long |
length()
Number of elements in the vector.
|
protected Vec |
makeCon(double d) |
static Vec |
makeCon(long l,
java.lang.String[] domain,
long len) |
static Vec |
makeCon(long l,
java.lang.String[] domain,
Vec.VectorGroup group,
long[] espc) |
static Vec |
makeConSeq(double x,
long len) |
static Vec |
makeSeq(long len) |
Vec |
makeTransf(int[][] map,
java.lang.String[] finalDomain)
Create a vector transforming values according given domain map.
|
Vec |
makeTransf(int[] values,
int[] indexes,
java.lang.String[] domain)
Creates a new transformation from given values to given indexes of given domain.
|
Vec |
makeZero()
Make a new vector with the same size and data layout as the old one, and
initialized to zero.
|
Vec |
makeZero(java.lang.String[] domain) |
protected Vec |
masterVec()
This Vec does not have dependent hidden Vec it uses.
|
double |
max()
Return column max - lazily computed as needed.
|
double[] |
maxs() |
double |
mean()
Return column mean - lazily computed as needed.
|
double |
min()
Return column min - lazily computed as needed.
|
double[] |
mins() |
long |
naCnt()
Return column missing-element-count - lazily computed as needed.
|
int |
nChunks()
Number of chunks.
|
static Key |
newKey()
Make a new random Key that fits the requirements for a Vec key.
|
long |
ninfs() |
long |
nzCnt()
Return column zero-element-count - lazily computed as needed.
|
Vec.Writer |
open()
Create a writer for bulk serial writes into this Vec
|
long |
pinfs()
Positive and negative infinity counts
|
Futures |
postWrite(Futures fs)
Stop writing into this Vec.
|
void |
preWriting()
Writing into this Vector from *some* chunk.
|
protected boolean |
readable()
Default read/write behavior for Vecs.
|
Futures |
remove_impl(Futures fs) |
RollupStats |
rollupStats()
Compute the roll-up stats as-needed
|
Key |
rollupStatsKey() |
void |
set_factors(java.lang.String[] factors) |
void |
set(long i,
double d)
Write element the slow way, as a double.
|
void |
set(long i,
float f)
Write element the slow way, as a float.
|
void |
set(long i,
long l)
Write element the slow way, as a long.
|
void |
set(long i,
java.lang.String str) |
double |
sigma()
Return column standard deviation - lazily computed as needed.
|
double |
stride() |
java.lang.String |
timeParse() |
Vec |
toEnum()
Transform this vector to enum.
|
java.lang.String |
toString()
Pretty print the Vec: [#elems, min/mean/max]{chunks,...}
|
protected boolean |
writable()
Default read/write behavior for Vecs.
|
clone, frozenType, read_impl, read, readJSON_impl, readJSON, write_impl, write, writeHTML_impl, writeHTML, writeJSON_impl, writeJSONpublic static final int CHUNK_SZ
protected java.lang.String[] _domain
protected byte _time
protected boolean _isUUID
protected boolean _isString
public static final int KEY_PREFIX_LEN
public Vec(Key key, long[] espc)
public Vec(Key key, long[] espc, java.lang.String[] domain)
public Vec(Key key, long[] espc, java.lang.String[] domain, boolean hasUUID, boolean hasString, byte time)
public final java.lang.String[] factors()
public final void set_factors(java.lang.String[] factors)
public Vec makeZero()
public Vec makeZero(java.lang.String[] domain)
public static Vec makeCon(long l, java.lang.String[] domain, long len)
public static Vec makeCon(long l, java.lang.String[] domain, Vec.VectorGroup group, long[] espc)
protected Vec makeCon(double d)
public static Vec makeSeq(long len)
public static Vec makeConSeq(double x, long len)
public long length()
public int nChunks()
public int chunkLen(int cidx)
public final boolean isEnum()
public final boolean isUUID()
public final boolean isString()
public final boolean isTime()
public final java.lang.String timeParse()
public final boolean isConst()
Returns true if the column contains only constant values and it is not full of NAs.
public java.lang.String[] domain()
public int cardinality()
protected boolean readable()
protected boolean writable()
public double min()
public double[] mins()
public double max()
public double[] maxs()
public double mean()
public double sigma()
public long naCnt()
public long nzCnt()
public long pinfs()
public long ninfs()
public boolean isInt()
public long[] bins()
public double base()
public double stride()
public RollupStats rollupStats()
public void preWriting()
public Futures postWrite(Futures fs)
public static Key getVecKey(Key key)
public Key chunkKey(int cidx)
public Key rollupStatsKey()
protected Value chunkIdx(int cidx)
DKV.get(). Warning: this pulls the data locally;
using this call on every Chunk index on the same node will
probably trigger an OOM!protected boolean checkMissing(int cidx,
Value val)
public static Key newKey()
public final Vec.VectorGroup group()
public Chunk chunkForChunkIdx(int cidx)
public final Chunk chunkForRow(long i)
public final long at8(long i)
public final double at(long i)
public final boolean isNA(long row)
public final long at16l(long i)
public final long at16h(long i)
public final ValueString atStr(ValueString vstr, long i)
public final void set(long i,
long l)
public final void set(long i,
double d)
public final void set(long i,
float f)
public final void set(long i,
java.lang.String str)
public final Vec.Writer open()
public java.lang.String toString()
toString in class java.lang.Objectpublic Futures remove_impl(Futures fs)
remove_impl in class Keyedpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic Vec align(Vec vec)
vec - vector which is intended to be copiedVec.VectorGroup with this vectorpublic Vec toEnum()
public Vec makeTransf(int[][] map, java.lang.String[] finalDomain)
makeTransf(int[], int[], String[])public Vec makeTransf(int[] values, int[] indexes, java.lang.String[] domain)
values - values being mapped fromindexes - values being mapped todomain - domain of new vectorprotected Vec masterVec()
null