use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method numZeros.
public int numZeros() {
IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
if (dstorage.size() == 0)
return (int) dim;
int numZero = 0;
if (dstorage.isSparse()) {
FloatIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextFloat() != 0) {
numZero += 1;
}
}
} else {
for (float val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (int) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method max.
public float max() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
float maxval = Float.MIN_VALUE;
if (idstorage.isSparse()) {
FloatIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
float val = iter.nextFloat();
if (val > maxval) {
maxval = val;
}
}
} else {
for (float val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method average.
public double average() {
IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
if (dstorage.isSparse()) {
FloatIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
sumval += iter.nextFloat();
}
} else {
for (double val : dstorage.getValues()) {
sumval += val;
}
}
sumval /= getDim();
return sumval;
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class ColumnFormat method saveLongFloatRows.
private void saveLongFloatRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerLongFloatRow) rows[0]);
// int size = rows.size();
long indexOffset = part.getPartitionKey().getStartCol();
LongFloatsCol col = new LongFloatsCol(0, new float[rows.length]);
if (vec instanceof IntFloatVector) {
IntFloatVectorStorage storage = ((IntFloatVector) vec).getStorage();
long startCol = rows[0].getStartCol();
long endCol = rows[0].getEndCol();
if (storage.isDense()) {
for (long i = startCol; i < endCol; i++) {
col.colId = i;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongFloatRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
if (saveContext.sortFirst()) {
int[] indices = storage.getIndices();
Sort.quickSort(indices, 0, indices.length - 1);
for (int i = 0; i < indices.length; i++) {
col.colId = indices[i] + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongFloatRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Int2FloatMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getIntKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongFloatRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
} else {
LongFloatVectorStorage storage = ((LongFloatVector) vec).getStorage();
if (saveContext.sortFirst()) {
long[] indices = storage.getIndices();
Sort.quickSort(indices, 0, indices.length - 1);
for (int i = 0; i < indices.length; i++) {
col.colId = indices[i] + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongFloatRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Long2FloatMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getLongKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongFloatRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class StreamSerdeUtils method serializeIntFloatVector.
// IntFloatVector
private static void serializeIntFloatVector(DataOutputStream out, IntFloatVector vector) throws IOException {
IntFloatVectorStorage storage = vector.getStorage();
if (storage.isDense()) {
serializeInt(out, DENSE_STORAGE_TYPE);
serializeFloats(out, storage.getValues());
} else if (storage.isSparse()) {
serializeInt(out, SPARSE_STORAGE_TYPE);
serializeInt(out, storage.size());
ObjectIterator<Int2FloatMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry e = iter.next();
serializeInt(out, e.getIntKey());
serializeFloat(out, e.getFloatValue());
}
} else if (storage.isSorted()) {
serializeInt(out, SORTED_STORAGE_TYPE);
int[] indices = vector.getStorage().getIndices();
float[] values = vector.getStorage().getValues();
serializeInts(out, indices);
serializeFloats(out, values);
} else {
throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
}
}
Aggregations