use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.
the class CompIntDoubleRowUpdateSplit method serialize.
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
IntDoubleVectorStorage storage = split.getStorage();
if (storage instanceof IntDoubleSparseVectorStorage) {
buf.writeInt(storage.size());
ObjectIterator<Int2DoubleMap.Entry> iter = storage.entryIterator();
Int2DoubleMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeDouble(entry.getDoubleValue());
}
} else if (storage instanceof IntDoubleSortedVectorStorage) {
buf.writeInt(storage.size());
int[] indices = storage.getIndices();
double[] values = storage.getValues();
for (int i = 0; i < indices.length; i++) {
buf.writeInt(indices[i]);
buf.writeDouble(values[i]);
}
} else if (storage instanceof IntDoubleDenseVectorStorage) {
double[] values = storage.getValues();
int writeSize = values.length < maxItemNum ? values.length : maxItemNum;
buf.writeInt(writeSize);
for (int i = 0; i < writeSize; i++) {
buf.writeDouble(values[i]);
}
} else {
throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
}
}
use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.
the class BlasDoubleMatrix method getRow.
@Override
public Vector getRow(int i) {
double[] row = new double[numCols];
System.arraycopy(data, i * numCols, row, 0, numCols);
IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(row);
return new IntDoubleVector(getMatrixId(), i, getClock(), numCols, storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.
the class BlasDoubleMatrix method getCol.
@Override
public Vector getCol(int j) {
double[] col = new double[numRows];
for (int i = 0; i < numRows; i++) {
col[i] = data[i * numCols + j];
}
IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(col);
return new IntDoubleVector(getMatrixId(), 0, getClock(), numRows, storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.
the class BlasDoubleMatrix method diag.
@Override
public Vector diag() {
int numDiag = Math.min(numRows, numCols);
double[] resArr = new double[numDiag];
for (int i = 0; i < numDiag; i++) {
resArr[i] = data[i * numRows + i];
}
IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
return new IntDoubleVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.
the class DotMatrixExecutor method apply.
private static Vector apply(BlasDoubleMatrix mat, boolean trans, IntIntVector v) {
int m = mat.getNumRows(), n = mat.getNumCols();
double[] resArr;
if (trans) {
assert m == v.getDim();
resArr = new double[n];
} else {
assert n == v.getDim();
resArr = new double[m];
}
int r = mat.getNumRows(), c = mat.getNumCols();
double[] data = mat.getData();
if (v.isDense()) {
double[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new double[v.getDim()]);
if (trans) {
blas.dgemv("N", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
} else {
blas.dgemv("T", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
}
} else if (v.isSparse()) {
if (trans) {
for (int j = 0; j < c; j++) {
ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int i = entry.getIntKey();
resArr[j] += data[i * c + j] * entry.getIntValue();
}
}
} else {
for (int i = 0; i < r; i++) {
ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int j = entry.getIntKey();
resArr[i] += data[i * c + j] * entry.getIntValue();
}
}
}
} else {
// sorted
if (trans) {
for (int j = 0; j < r; j++) {
int[] idxs = v.getStorage().getIndices();
int[] 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();
int[] vals = v.getStorage().getValues();
for (int k = 0; k < idxs.length; k++) {
resArr[i] += data[i * c + idxs[k]] * vals[k];
}
}
}
}
IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
return new IntDoubleVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Aggregations