use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class ByteBufSerdeUtils method serializeIntFloatVectors.
// IntFloatVector array
public static void serializeIntFloatVectors(ByteBuf out, IntFloatVector[] vectors) {
int start = 0;
int end = vectors.length;
serializeInt(out, end - start);
for (int i = start; i < end; i++) {
IntFloatVector vector = vectors[i];
serializeInt(out, vector.getRowId());
serializeLong(out, vector.dim());
// serializeInt(out, vector.getType().getNumber()); // no need to record type
serializeIntFloatVector(out, vectors[i]);
}
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class ByteBufSerdeUtils method deserializeIntFloatVector.
private static IntFloatVector deserializeIntFloatVector(ByteBuf in, long dim) {
int storageType = deserializeInt(in);
switch(storageType) {
case DENSE_STORAGE_TYPE:
return VFactory.denseFloatVector(deserializeFloats(in));
case SPARSE_STORAGE_TYPE:
int len = deserializeInt(in);
Int2FloatOpenHashMap idToValueMap = new Int2FloatOpenHashMap(len);
for (int i = 0; i < len; i++) {
idToValueMap.put(deserializeInt(in), deserializeFloat(in));
}
return new IntFloatVector((int) dim, new IntFloatSparseVectorStorage((int) dim, idToValueMap));
case SORTED_STORAGE_TYPE:
return VFactory.sortedFloatVector((int) dim, deserializeInts(in), deserializeFloats(in));
default:
throw new UnsupportedOperationException("Unsupport storage type " + storageType);
}
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class StreamSerdeUtils method deserializeIntFloatVector.
private static IntFloatVector deserializeIntFloatVector(DataInputStream in, long dim) throws IOException {
int storageType = deserializeInt(in);
switch(storageType) {
case DENSE_STORAGE_TYPE:
return VFactory.denseFloatVector(deserializeFloats(in));
case SPARSE_STORAGE_TYPE:
int len = deserializeInt(in);
Int2FloatOpenHashMap idToValueMap = new Int2FloatOpenHashMap(len);
for (int i = 0; i < len; i++) {
idToValueMap.put(deserializeInt(in), deserializeFloat(in));
}
return new IntFloatVector((int) dim, new IntFloatSparseVectorStorage((int) dim, idToValueMap));
case SORTED_STORAGE_TYPE:
return VFactory.sortedFloatVector((int) dim, deserializeInts(in), deserializeFloats(in));
default:
throw new UnsupportedOperationException("Unsupport storage type " + storageType);
}
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class StreamSerdeUtils method serializeIntFloatVector.
// IntFloatVector
private static void serializeIntFloatVector(DataOutputStream out, IntFloatVector vector) throws IOException {
IntFloatVectorStorage storage = vector.getStorage();
if (storage.isDense()) {
serializeInt(out, DENSE_STORAGE_TYPE);
serializeFloats(out, storage.getValues());
} else if (storage.isSparse()) {
serializeInt(out, SPARSE_STORAGE_TYPE);
serializeInt(out, storage.size());
ObjectIterator<Int2FloatMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry e = iter.next();
serializeInt(out, e.getIntKey());
serializeFloat(out, e.getFloatValue());
}
} else if (storage.isSorted()) {
serializeInt(out, SORTED_STORAGE_TYPE);
int[] indices = vector.getStorage().getIndices();
float[] values = vector.getStorage().getValues();
serializeInts(out, indices);
serializeFloats(out, values);
} else {
throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
}
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class DotMatrixExecutor method apply.
private static Matrix apply(BlasFloatMatrix mat1, boolean trans1, RBIntFloatMatrix mat2, boolean trans2) {
if (trans1 && !trans2) {
int outputRows = mat1.getNumCols();
IntFloatVector[] rows = new IntFloatVector[outputRows];
for (int i = 0; i < outputRows; i++) {
Vector col = mat1.getCol(i);
rows[i] = (IntFloatVector) mat2.transDot(col);
}
return MFactory.rbIntFloatMatrix(rows);
} else if (!trans1 && !trans2) {
int outputRows = mat1.getNumRows();
IntFloatVector[] rows = new IntFloatVector[outputRows];
for (int i = 0; i < outputRows; i++) {
Vector row = mat1.getRow(i);
rows[i] = (IntFloatVector) mat2.transDot(row);
}
return MFactory.rbIntFloatMatrix(rows);
} else {
throw new AngelException("the operation is not supported!");
}
}
Aggregations