use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class CooIntFloatMatrix method getCol.
@Override
public Vector getCol(int idx) {
IntArrayList cols = new IntArrayList();
FloatArrayList data = new FloatArrayList();
for (int i = 0; i < colIndices.length; i++) {
if (colIndices[i] == idx) {
cols.add(rowIndices[i]);
data.add(values[i]);
}
}
IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(shape[0], cols.toIntArray(), data.toFloatArray());
return new IntFloatVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector 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.IntFloatVector in project angel by Tencent.
the class BlasFloatMatrix method getCol.
@Override
public Vector getCol(int j) {
float[] col = new float[numRows];
for (int i = 0; i < numRows; i++) {
col[i] = data[i * numCols + j];
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(col);
return new IntFloatVector(getMatrixId(), 0, getClock(), numRows, storage);
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class BlasFloatMatrix method diag.
@Override
public Vector diag() {
int numDiag = Math.min(numRows, numCols);
float[] resArr = new float[numDiag];
for (int i = 0; i < numDiag; i++) {
resArr[i] = data[i * numRows + i];
}
IntFloatDenseVectorStorage storage = new IntFloatDenseVectorStorage(resArr);
return new IntFloatVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.
the class RBCompIntFloatMatrix method initEmpty.
@Override
public void initEmpty(int idx) {
int numComp = (int) ((getDim() + subDim - 1) / subDim);
if (null == rows[idx]) {
IntFloatVector[] tmpParts = new IntFloatVector[numComp];
for (int i = 0; i < numComp; i++) {
IntFloatSparseVectorStorage storage = new IntFloatSparseVectorStorage(subDim);
tmpParts[i] = new IntFloatVector(matrixId, idx, clock, (int) getDim(), storage);
}
CompIntFloatVector tmpVect = new CompIntFloatVector(matrixId, idx, clock, (int) getDim(), tmpParts, subDim);
rows[idx] = tmpVect;
}
}
Aggregations