use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class IntIntVector method argmin.
public int argmin() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int minval = Integer.MAX_VALUE;
int minidx = -1;
if (idstorage.isDense()) {
int[] 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<Int2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
int val = entry.getIntValue();
if (val < minval) {
minval = val;
minidx = 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] < minval) {
minval = val[i];
minidx = idx;
}
}
}
return minidx;
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class IntLongVector method argmax.
public int argmax() {
IntLongVectorStorage idstorage = (IntLongVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
long maxval = Long.MIN_VALUE;
int maxidx = -1;
if (idstorage.isDense()) {
long[] 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<Int2LongMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int idx = entry.getIntKey();
long val = entry.getLongValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
long[] 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;
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class SnapshotFormat method save.
private void save(ServerLongLongRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
long startCol = meta.getStartCol();
if (ServerRowUtils.getVector(row) instanceof IntLongVector) {
IntLongVector vector = (IntLongVector) ServerRowUtils.getVector(row);
if (vector.isDense()) {
long[] data = vector.getStorage().getValues();
for (int i = 0; i < data.length; i++) {
out.writeLong(data[i]);
}
} else if (vector.isSorted()) {
int[] indices = vector.getStorage().getIndices();
long[] values = vector.getStorage().getValues();
for (int i = 0; i < indices.length; i++) {
out.writeLong(indices[i] + startCol);
out.writeLong(values[i]);
}
} else {
ObjectIterator<Int2LongMap.Entry> iter = vector.getStorage().entryIterator();
Int2LongMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
out.writeLong(entry.getIntKey() + startCol);
out.writeLong(entry.getLongValue());
}
}
} else {
LongLongVector vector = (LongLongVector) ServerRowUtils.getVector(row);
if (vector.isSorted()) {
long[] indices = vector.getStorage().getIndices();
long[] values = vector.getStorage().getValues();
for (int i = 0; i < indices.length; i++) {
out.writeLong(indices[i] + startCol);
out.writeLong(values[i]);
}
} else {
ObjectIterator<Long2LongMap.Entry> iter = vector.getStorage().entryIterator();
Long2LongMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
out.writeLong(entry.getLongKey() + startCol);
out.writeLong(entry.getLongValue());
}
}
}
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class SnapshotFormat method save.
private void save(ServerIntFloatRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
int startCol = (int) meta.getStartCol();
IntFloatVector vector = ServerRowUtils.getVector(row);
if (vector.isDense()) {
float[] data = vector.getStorage().getValues();
for (int i = 0; i < data.length; i++) {
out.writeFloat(data[i]);
}
} else if (vector.isSorted()) {
int[] indices = vector.getStorage().getIndices();
float[] values = vector.getStorage().getValues();
for (int i = 0; i < indices.length; i++) {
out.writeInt(indices[i] + startCol);
out.writeFloat(values[i]);
}
} else {
ObjectIterator<Int2FloatMap.Entry> iter = vector.getStorage().entryIterator();
Int2FloatMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
out.writeInt(entry.getIntKey() + startCol);
out.writeFloat(entry.getFloatValue());
}
}
}
use of it.unimi.dsi.fastutil.objects.ObjectIterator in project angel by Tencent.
the class ComplexRowFormat method save.
private void save(ServerIntAnyRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta partMeta, DataOutputStream output) throws IOException {
IntElementStorage storage = row.getStorage();
long startPos = partMeta.getStartCol();
if (storage instanceof IntArrayElementStorage) {
IElement[] data = ((IntArrayElementStorage) storage).getData();
for (int i = 0; i < data.length; i++) {
save(i + startPos, data[i], output);
}
} else if (storage instanceof IntElementMapStorage) {
Int2ObjectOpenHashMap<IElement> data = ((IntElementMapStorage) storage).getData();
ObjectIterator<Int2ObjectMap.Entry<IElement>> iter = data.int2ObjectEntrySet().fastIterator();
while (iter.hasNext()) {
Int2ObjectMap.Entry<IElement> entry = iter.next();
save(entry.getIntKey() + startPos, entry.getValue(), output);
}
}
}
Aggregations