本文整理汇总了Java中org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator.advance方法的典型用法代码示例。如果您正苦于以下问题:Java Iterator.advance方法的具体用法?Java Iterator.advance怎么用?Java Iterator.advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator
的用法示例。
在下文中一共展示了Iterator.advance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to add two OpenMapRealVectors.
* It copies the larger vector, then iterates over the smaller.
*
* @param v Vector to add.
* @return the sum of {@code this} and {@code v}.
* @throws DimensionMismatchException if the dimensions do not match.
*/
public OpenMapRealVector add(OpenMapRealVector v)
throws DimensionMismatchException {
checkVectorDimensions(v.getDimension());
boolean copyThis = entries.size() > v.entries.size();
OpenMapRealVector res = copyThis ? this.copy() : v.copy();
Iterator iter = copyThis ? v.entries.iterator() : entries.iterator();
OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries;
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (randomAccess.containsKey(key)) {
res.setEntry(key, randomAccess.get(key) + iter.value());
} else {
res.setEntry(key, iter.value());
}
}
return res;
}
示例2: getSubVector
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public OpenMapRealVector getSubVector(int index, int n)
throws NotPositiveException, OutOfRangeException {
checkIndex(index);
if (n < 0) {
throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n);
}
checkIndex(index + n - 1);
OpenMapRealVector res = new OpenMapRealVector(n);
int end = index + n;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (key >= index && key < end) {
res.setEntry(key - index, iter.value());
}
}
return res;
}
示例3: isInfinite
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean isInfinite() {
boolean infiniteFound = false;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
final double value = iter.value();
if (Double.isNaN(value)) {
return false;
}
if (Double.isInfinite(value)) {
infiniteFound = true;
}
}
return infiniteFound;
}
示例4: subtract
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to subtract OpenMapRealVectors.
*
* @param v Vector to subtract from {@code this}.
* @return the difference of {@code this} and {@code v}.
* @throws DimensionMismatchException if the dimensions do not match.
*/
public OpenMapRealVector subtract(OpenMapRealVector v)
throws DimensionMismatchException {
checkVectorDimensions(v.getDimension());
OpenMapRealVector res = copy();
Iterator iter = v.getEntries().iterator();
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (entries.containsKey(key)) {
res.setEntry(key, entries.get(key) - iter.value());
} else {
res.setEntry(key, -iter.value());
}
}
return res;
}
示例5: hashCode
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* Implementation Note: This works on exact values, and as a result
* it is possible for {@code a.subtract(b)} to be the zero vector, while
* {@code a.hashCode() != b.hashCode()}.
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(epsilon);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + virtualSize;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
temp = Double.doubleToLongBits(iter.value());
result = prime * result + (int) (temp ^ (temp >>32));
}
return result;
}
示例6: add
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to add two OpenMapRealVectors.
* It copies the larger vector, then iterates over the smaller.
*
* @param v Vector to add.
* @return the sum of {@code this} and {@code v}.
* @throws org.apache.commons.math3.exception.DimensionMismatchException
* if the dimensions do not match.
*/
public OpenMapRealVector add(OpenMapRealVector v) {
checkVectorDimensions(v.getDimension());
boolean copyThis = entries.size() > v.entries.size();
OpenMapRealVector res = copyThis ? this.copy() : v.copy();
Iterator iter = copyThis ? v.entries.iterator() : entries.iterator();
OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries;
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (randomAccess.containsKey(key)) {
res.setEntry(key, randomAccess.get(key) + iter.value());
} else {
res.setEntry(key, iter.value());
}
}
return res;
}
示例7: getSubVector
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public OpenMapRealVector getSubVector(int index, int n) {
checkIndex(index);
checkIndex(index + n - 1);
OpenMapRealVector res = new OpenMapRealVector(n);
int end = index + n;
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (key >= index && key < end) {
res.setEntry(key - index, iter.value());
}
}
return res;
}
示例8: subtract
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to subtract OpenMapRealVectors.
*
* @param v Vector to subtract from {@code this}.
* @return the difference of {@code this} and {@code v}.
* @throws org.apache.commons.math3.exception.DimensionMismatchException
* if the dimensions do not match.
*/
public OpenMapRealVector subtract(OpenMapRealVector v) {
checkVectorDimensions(v.getDimension());
OpenMapRealVector res = copy();
Iterator iter = v.getEntries().iterator();
while (iter.hasNext()) {
iter.advance();
int key = iter.key();
if (entries.containsKey(key)) {
res.setEntry(key, entries.get(key) - iter.value());
} else {
res.setEntry(key, -iter.value());
}
}
return res;
}
示例9: append
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to append a OpenMapRealVector.
* @param v vector to append
* @return The result of appending {@code v} to self
*/
public OpenMapRealVector append(OpenMapRealVector v) {
OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension());
Iterator iter = v.entries.iterator();
while (iter.hasNext()) {
iter.advance();
res.setEntry(iter.key() + virtualSize, iter.value());
}
return res;
}
示例10: toArray
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double[] toArray() {
double[] res = new double[virtualSize];
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
res[iter.key()] = iter.value();
}
return res;
}
示例11: isNaN
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean isNaN() {
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
if (Double.isNaN(iter.value())) {
return true;
}
}
return false;
}
示例12: unitize
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void unitize() throws MathArithmeticException {
double norm = getNorm();
if (isDefaultValue(norm)) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
entries.put(iter.key(), iter.value() / norm);
}
}
示例13: dotProduct
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/**
* Optimized method to compute the dot product with an OpenMapRealVector.
* It iterates over the smallest of the two.
*
* @param v Cector to compute the dot product with.
* @return the dot product of {@code this} and {@code v}.
* @throws org.apache.commons.math3.exception.DimensionMismatchException
* if the dimensions do not match.
*/
public double dotProduct(OpenMapRealVector v) {
checkVectorDimensions(v.getDimension());
boolean thisIsSmaller = entries.size() < v.entries.size();
Iterator iter = thisIsSmaller ? entries.iterator() : v.entries.iterator();
OpenIntToDoubleHashMap larger = thisIsSmaller ? v.entries : entries;
double d = 0;
while(iter.hasNext()) {
iter.advance();
d += iter.value() * larger.get(iter.key());
}
return d;
}
示例14: ebeMultiply
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public OpenMapRealVector ebeMultiply(RealVector v) {
checkVectorDimensions(v.getDimension());
OpenMapRealVector res = new OpenMapRealVector(this);
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
}
return res;
}
示例15: unitize
import org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void unitize() {
double norm = getNorm();
if (isDefaultValue(norm)) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
entries.put(iter.key(), iter.value() / norm);
}
}