use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class ColumnFormat method saveLongIntRows.
private void saveLongIntRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerLongIntRow) rows[0]);
// int size = rows.size();
long indexOffset = part.getPartitionKey().getStartCol();
LongIntsCol col = new LongIntsCol(0, new int[rows.length]);
if (vec instanceof IntIntVector) {
IntIntVectorStorage storage = ((IntIntVector) vec).getStorage();
long startCol = rows[0].getStartCol();
long endCol = rows[0].getEndCol();
if (storage.isDense()) {
for (long i = startCol; i < endCol; i++) {
col.colId = i;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
if (saveContext.sortFirst()) {
int[] indices = storage.getIndices();
Sort.quickSort(indices, 0, indices.length - 1);
for (int i = 0; i < indices.length; i++) {
col.colId = indices[i] + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Int2IntMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getIntKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
} else {
LongIntVectorStorage storage = ((LongIntVector) vec).getStorage();
if (saveContext.sortFirst()) {
long[] indices = storage.getIndices();
Sort.quickSort(indices, 0, indices.length - 1);
for (int i = 0; i < indices.length; i++) {
col.colId = indices[i] + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Long2IntMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getLongKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerLongIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class ColumnFormat method saveIntIntRows.
private void saveIntIntRows(ServerPartition part, ServerRow[] rows, MatrixPartitionMeta partMeta, PSMatrixSaveContext saveContext, DataOutputStream output) throws IOException {
Vector vec = ServerRowUtils.getVector((ServerIntIntRow) rows[0]);
// int size = rows.size();
int indexOffset = (int) part.getPartitionKey().getStartCol();
IntIntVectorStorage storage = ((IntIntVector) vec).getStorage();
IntIntsCol col = new IntIntsCol(0, new int[rows.length]);
int startCol = (int) rows[0].getStartCol();
int endCol = (int) rows[0].getEndCol();
if (storage.isDense()) {
for (int i = startCol; i < endCol; i++) {
col.colId = i;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerIntIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
if (saveContext.sortFirst()) {
int[] indices = storage.getIndices();
Sort.quickSort(indices, 0, indices.length - 1);
for (int i = 0; i < indices.length; i++) {
col.colId = indices[i] + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerIntIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
} else {
ObjectIterator<Int2IntMap.Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
col.colId = iter.next().getIntKey() + indexOffset;
for (int j = 0; j < rows.length; j++) {
col.colElems[j] = ((ServerIntIntRow) (rows[j])).get(col.colId);
}
save(col, output);
}
}
}
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompIntIntVector v1, IntDummyVector v2, Binary op) {
IntIntVector[] 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 IntIntSortedVectorStorage) {
resParts[i] = new IntIntSparseVectorStorage(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;
((IntIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
IntIntVector[] res = new IntIntVector[parts.length];
int i = 0;
for (IntIntVector part : parts) {
res[i] = new IntIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntIntVectorStorage) resParts[i]);
i++;
}
return new CompIntIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class SimpleBinaryInAllExecutor method apply.
public static Vector apply(IntFloatVector v1, IntIntVector v2, Binary op) {
if (v1.isDense() && v2.isDense()) {
float[] resValues = v1.getStorage().getValues();
int[] v2Values = v2.getStorage().getValues();
for (int idx = 0; idx < resValues.length; idx++) {
resValues[idx] = op.apply(resValues[idx], v2Values[idx]);
}
} else if (v1.isDense() && v2.isSparse()) {
float[] resValues = v1.getStorage().getValues();
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
} else if (v1.isDense() && v2.isSorted()) {
float[] resValues = v1.getStorage().getValues();
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
int size = v2.size();
for (int i = 0; i < size; i++) {
int idx = v2Indices[i];
resValues[idx] = op.apply(v1.get(idx), v2Values[i]);
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
} else if (v1.isSparse() && v2.isDense()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
int[] v2Values = v2.getStorage().getValues();
if (v1.size() < Constant.denseLoopThreshold * v1.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(0, v2Values[i]);
}
ObjectIterator<Int2FloatMap.Entry> iter = v1.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = entry.getIntKey();
resValues[idx] = op.apply(entry.getFloatValue(), v2Values[idx]);
}
} else {
for (int i = 0; i < resValues.length; i++) {
if (v1.getStorage().hasKey(i)) {
resValues[i] = op.apply(v1.get(i), v2Values[i]);
} else {
resValues[i] = op.apply(0, v2Values[i]);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isDense()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
int[] v2Values = v2.getStorage().getValues();
if (v1.size() < Constant.denseLoopThreshold * v1.getDim()) {
int[] v1Indices = v1.getStorage().getIndices();
float[] v1Values = v1.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(0, v2Values[i]);
}
int size = v1.size();
for (int i = 0; i < size; i++) {
int idx = v1Indices[i];
resValues[idx] = op.apply(v1Values[i], v2Values[idx]);
}
} else {
IntFloatVectorStorage v1Storage = v1.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v1Storage.hasKey(i)) {
resValues[i] = op.apply(v1.get(i), v2Values[i]);
} else {
resValues[i] = op.apply(0, v2Values[i]);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSparse() && v2.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
ObjectIterator<Int2FloatMap.Entry> iter1 = v1.getStorage().entryIterator();
while (iter1.hasNext()) {
Int2FloatMap.Entry entry = iter1.next();
int idx = entry.getIntKey();
resValues[idx] = entry.getFloatValue();
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSparse() && v2.isSorted()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
ObjectIterator<Int2FloatMap.Entry> iter1 = v1.getStorage().entryIterator();
while (iter1.hasNext()) {
Int2FloatMap.Entry entry = iter1.next();
int idx = entry.getIntKey();
resValues[idx] = entry.getFloatValue();
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
int size = v2.size();
for (int i = 0; i < size; i++) {
int idx = v2Indices[i];
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), v2Values[i]);
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
int[] v1Indices = v1.getStorage().getIndices();
float[] v1Values = v1.getStorage().getValues();
int size = v1.size();
for (int i = 0; i < size; i++) {
int idx = v1Indices[i];
resValues[idx] = v1Values[i];
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isSorted()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
int v1Pointor = 0;
int v2Pointor = 0;
int size1 = v1.size();
int size2 = v2.size();
int[] v1Indices = v1.getStorage().getIndices();
float[] v1Values = v1.getStorage().getValues();
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
if (!op.isCompare()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = Float.NaN;
}
}
while (v1Pointor < size1 && v2Pointor < size2) {
if (v1Indices[v1Pointor] == v2Indices[v2Pointor]) {
resValues[v1Indices[v1Pointor]] = op.apply(v1Values[v1Pointor], v2Values[v2Pointor]);
v1Pointor++;
v2Pointor++;
} else if (v1Indices[v1Pointor] < v2Indices[v2Pointor]) {
resValues[v1Indices[v1Pointor]] = op.apply(v1Values[v1Pointor], 0);
v1Pointor++;
} else {
// v1Indices[v1Pointor] > v2Indices[v2Pointor]
resValues[v2Indices[v2Pointor]] = op.apply(0, v2Values[v2Pointor]);
v2Pointor++;
}
}
v1.setStorage(newStorage);
}
} else {
throw new AngelException("The operation is not support!");
}
return v1;
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class SimpleBinaryInAllExecutor method apply.
public static Vector apply(IntLongVector v1, IntIntVector v2, Binary op) {
if (v1.isDense() && v2.isDense()) {
long[] resValues = v1.getStorage().getValues();
int[] v2Values = v2.getStorage().getValues();
for (int idx = 0; idx < resValues.length; idx++) {
resValues[idx] = op.apply(resValues[idx], v2Values[idx]);
}
} else if (v1.isDense() && v2.isSparse()) {
long[] resValues = v1.getStorage().getValues();
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
} else if (v1.isDense() && v2.isSorted()) {
long[] resValues = v1.getStorage().getValues();
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
int size = v2.size();
for (int i = 0; i < size; i++) {
int idx = v2Indices[i];
resValues[idx] = op.apply(v1.get(idx), v2Values[i]);
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
} else if (v1.isSparse() && v2.isDense()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
int[] v2Values = v2.getStorage().getValues();
if (v1.size() < Constant.denseLoopThreshold * v1.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(0, v2Values[i]);
}
ObjectIterator<Int2LongMap.Entry> iter = v1.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int idx = entry.getIntKey();
resValues[idx] = op.apply(entry.getLongValue(), v2Values[idx]);
}
} else {
for (int i = 0; i < resValues.length; i++) {
if (v1.getStorage().hasKey(i)) {
resValues[i] = op.apply(v1.get(i), v2Values[i]);
} else {
resValues[i] = op.apply(0, v2Values[i]);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isDense()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
int[] v2Values = v2.getStorage().getValues();
if (v1.size() < Constant.denseLoopThreshold * v1.getDim()) {
int[] v1Indices = v1.getStorage().getIndices();
long[] v1Values = v1.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(0, v2Values[i]);
}
int size = v1.size();
for (int i = 0; i < size; i++) {
int idx = v1Indices[i];
resValues[idx] = op.apply(v1Values[i], v2Values[idx]);
}
} else {
IntLongVectorStorage v1Storage = v1.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v1Storage.hasKey(i)) {
resValues[i] = op.apply(v1.get(i), v2Values[i]);
} else {
resValues[i] = op.apply(0, v2Values[i]);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSparse() && v2.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
ObjectIterator<Int2LongMap.Entry> iter1 = v1.getStorage().entryIterator();
while (iter1.hasNext()) {
Int2LongMap.Entry entry = iter1.next();
int idx = entry.getIntKey();
resValues[idx] = entry.getLongValue();
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSparse() && v2.isSorted()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
ObjectIterator<Int2LongMap.Entry> iter1 = v1.getStorage().entryIterator();
while (iter1.hasNext()) {
Int2LongMap.Entry entry = iter1.next();
int idx = entry.getIntKey();
resValues[idx] = entry.getLongValue();
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
int size = v2.size();
for (int i = 0; i < size; i++) {
int idx = v2Indices[i];
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), v2Values[i]);
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
int[] v1Indices = v1.getStorage().getIndices();
long[] v1Values = v1.getStorage().getValues();
int size = v1.size();
for (int i = 0; i < size; i++) {
int idx = v1Indices[i];
resValues[idx] = v1Values[i];
}
if (v2.size() < Constant.denseLoopThreshold * v2.getDim()) {
for (int i = 0; i < resValues.length; i++) {
resValues[i] = op.apply(resValues[i], 0);
}
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
if (v1.getStorage().hasKey(idx)) {
resValues[idx] = op.apply(v1.get(idx), entry.getIntValue());
}
}
} else {
IntIntVectorStorage v2Storage = v2.getStorage();
for (int i = 0; i < resValues.length; i++) {
if (v2Storage.hasKey(i)) {
resValues[i] = op.apply(resValues[i], v2.get(i));
} else {
resValues[i] = op.apply(resValues[i], 0);
}
}
}
v1.setStorage(newStorage);
}
} else if (v1.isSorted() && v2.isSorted()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntLongVectorStorage newStorage = v1.getStorage().emptyDense();
long[] resValues = newStorage.getValues();
int v1Pointor = 0;
int v2Pointor = 0;
int size1 = v1.size();
int size2 = v2.size();
int[] v1Indices = v1.getStorage().getIndices();
long[] v1Values = v1.getStorage().getValues();
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
if (!op.isCompare()) {
if (size1 != v1.getDim() && size2 != v2.getDim()) {
for (int i = 0; i < v1.getDim(); i++) {
resValues[i] = 0 / 0;
}
}
}
while (v1Pointor < size1 && v2Pointor < size2) {
if (v1Indices[v1Pointor] == v2Indices[v2Pointor]) {
resValues[v1Indices[v1Pointor]] = op.apply(v1Values[v1Pointor], v2Values[v2Pointor]);
v1Pointor++;
v2Pointor++;
} else if (v1Indices[v1Pointor] < v2Indices[v2Pointor]) {
resValues[v1Indices[v1Pointor]] = op.apply(v1Values[v1Pointor], 0);
v1Pointor++;
} else {
// v1Indices[v1Pointor] > v2Indices[v2Pointor]
resValues[v2Indices[v2Pointor]] = op.apply(0, v2Values[v2Pointor]);
v2Pointor++;
}
}
v1.setStorage(newStorage);
}
} else {
throw new AngelException("The operation is not support!");
}
return v1;
}
Aggregations