Search in sources :

Example 1 with StorageMethod

use of com.tencent.angel.ps.storage.vector.storage.StorageMethod in project angel by Tencent.

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(ByteBuf input) {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 2 with StorageMethod

use of com.tencent.angel.ps.storage.vector.storage.StorageMethod in project angel by Tencent.

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(DataInputStream input) throws IOException {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 3 with StorageMethod

use of com.tencent.angel.ps.storage.vector.storage.StorageMethod in project angel by Tencent.

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(DataInputStream input) throws IOException {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 4 with StorageMethod

use of com.tencent.angel.ps.storage.vector.storage.StorageMethod in project angel by Tencent.

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(ByteBuf input) {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)4 StorageMethod (com.tencent.angel.ps.storage.vector.storage.StorageMethod)4