use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasDoubleMatrix mat, IntFloatVector v, int idx, boolean onCol, Binary op) {
double[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = null;
if (!v.isDense()) {
flag = new byte[v.getDim()];
}
if (onCol && op.isInplace()) {
if (v.isDense()) {
float[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
data[i * n + idx] = op.apply(data[i * n + idx], values[i]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
data[i * n + idx] = op.apply(data[i * n + idx], entry.getFloatValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
float[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
data[i * n + idx] = op.apply(data[i * n + idx], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = 0;
}
}
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = op.apply(data[i * n + idx], 0);
}
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
float[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
newData[i * n + idx] = op.apply(data[i * n + idx], values[i]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
newData[i * n + idx] = op.apply(data[i * n + idx], entry.getFloatValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
float[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
newData[i * n + idx] = op.apply(data[i * n + idx], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
newData[i * n + idx] = op.apply(data[i * n + idx], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
if (v.isDense()) {
float[] values = v.getStorage().getValues();
for (int j = 0; j < n; j++) {
data[idx * n + j] = op.apply(data[idx * n + j], values[j]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int j = entry.getIntKey();
flag[j] = 1;
data[idx * n + j] = op.apply(data[idx * n + j], entry.getFloatValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
float[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
data[idx * n + j] = op.apply(data[idx * n + j], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = 0;
}
}
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = op.apply(data[idx * n + j], 0);
}
}
}
}
return mat;
} else {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
float[] values = v.getStorage().getValues();
for (int j = 0; j < n; j++) {
newData[idx * n + j] = op.apply(data[idx * n + j], values[j]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int j = entry.getIntKey();
flag[j] = 1;
newData[idx * n + j] = op.apply(data[idx * n + j], entry.getFloatValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
float[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
newData[idx * n + j] = op.apply(data[idx * n + j], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
newData[idx * n + j] = op.apply(data[idx * n + j], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasFloatMatrix mat, IntLongVector v, boolean onCol, Binary op) {
float[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = null;
if (!v.isDense()) {
flag = new byte[v.getDim()];
}
if (onCol && op.isInplace()) {
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
long value = values[i];
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
float value = entry.getLongValue();
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
long value = values[k];
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], value);
}
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = 0;
}
}
}
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
float[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new float[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
long value = values[i];
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
float value = entry.getLongValue();
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
long value = values[k];
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
}
return new BlasFloatMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], values[j]);
}
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
float value = entry.getLongValue();
flag[j] = 1;
for (int i = 0; i < m; i++) {
data[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
long value = values[k];
flag[j] = 1;
for (int i = 0; i < m; i++) {
data[i * n + j] = op.apply(data[i * n + j], value);
}
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = 0;
}
}
}
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
}
return mat;
} else {
float[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new float[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int j = 0; j < n; j++) {
long value = values[j];
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
flag[j] = 1;
float value = entry.getLongValue();
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
long value = values[k];
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(data[i * n + j], value);
}
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
}
return new BlasFloatMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasDoubleMatrix mat, IntLongVector v, int idx, boolean onCol, Binary op) {
double[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = null;
if (!v.isDense()) {
flag = new byte[v.getDim()];
}
if (onCol && op.isInplace()) {
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
data[i * n + idx] = op.apply(data[i * n + idx], values[i]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
data[i * n + idx] = op.apply(data[i * n + idx], entry.getLongValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
data[i * n + idx] = op.apply(data[i * n + idx], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = 0;
}
}
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = op.apply(data[i * n + idx], 0);
}
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int i = 0; i < m; i++) {
newData[i * n + idx] = op.apply(data[i * n + idx], values[i]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int i = entry.getIntKey();
flag[i] = 1;
newData[i * n + idx] = op.apply(data[i * n + idx], entry.getLongValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
newData[i * n + idx] = op.apply(data[i * n + idx], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
newData[i * n + idx] = op.apply(data[i * n + idx], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int j = 0; j < n; j++) {
data[idx * n + j] = op.apply(data[idx * n + j], values[j]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
flag[j] = 1;
data[idx * n + j] = op.apply(data[idx * n + j], entry.getLongValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
data[idx * n + j] = op.apply(data[idx * n + j], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = 0;
}
}
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = op.apply(data[idx * n + j], 0);
}
}
}
}
return mat;
} else {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
if (v.isDense()) {
long[] values = v.getStorage().getValues();
for (int j = 0; j < n; j++) {
newData[idx * n + j] = op.apply(data[idx * n + j], values[j]);
}
} else if (v.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
flag[j] = 1;
newData[idx * n + j] = op.apply(data[idx * n + j], entry.getLongValue());
}
} else {
// sorted
int[] idxs = v.getStorage().getIndices();
long[] values = v.getStorage().getValues();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
newData[idx * n + j] = op.apply(data[idx * n + j], values[k]);
}
}
if (!v.isDense()) {
switch(op.getOpType()) {
case INTERSECTION:
break;
case UNION:
break;
case ALL:
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
newData[idx * n + j] = op.apply(data[idx * n + j], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class IntFloatVector method argmin.
public int argmin() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
float minval = Float.MAX_VALUE;
int minidx = -1;
if (idstorage.isDense()) {
float[] val = idstorage.getValues();
int length = val.length;
for (int idx = 0; idx < length; idx++) {
if (val[idx] < minval) {
minval = val[idx];
minidx = idx;
}
}
} else if (idstorage.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = entry.getIntKey();
float val = entry.getFloatValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
float[] val = idstorage.getValues();
int size = idstorage.size();
for (int i = 0; i < size; i++) {
int idx = indices[i];
if (val[i] < minval) {
minval = val[i];
minidx = idx;
}
}
}
return minidx;
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class IntIntVector method argmax.
public int argmax() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int maxval = Integer.MIN_VALUE;
int maxidx = -1;
if (idstorage.isDense()) {
int[] val = idstorage.getValues();
int length = val.length;
for (int idx = 0; idx < length; idx++) {
if (val[idx] > maxval) {
maxval = val[idx];
maxidx = idx;
}
}
} else if (idstorage.isSparse()) {
ObjectIterator<Int2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
int val = entry.getIntValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
int[] val = idstorage.getValues();
int size = idstorage.size();
for (int i = 0; i < size; i++) {
int idx = indices[i];
if (val[i] > maxval) {
maxval = val[i];
maxidx = idx;
}
}
}
return maxidx;
}
Aggregations