use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class CompIntLongRowUpdateSplit method serialize.
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
IntLongVectorStorage storage = split.getStorage();
if (storage instanceof IntLongSparseVectorStorage) {
buf.writeInt(storage.size());
ObjectIterator<Int2LongMap.Entry> iter = storage.entryIterator();
Int2LongMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeLong(entry.getLongValue());
}
} else if (storage instanceof IntLongSortedVectorStorage) {
buf.writeInt(storage.size());
int[] indices = storage.getIndices();
long[] values = storage.getValues();
for (int i = 0; i < indices.length; i++) {
buf.writeInt(indices[i]);
buf.writeLong(values[i]);
}
} else if (storage instanceof IntLongDenseVectorStorage) {
long[] values = storage.getValues();
int writeSize = values.length < maxItemNum ? values.length : maxItemNum;
buf.writeInt(writeSize);
for (int i = 0; i < writeSize; i++) {
buf.writeLong(values[i]);
}
} else {
throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
}
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class RBIntLongMatrix method diag.
@Override
public Vector diag() {
long[] resArr = new long[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntLongDenseVectorStorage storage = new IntLongDenseVectorStorage(resArr);
return new IntLongVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntLongDenseVectorStorage in project angel by Tencent.
the class RBCompLongLongMatrix method diag.
@Override
public Vector diag() {
long[] resArr = new long[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntLongDenseVectorStorage storage = new IntLongDenseVectorStorage(resArr);
return new IntLongVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
Aggregations