use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class BlasFloatMatrix method setCol.
public Matrix setCol(int i, Vector v) {
if (v instanceof IntFloatVector) {
float[] rowData;
if (v.isDense()) {
rowData = ((IntFloatVector) v).getStorage().getValues();
} else if (v.isSparse()) {
rowData = new float[numRows];
ObjectIterator<Int2FloatMap.Entry> iter = ((IntFloatVector) v).getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int j = entry.getIntKey();
rowData[j] = entry.getFloatValue();
}
} else {
// sorted
rowData = new float[numRows];
int[] idxs = ((IntFloatVector) v).getStorage().getIndices();
float[] values = ((IntFloatVector) v).getStorage().getValues();
int size = ((IntFloatVector) v).size();
for (int k = 0; k < size; k++) {
int j = idxs[k];
rowData[j] = values[k];
}
}
for (int j = 0; j < numRows; j++) {
data[j * numCols + i] = rowData[j];
}
} else if (v instanceof IntLongVector) {
long[] rowData;
if (v.isDense()) {
rowData = ((IntLongVector) v).getStorage().getValues();
} else if (v.isSparse()) {
rowData = new long[numRows];
ObjectIterator<Int2LongMap.Entry> iter = ((IntLongVector) v).getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
rowData[j] = entry.getLongValue();
}
} else {
// sorted
rowData = new long[numRows];
int[] idxs = ((IntLongVector) v).getStorage().getIndices();
long[] values = ((IntLongVector) v).getStorage().getValues();
int size = ((IntLongVector) v).size();
for (int k = 0; k < size; k++) {
int j = idxs[k];
rowData[j] = values[k];
}
}
for (int j = 0; j < numRows; j++) {
data[j * numCols + i] = rowData[j];
}
} else if (v instanceof IntIntVector) {
int[] rowData;
if (v.isDense()) {
rowData = ((IntIntVector) v).getStorage().getValues();
} else if (v.isSparse()) {
rowData = new int[numRows];
ObjectIterator<Int2IntMap.Entry> iter = ((IntIntVector) v).getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int j = entry.getIntKey();
rowData[j] = entry.getIntValue();
}
} else {
// sorted
rowData = new int[numRows];
int[] idxs = ((IntIntVector) v).getStorage().getIndices();
int[] values = ((IntIntVector) v).getStorage().getValues();
int size = ((IntIntVector) v).size();
for (int k = 0; k < size; k++) {
int j = idxs[k];
rowData[j] = values[k];
}
}
for (int j = 0; j < numRows; j++) {
data[j * numCols + i] = rowData[j];
}
} else if (v instanceof IntDummyVector) {
int[] rowData = new int[numRows];
int[] idxs = ((IntDummyVector) v).getIndices();
int size = ((IntDummyVector) v).size();
for (int k = 0; k < size; k++) {
int j = idxs[k];
rowData[j] = 1;
}
for (int j = 0; j < numRows; j++) {
data[j * numCols + i] = rowData[j];
}
} else {
throw new AngelException("The operation is not supported!");
}
return this;
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryOutZAExecutor method apply.
private static Vector apply(CompIntLongVector v1, IntDummyVector v2, Binary op) {
IntLongVector[] 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)) {
((IntLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
}
} else {
int base = 0;
for (int i = 0; i < parts.length; i++) {
IntLongVector part = parts[i];
IntLongVectorStorage resPart = (IntLongVectorStorage) resParts[i];
if (part.isDense()) {
long[] partValues = part.getStorage().getValues();
long[] 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<Int2LongMap.Entry> piter = part.getStorage().entryIterator();
while (piter.hasNext()) {
Int2LongMap.Entry entry = piter.next();
int idx = entry.getIntKey();
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(entry.getLongValue(), v2.get(idx + base)));
}
}
} else {
// sorted
if (op.isKeepStorage()) {
int[] partIndices = part.getStorage().getIndices();
long[] partValues = part.getStorage().getValues();
int[] resPartIndices = resPart.getIndices();
long[] 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();
long[] 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();
}
}
IntLongVector[] res = new IntLongVector[parts.length];
int i = 0;
for (IntLongVector part : parts) {
res[i] = new IntLongVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntLongVectorStorage) resParts[i]);
i++;
}
return new CompIntLongVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompIntDoubleVector v1, IntDummyVector v2, Binary op) {
IntDoubleVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof IntDoubleSortedVectorStorage) {
resParts[i] = new IntDoubleSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
int subidx = i % subDim;
((IntDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
IntDoubleVector[] res = new IntDoubleVector[parts.length];
int i = 0;
for (IntDoubleVector part : parts) {
res[i] = new IntDoubleVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntDoubleVectorStorage) resParts[i]);
i++;
}
return new CompIntDoubleVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompIntLongVector v1, IntDummyVector v2, Binary op) {
IntLongVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof IntLongSortedVectorStorage) {
resParts[i] = new IntLongSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
int subidx = i % subDim;
((IntLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
IntLongVector[] res = new IntLongVector[parts.length];
int i = 0;
for (IntLongVector part : parts) {
res[i] = new IntLongVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntLongVectorStorage) resParts[i]);
i++;
}
return new CompIntLongVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof IntFloatSortedVectorStorage) {
resParts[i] = new IntFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
int subidx = i % subDim;
((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
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());
}
Aggregations