use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntDoubleVector method average.
public double average() {
IntDoubleVectorStorage dstorage = (IntDoubleVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
if (dstorage.isSparse()) {
DoubleIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
sumval += iter.nextDouble();
}
} else {
for (double val : dstorage.getValues()) {
sumval += val;
}
}
sumval /= getDim();
return sumval;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntDoubleVector method numZeros.
public int numZeros() {
IntDoubleVectorStorage dstorage = (IntDoubleVectorStorage) storage;
if (dstorage.size() == 0)
return (int) dim;
int numZero = 0;
if (dstorage.isSparse()) {
DoubleIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextDouble() != 0) {
numZero += 1;
}
}
} else {
for (double val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (int) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class ColumnFormat method saveIntDoubleRows.
private void saveIntDoubleRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerIntDoubleRow) rows[0]);
// int size = rows.length;
int indexOffset = (int) part.getPartitionKey().getStartCol();
IntDoubleVectorStorage storage = ((IntDoubleVector) vec).getStorage();
IntDoublesCol col = new IntDoublesCol(0, new double[rows.length]);
int startCol = (int) rows[0].getStartCol();
int endCol = (int) rows[0].getEndCol();
if (storage.isDense()) {
for (int i = startCol; i < endCol; i++) {
col.colId = i;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerIntDoubleRow) (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] = ((ServerIntDoubleRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Int2DoubleMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getIntKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerIntDoubleRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.Storage 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.Storage in project angel by Tencent.
the class ColumnFormat method saveLongIntRows.
private void saveLongIntRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerLongIntRow) rows[0]);
// int size = rows.size();
long indexOffset = part.getPartitionKey().getStartCol();
LongIntsCol col = new LongIntsCol(0, new int[rows.length]);
if (vec instanceof IntIntVector) {
IntIntVectorStorage storage = ((IntIntVector) 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] = ((ServerLongIntRow) (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] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Int2IntMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getIntKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
} else {
LongIntVectorStorage storage = ((LongIntVector) 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] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Long2IntMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getLongKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
Aggregations