use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.
the class UpdatePartFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
CSRPartUpdateParam param = (CSRPartUpdateParam) partParam;
PartitionKey pkey = partParam.getPartKey();
pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
try {
while (param.buf.isReadable()) {
int row = param.buf.readInt();
int len = param.buf.readInt();
ServerRow serverRow = psContext.getMatrixStorageManager().getRow(pkey, row);
try {
serverRow.startWrite();
if (serverRow.isDense())
updateDenseIntRow((ServerIntIntRow) serverRow, param.buf, len);
if (serverRow.isSparse())
updateSparseIntRow((ServerIntIntRow) serverRow, param.buf, len);
} finally {
serverRow.endWrite();
}
}
} finally {
param.buf.release();
}
}
use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.
the class GetColumnFunc method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
if (partParam instanceof PartitionGetRowsParam) {
PartitionGetRowsParam param = (PartitionGetRowsParam) partParam;
PartitionKey pkey = param.getPartKey();
pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
List<Integer> reqCols = param.getRowIndexes();
int start = reqCols.get(0);
int end = reqCols.get(1);
MatrixStorageManager manager = psContext.getMatrixStorageManager();
Map<Integer, Int2IntOpenHashMap> cks = new HashMap();
for (int col = start; col < end; col++) cks.put(col, new Int2IntOpenHashMap());
int rowOffset = pkey.getStartRow();
int rowLength = pkey.getEndRow();
for (int r = rowOffset; r < rowLength; r++) {
ServerRow row = manager.getRow(pkey, r);
if (row instanceof ServerIntIntRow) {
for (int col = start; col < end; col++) {
Int2IntOpenHashMap map = cks.get(col);
int k = ((ServerIntIntRow) row).get(col);
if (k > 0)
map.put(row.getRowId(), k);
}
}
}
return new PartColumnResult(cks);
} else {
return null;
}
}
use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.
the class PartCSRResult method bufferLen.
@Override
public int bufferLen() {
int len = 4;
for (ServerRow row : splits) {
if (row.isDense()) {
int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
int size = (int) (row.getEndCol() - row.getStartCol());
int cnt = 0;
for (int i = 0; i < size; i++) if (values[i] > 0)
cnt++;
len += 1 + 4;
if (cnt > size * 0.5) {
// dense
len += 4 * size;
} else {
// sparse
len += 8 * cnt;
}
} else if (row.isSparse()) {
int[] values = ServerRowUtils.getVector((ServerIntIntRow) row).getStorage().getValues();
int size = values.length;
int cnt = 0;
for (int i = 0; i < size; i++) if (values[i] > 0)
cnt++;
len += 1 + 4 + 8 * cnt;
} else
return len;
}
return len;
}
use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.
the class MergeUtils method combineServerIntIntRowSplits.
private static Vector combineServerIntIntRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
int colNum = (int) matrixMeta.getColNum();
int elemNum = 0;
int size = rowSplits.size();
for (int i = 0; i < size; i++) {
elemNum += rowSplits.get(i).size();
}
IntIntVector row;
if (matrixMeta.isHash()) {
row = VFactory.sparseIntVector(colNum, elemNum);
} else {
if (elemNum >= (int) (storageConvFactor * colNum)) {
row = VFactory.denseIntVector(colNum);
} else {
row = VFactory.sparseIntVector(colNum, elemNum);
}
}
row.setMatrixId(matrixMeta.getId());
row.setRowId(rowIndex);
Collections.sort(rowSplits, serverRowComp);
for (int i = 0; i < size; i++) {
if (rowSplits.get(i) == null) {
continue;
}
((ServerIntIntRow) rowSplits.get(i)).mergeTo(row);
}
return row;
}
use of com.tencent.angel.ps.storage.vector.ServerIntIntRow in project angel by Tencent.
the class RowSplitCombineUtils method combineServerIntIntRowSplits.
private static Vector combineServerIntIntRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
int colNum = (int) matrixMeta.getColNum();
int elemNum = 0;
int size = rowSplits.size();
for (int i = 0; i < size; i++) {
elemNum += rowSplits.get(i).size();
}
IntIntVector row;
if (elemNum >= (int) (storageConvFactor * colNum)) {
row = VFactory.denseIntVector(colNum);
} else {
row = VFactory.sparseIntVector(colNum, elemNum);
}
row.setMatrixId(matrixMeta.getId());
row.setRowId(rowIndex);
Collections.sort(rowSplits, serverRowComp);
int clock = Integer.MAX_VALUE;
for (int i = 0; i < size; i++) {
if (rowSplits.get(i) == null) {
continue;
}
if (rowSplits.get(i).getClock() < clock) {
clock = rowSplits.get(i).getClock();
}
((ServerIntIntRow) rowSplits.get(i)).mergeTo(row);
}
row.setClock(clock);
return row;
}
Aggregations