Search in sources :

Example 36 with IntFloatVector

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]);
    }
}
Also used : IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 37 with IntFloatVector

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);
    }
}
Also used : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 38 with IntFloatVector

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);
    }
}
Also used : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 39 with IntFloatVector

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());
    }
}
Also used : IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 40 with IntFloatVector

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!");
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntDummyVector(com.tencent.angel.ml.math2.vector.IntDummyVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)104 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)60 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)57 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)50 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)34 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)33 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)32 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)31 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)30 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)30 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)30 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)25 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)21 AngelException (com.tencent.angel.exception.AngelException)20 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20