use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RBLongFloatMatrix method dot.
@Override
public Vector dot(Vector other) {
float[] resArr = new float[rows.length];
for (int i = 0; i < rows.length; i++) {
resArr[i] = (float) rows[i].dot(other);
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(matrixId, 0, clock, rows.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class BlasFloatMatrix method getRow.
@Override
public Vector getRow(int i) {
float[] row = new float[numCols];
System.arraycopy(data, i * numCols, row, 0, numCols);
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(row);
return new IntFloatVector(getMatrixId(), i, getClock(), numCols, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RBCompIntFloatMatrix method dot.
@Override
public Vector dot(Vector other) {
float[] resArr = new float[rows.length];
for (int i = 0; i < rows.length; i++) {
resArr[i] = (float) rows[i].dot(other);
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(matrixId, 0, clock, rows.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class RBCompLongFloatMatrix method dot.
@Override
public Vector dot(Vector other) {
float[] resArr = new float[rows.length];
for (int i = 0; i < rows.length; i++) {
resArr[i] = (float) rows[i].dot(other);
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(matrixId, 0, clock, rows.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage in project angel by Tencent.
the class DotMatrixExecutor method apply.
private static Vector apply(BlasFloatMatrix mat, boolean trans, IntLongVector v) {
int m = mat.getNumRows(), n = mat.getNumCols();
float[] resArr;
if (trans) {
assert m == v.getDim();
resArr = new float[n];
} else {
assert n == v.getDim();
resArr = new float[m];
}
int r = mat.getNumRows(), c = mat.getNumCols();
float[] data = mat.getData();
if (v.isDense()) {
float[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new float[v.getDim()]);
if (trans) {
blas.sgemv("N", c, r, 1.0f, data, c, tempArray, 1, 0.0f, resArr, 1);
} else {
blas.sgemv("T", c, r, 1.0f, data, c, tempArray, 1, 0.0f, resArr, 1);
}
} else if (v.isSparse()) {
if (trans) {
for (int j = 0; j < c; j++) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int i = entry.getIntKey();
resArr[j] += data[i * c + j] * entry.getLongValue();
}
}
} else {
for (int i = 0; i < r; i++) {
ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int j = entry.getIntKey();
resArr[i] += data[i * c + j] * entry.getLongValue();
}
}
}
} else {
// sorted
if (trans) {
for (int j = 0; j < r; j++) {
int[] idxs = v.getStorage().getIndices();
long[] vals = v.getStorage().getValues();
for (int k = 0; k < idxs.length; k++) {
resArr[j] += data[idxs[k] * c + j] * vals[k];
}
}
} else {
for (int i = 0; i < r; i++) {
int[] idxs = v.getStorage().getIndices();
long[] vals = v.getStorage().getValues();
for (int k = 0; k < idxs.length; k++) {
resArr[i] += data[i * c + idxs[k]] * vals[k];
}
}
}
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Aggregations