use of com.tencent.angel.ml.math2.vector.CompIntFloatVector in project angel by Tencent.
the class MixedBinaryOutZAExecutor method apply.
private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (v1.size() > v2.size()) {
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
int[] v2Indices = v2.getIndices();
for (int i = 0; i < v2Indices.length; i++) {
int idx = v2Indices[i];
int pidx = (int) (idx / subDim);
int subidx = idx % subDim;
if (parts[pidx].hasKey(subidx)) {
((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
}
} else {
int base = 0;
for (int i = 0; i < parts.length; i++) {
IntFloatVector part = parts[i];
IntFloatVectorStorage resPart = (IntFloatVectorStorage) resParts[i];
if (part.isDense()) {
float[] partValues = part.getStorage().getValues();
float[] resPartValues = resPart.getValues();
for (int j = 0; j < partValues.length; j++) {
if (v2.hasKey(j + base)) {
resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
}
}
} else if (part.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> piter = part.getStorage().entryIterator();
while (piter.hasNext()) {
Int2FloatMap.Entry entry = piter.next();
int idx = entry.getIntKey();
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(entry.getFloatValue(), v2.get(idx + base)));
}
}
} else {
// sorted
if (op.isKeepStorage()) {
int[] partIndices = part.getStorage().getIndices();
float[] partValues = part.getStorage().getValues();
int[] resPartIndices = resPart.getIndices();
float[] resPartValues = resPart.getValues();
for (int j = 0; j < partIndices.length; j++) {
int idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPartIndices[j] = idx;
resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
}
}
} else {
int[] partIndices = part.getStorage().getIndices();
float[] partValues = part.getStorage().getValues();
for (int j = 0; j < partIndices.length; j++) {
int idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
}
}
}
}
base += part.getDim();
}
}
IntFloatVector[] res = new IntFloatVector[parts.length];
int i = 0;
for (IntFloatVector part : parts) {
res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
i++;
}
return new CompIntFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.vector.CompIntFloatVector in project angel by Tencent.
the class UpdateColsFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
PartitionUpdateColsParam param = (PartitionUpdateColsParam) partParam;
int[] rows = param.rows;
long[] cols = param.cols;
Vector vector = param.vector;
UpdateOp op = param.op;
int matId = param.getMatrixId();
int partitionId = param.getPartKey().getPartitionId();
RowBasedPartition partition = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(matId, partitionId);
switch(partition.getRowType()) {
case T_DOUBLE_DENSE:
case T_DOUBLE_SPARSE:
{
ServerIntDoubleRow[] doubles = new ServerIntDoubleRow[rows.length];
for (int r = 0; r < rows.length; r++) doubles[r] = (ServerIntDoubleRow) partition.getRow(rows[r]);
doUpdate((CompIntDoubleVector) vector, rows, cols, doubles, op);
return;
}
case T_DOUBLE_SPARSE_LONGKEY:
{
ServerLongDoubleRow[] doubles = new ServerLongDoubleRow[rows.length];
for (int r = 0; r < rows.length; r++) doubles[r] = (ServerLongDoubleRow) partition.getRow(rows[r]);
doUpdate((CompIntDoubleVector) vector, rows, cols, doubles, op);
return;
}
case T_FLOAT_DENSE:
case T_FLOAT_SPARSE:
{
ServerIntFloatRow[] floats = new ServerIntFloatRow[rows.length];
for (int r = 0; r < rows.length; r++) floats[r] = (ServerIntFloatRow) partition.getRow(rows[r]);
doUpdate((CompIntFloatVector) vector, rows, cols, floats, op);
return;
}
case T_FLOAT_SPARSE_LONGKEY:
{
ServerLongFloatRow[] floats = new ServerLongFloatRow[rows.length];
for (int r = 0; r < rows.length; r++) floats[r] = (ServerLongFloatRow) partition.getRow(rows[r]);
doUpdate((CompIntFloatVector) vector, rows, cols, floats, op);
return;
}
default:
throw new AngelException("Data type should be double or float!");
}
}
use of com.tencent.angel.ml.math2.vector.CompIntFloatVector in project angel by Tencent.
the class MatrixUtils method rbCompDense2Blas.
public static BlasFloatMatrix rbCompDense2Blas(RBCompIntFloatMatrix mat) {
assert mat != null;
int dim = (int) mat.getDim();
int subDim = mat.getSubDim();
CompIntFloatVector[] rows = mat.getRows();
float[] data = new float[rows.length * dim];
int rowId = 0;
for (CompIntFloatVector row : rows) {
IntFloatVector[] partitions = row.getPartitions();
int partId = 0;
for (IntFloatVector part : partitions) {
assert part.isDense();
float[] src = part.getStorage().getValues();
System.arraycopy(src, 0, data, rowId * dim + partId * subDim, src.length);
partId += 1;
}
rowId += 1;
}
return MFactory.denseFloatMatrix(rows.length, dim, data);
}
Aggregations