本文整理汇总了Java中it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry方法的典型用法代码示例。如果您正苦于以下问题:Java Int2DoubleMap.Entry方法的具体用法?Java Int2DoubleMap.Entry怎么用?Java Int2DoubleMap.Entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.ints.Int2DoubleMap
的用法示例。
在下文中一共展示了Int2DoubleMap.Entry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Override public void serialize(ByteBuf buf) {
try {
lock.readLock().lock();
super.serialize(buf);
buf.writeInt(hashMap.size());
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeDouble(entry.getDoubleValue());
}
} finally {
lock.readLock().unlock();
}
}
示例2: mergeTo
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
/**
* Merge this sparse double vector split to a index/value array
* @param indexes index array
* @param values value array
* @param startPos write start position of the index/value array
* @param len write length
*/
public void mergeTo(int[] indexes, double[] values, int startPos, int len) {
try {
lock.readLock().lock();
int writeLen = len < hashMap.size() ? len : hashMap.size();
if (writeLen == 0) {
return;
}
int index = 0;
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
indexes[startPos + index] = entry.getIntKey();
values[startPos + index] = entry.getDoubleValue();
index++;
if (index == writeLen) {
return;
}
}
} finally {
lock.readLock().unlock();
}
}
示例3: dot
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private double dot(SparseDoubleVector other) {
double ret = 0.0;
Int2DoubleOpenHashMap smallMap = this.hashMap;
Int2DoubleOpenHashMap largeMap = other.hashMap;
if (smallMap.size() > largeMap.size()) {
smallMap = other.hashMap;
largeMap = this.hashMap;
}
ObjectIterator<Int2DoubleMap.Entry> iter = smallMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
if (largeMap.containsKey(entry.getIntKey())) {
ret += entry.getDoubleValue() * largeMap.get(entry.getIntKey());
}
}
return ret;
}
示例4: cosine
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
/**
* Calculate the cosine of two vectors
* @param _v1 Vector 1
* @param _v2 Vector 2
* @return Sum(x*y)/(norm(x)*norm(y))
*/
public static double cosine(Vector _v1, Vector _v2) {
final Vector v1 = _v1.size() < _v2.size() ? _v1 : _v2;
final Vector v2 = _v1.size() < _v2.size() ? _v2 : _v1;
if(v1.len() != v2.len()) throw new LinearAlgebraException(String.format("Vector lengths do not match %d <-> %d", v1.len(), v2.len()));
double aa = 0, ab = 0;
for(Int2DoubleMap.Entry s : v1.sparseEntrySet()) {
aa += s.getDoubleValue()*s.getDoubleValue();
ab += s.getDoubleValue()*v2.getDouble(s.getIntKey());
}
final double bnorm = v2.norm();
if(aa == 0 && bnorm == 0) {
return 0.0;
} else {
return ab / Math.sqrt(aa) / bnorm;
}
}
示例5: newNumberVector
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Override
public SparseFloatVector newNumberVector(Int2DoubleOpenHashMap dvalues, int maxdim) {
int[] indexes = new int[dvalues.size()];
float[] values = new float[dvalues.size()];
// Import and sort the indexes
ObjectIterator<Int2DoubleMap.Entry> iter = dvalues.int2DoubleEntrySet().fastIterator();
for(int i = 0; iter.hasNext(); i++) {
indexes[i] = iter.next().getIntKey();
}
Arrays.sort(indexes);
// Import the values accordingly
for(int i = 0; i < dvalues.size(); i++) {
values[i] = (float) dvalues.get(indexes[i]);
}
return new SparseFloatVector(indexes, values, maxdim);
}
示例6: testIterationOrder
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Test
public void testIterationOrder() {
Vector v = new Vector();
v.put(0, 0);
v.put(1, 1);
v.put(2, 2);
v.put(3, 3);
v.put(4, 4);
BidirectionalIterator<Int2DoubleMap.Entry> it = v.int2DoubleEntrySet().fastIterator(v.int2DoubleEntrySet().last());
// for (int i = 0; i < v.size(); i++) {
int i = 4;
while (it.hasPrevious()) {
Entry e = it.previous();
int lastKey = e.getIntKey();
double lastValue = e.getDoubleValue();
assertEquals(i, lastKey);
assertEquals(i, lastValue, Double.MIN_NORMAL);
i--;
}
assertEquals(5, v.size());
assertEquals(0, v.int2DoubleEntrySet().first().getIntKey());
assertEquals(4, v.int2DoubleEntrySet().last().getIntKey());
}
示例7: dot
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private double dot(SparseDoubleVector other) {
double ret = 0.0;
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
ret += values[entry.getIntKey()] * entry.getDoubleValue();
}
return ret;
}
示例8: plus
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private TVector plus(SparseDoubleVector other) {
DenseFloatVector vector = new DenseFloatVector(dim);
System.arraycopy(values, 0, vector.values, 0, dim);
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
vector.values[entry.getIntKey()] += (float) entry.getDoubleValue();
}
return vector;
}
示例9: plusBy
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private TFloatVector plusBy(SparseDoubleVector other) {
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
values[entry.getIntKey()] += (float) entry.getDoubleValue();
}
return this;
}
示例10: plusBy
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private TVector plusBy(SparseDoubleVector other) {
ObjectIterator<Int2DoubleMap.Entry>
iter = other.hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while(iter.hasNext()) {
entry = iter.next();
plusBy(entry.getIntKey(), entry.getDoubleValue());
}
return this;
}
示例11: norm
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Override public double norm() {
ObjectIterator<Int2DoubleMap.Entry> iter = hashMap.int2DoubleEntrySet().iterator();
double sum = 0;
while (iter.hasNext()) {
sum += Math.abs(iter.next().getDoubleValue());
}
return sum;
}
示例12: dot
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private double dot(SparseDoubleVector other) {
double dotValue = 0.0;
ObjectIterator<Int2DoubleMap.Entry>
iter = other.hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while(iter.hasNext()) {
entry = iter.next();
dotValue += entry.getDoubleValue() * get(entry.getIntKey());
}
return dotValue;
}
示例13: serialize
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Override public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeInt(split.size());
ObjectIterator<Int2DoubleMap.Entry> iter =
split.getIndexToValueMap().int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
buf.writeInt(entry.getIntKey());
buf.writeDouble(entry.getDoubleValue());
}
}
示例14: times
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
@Override
public TIntDoubleVector times(double x) {
SparseDoubleVector vector = (SparseDoubleVector) this.clone();
ObjectIterator<Int2DoubleMap.Entry> iter = vector.hashMap.int2DoubleEntrySet().fastIterator();
Int2DoubleMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
vector.hashMap.put(entry.getIntKey(), entry.getDoubleValue() * x);
}
return vector;
}
示例15: plusBy
import it.unimi.dsi.fastutil.ints.Int2DoubleMap; //导入方法依赖的package包/类
private TIntDoubleVector plusBy(SparseDoubleVector other, double x) {
ObjectIterator<Int2DoubleMap.Entry> iter = other.hashMap.int2DoubleEntrySet().fastIterator();
while (iter.hasNext()) {
Int2DoubleMap.Entry entry = iter.next();
values[entry.getIntKey()] += entry.getDoubleValue() * x;
}
return this;
}