use of com.tencent.angel.ml.math2.vector.IntDoubleVector in project angel by Tencent.
the class SnapshotFormat method save.
private void save(ServerLongDoubleRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
long startCol = meta.getStartCol();
if (ServerRowUtils.getVector(row) instanceof IntDoubleVector) {
IntDoubleVector vector = (IntDoubleVector) ServerRowUtils.getVector(row);
if (vector.isDense()) {
double[] data = vector.getStorage().getValues();
for (int i = 0; i < data.length; i++) {
out.writeDouble(data[i]);
}
} else if (vector.isSorted()) {
int[] indices = vector.getStorage().getIndices();
double[] values = vector.getStorage().getValues();
for (int i = 0; i < indices.length; i++) {
out.writeLong(indices[i] + startCol);
out.writeDouble(values[i]);
}
} else {
ObjectIterator<Int2DoubleMap.Entry> iter = vector.getStorage().entryIterator();
Int2DoubleMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
out.writeLong(entry.getIntKey() + startCol);
out.writeDouble(entry.getDoubleValue());
}
}
} else {
LongDoubleVector vector = (LongDoubleVector) ServerRowUtils.getVector(row);
if (vector.isSorted()) {
long[] indices = vector.getStorage().getIndices();
double[] values = vector.getStorage().getValues();
for (int i = 0; i < indices.length; i++) {
out.writeLong(indices[i] + startCol);
out.writeDouble(values[i]);
}
} else {
ObjectIterator<Long2DoubleMap.Entry> iter = vector.getStorage().entryIterator();
Long2DoubleMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
out.writeLong(entry.getLongKey() + startCol);
out.writeDouble(entry.getDoubleValue());
}
}
}
}
use of com.tencent.angel.ml.math2.vector.IntDoubleVector 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.vector.IntDoubleVector 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.vector.IntDoubleVector in project angel by Tencent.
the class RBCompIntDoubleMatrix method diag.
@Override
public Vector diag() {
double[] resArr = new double[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
return new IntDoubleVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.vector.IntDoubleVector in project angel by Tencent.
the class RBCompIntDoubleMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
IntDoubleVector[] tmpParts = new IntDoubleVector[numComp];
for (int i = 0; i < numComp; i++) {
IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(subDim);
tmpParts[i] = new IntDoubleVector(matrixId, idx, clock, (int) getDim(), storage);
}
CompIntDoubleVector tmpVect = new CompIntDoubleVector(matrixId, idx, clock, (int) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
Aggregations