use of com.tencent.angel.ml.math2.vector.IntFloatVector 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.vector.IntFloatVector in project angel by Tencent.
the class BlasFloatMatrix method setRow.
public Matrix setRow(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[numCols];
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[numCols];
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];
}
}
System.arraycopy(rowData, 0, data, i * numCols, numCols);
} else if (v instanceof IntLongVector) {
long[] rowData;
if (v.isDense()) {
rowData = ((IntLongVector) v).getStorage().getValues();
} else if (v.isSparse()) {
rowData = new long[numCols];
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[numCols];
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 < numCols; j++) {
data[i * numCols + j] = rowData[j];
}
} else if (v instanceof IntIntVector) {
int[] rowData;
if (v.isDense()) {
rowData = ((IntIntVector) v).getStorage().getValues();
} else if (v.isSparse()) {
rowData = new int[numCols];
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[numCols];
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 < numCols; j++) {
data[i * numCols + j] = rowData[j];
}
} else if (v instanceof IntDummyVector) {
int[] rowData = new int[numCols];
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 < numCols; j++) {
data[i * numCols + j] = rowData[j];
}
} else {
throw new AngelException("The operation is not supported!");
}
return this;
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector 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.vector.IntFloatVector 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.vector.IntFloatVector in project angel by Tencent.
the class MixedDotExecutor method apply.
private static double apply(CompIntFloatVector v1, IntIntVector v2) {
double dotValue = 0.0;
if (v2.isDense()) {
int base = 0;
int[] v2Values = v2.getStorage().getValues();
for (IntFloatVector part : v1.getPartitions()) {
if (part.isDense()) {
float[] partValues = part.getStorage().getValues();
for (int i = 0; i < partValues.length; i++) {
int idx = base + i;
dotValue += partValues[i] * v2Values[idx];
}
} else if (part.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = part.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = base + entry.getIntKey();
dotValue += entry.getFloatValue() * v2Values[idx];
}
} else {
// isSorted
int[] partIndices = part.getStorage().getIndices();
float[] partValues = part.getStorage().getValues();
for (int i = 0; i < partIndices.length; i++) {
int idx = base + partIndices[i];
dotValue += partValues[i] * v2Values[idx];
}
}
base += part.getDim();
}
} else if (v2.isSparse()) {
ObjectIterator<Int2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
dotValue += v1.get(idx) * entry.getIntValue();
}
} else if (v2.isSorted() && v1.size() > v2.size()) {
// v2 is sorted
int[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < v2Indices.length; i++) {
int idx = v2Indices[i];
dotValue += v1.get(idx) * v2Values[i];
}
} else {
int base = 0;
for (IntFloatVector part : v1.getPartitions()) {
if (part.isDense()) {
float[] partValues = part.getStorage().getValues();
for (int i = 0; i < partValues.length; i++) {
int idx = base + i;
dotValue += partValues[i] * v2.get(idx);
}
} else if (part.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = part.getStorage().entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = base + entry.getIntKey();
dotValue += entry.getFloatValue() * v2.get(idx);
}
} else {
// isSorted
int[] partIndices = part.getStorage().getIndices();
float[] partValues = part.getStorage().getValues();
for (int i = 0; i < partIndices.length; i++) {
int idx = base + partIndices[i];
dotValue += partValues[i] * v2.get(idx);
}
}
base += part.getDim();
}
}
return dotValue;
}
Aggregations