use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class ColumnFormat method saveIntIntRows.
private void saveIntIntRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerIntIntRow) rows[0]);
// int size = rows.size();
int indexOffset = (int) part.getPartitionKey().getStartCol();
IntIntVectorStorage storage = ((IntIntVector) vec).getStorage();
IntIntsCol col = new IntIntsCol(0, new int[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] = ((ServerIntIntRow) (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] = ((ServerIntIntRow) (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] = ((ServerIntIntRow) (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 saveLongDoubleRows.
private void saveLongDoubleRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerLongDoubleRow) rows[0]);
// int size = rows.size();
long indexOffset = part.getPartitionKey().getStartCol();
LongDoublesCol col = new LongDoublesCol(0, new double[rows.length]);
if (vec instanceof IntDoubleVector) {
IntDoubleVectorStorage storage = ((IntDoubleVector) 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] = ((ServerLongDoubleRow) (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] = ((ServerLongDoubleRow) (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] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
} else {
LongDoubleVectorStorage storage = ((LongDoubleVector) 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] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Long2DoubleMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getLongKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongDoubleRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class RBCompLongFloatMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
LongFloatVector[] tmpParts = new LongFloatVector[numComp];
for (int i = 0; i < numComp; i++) {
LongFloatSparseVectorStorage storage = new LongFloatSparseVectorStorage(subDim);
tmpParts[i] = new LongFloatVector(matrixId, idx, clock, (long) getDim(), storage);
}
CompLongFloatVector tmpVect = new CompLongFloatVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class RBCompLongLongMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
LongLongVector[] tmpParts = new LongLongVector[numComp];
for (int i = 0; i < numComp; i++) {
LongLongSparseVectorStorage storage = new LongLongSparseVectorStorage(subDim);
tmpParts[i] = new LongLongVector(matrixId, idx, clock, (long) getDim(), storage);
}
CompLongLongVector tmpVect = new CompLongLongVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class CooLongDoubleMatrix method getRow.
@Override
public Vector getRow(int idx) {
LongArrayList cols = new LongArrayList();
DoubleArrayList data = new DoubleArrayList();
for (int i = 0; i < rowIndices.length; i++) {
if (rowIndices[i] == idx) {
cols.add(colIndices[i]);
data.add(values[i]);
}
}
LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage(shape[1], cols.toLongArray(), data.toDoubleArray());
return new LongDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Aggregations