use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RangeRouterUtils method splitIntFloatVector.
public static KeyValuePart[] splitIntFloatVector(MatrixMeta matrixMeta, IntFloatVector vector) {
IntFloatVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Get keys and values
IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
int[] keys = sparseStorage.getIndices();
float[] values = sparseStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, false);
} else if (storage.isDense()) {
// Get values
IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
float[] values = denseStorage.getValues();
return split(matrixMeta, vector.getRowId(), values);
} else {
// Key and value array pair
IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
float[] values = sortStorage.getValues();
return split(matrixMeta, vector.getRowId(), keys, values, true);
}
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class CompIntFloatRowUpdateSplit method serialize.
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
IntFloatVectorStorage storage = split.getStorage();
if (storage instanceof IntFloatSparseVectorStorage) {
buf.writeInt(storage.size());
ObjectIterator<Int2FloatMap.Entry> iter = storage.entryIterator();
Int2FloatMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeFloat(entry.getFloatValue());
}
} else if (storage instanceof IntFloatSortedVectorStorage) {
buf.writeInt(storage.size());
int[] indices = storage.getIndices();
float[] values = storage.getValues();
for (int i = 0; i < indices.length; i++) {
buf.writeInt(indices[i]);
buf.writeFloat(values[i]);
}
} else if (storage instanceof IntFloatDenseVectorStorage) {
float[] values = storage.getValues();
int writeSize = values.length < maxItemNum ? values.length : maxItemNum;
buf.writeInt(writeSize);
for (int i = 0; i < writeSize; i++) {
buf.writeFloat(values[i]);
}
} else {
throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
}
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RBIntFloatMatrix method diag.
@Override
public Vector diag() {
float[] resArr = new float[rows.length];
for (int i = 0; i < rows.length; i++) {
if (null == rows[i]) {
resArr[i] = 0;
} else {
resArr[i] = rows[i].get(i);
}
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RBIntFloatMatrix method dot.
@Override
public Vector dot(Vector other) {
float[] resArr = new float[rows.length];
for (int i = 0; i < rows.length; i++) {
resArr[i] = (float) rows[i].dot(other);
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(matrixId, 0, clock, rows.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class BlasFloatMatrix method getCol.
@Override
public Vector getCol(int j) {
float[] col = new float[numRows];
for (int i = 0; i < numRows; i++) {
col[i] = data[i * numCols + j];
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(col);
return new IntFloatVector(getMatrixId(), 0, getClock(), numRows, storage);
}
Aggregations