当前位置: 首页>>代码示例>>Java>>正文


Java Int2DoubleMap.Entry方法代码示例

本文整理汇总了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();
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:18,代码来源:ServerSparseDoubleRow.java

示例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();
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:33,代码来源:ServerSparseDoubleRow.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:23,代码来源:SparseDoubleVector.java

示例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;
    }
}
 
开发者ID:jmccrae,项目名称:naisc,代码行数:25,代码来源:Vectors.java

示例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);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:17,代码来源:SparseFloatVector.java

示例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());
}
 
开发者ID:gdfm,项目名称:sssj,代码行数:24,代码来源:VectorTest.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:10,代码来源:DenseFloatVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:12,代码来源:DenseFloatVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:10,代码来源:DenseFloatVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:11,代码来源:CompDoubleVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:9,代码来源:SparseDoubleVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:12,代码来源:CompDoubleVector.java

示例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());
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:14,代码来源:CompSparseDoubleRowUpdateSplit.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:13,代码来源:SparseDoubleVector.java

示例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;
}
 
开发者ID:Tencent,项目名称:angel,代码行数:10,代码来源:DenseDoubleVector.java


注:本文中的it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。