本文整理汇总了Java中org.apache.commons.math3.util.OpenIntToDoubleHashMap.Iterator方法的典型用法代码示例。如果您正苦于以下问题:Java OpenIntToDoubleHashMap.Iterator方法的具体用法?Java OpenIntToDoubleHashMap.Iterator怎么用?Java OpenIntToDoubleHashMap.Iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.OpenIntToDoubleHashMap
的用法示例。
在下文中一共展示了OpenIntToDoubleHashMap.Iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* Compute the sum of this matrix and {@code m}.
*
* @param m Matrix to be added.
* @return {@code this} + {@code m}.
* @throws MatrixDimensionMismatchException if {@code m} is not the same
* size as {@code this}.
*/
public OpenMapRealMatrix add(OpenMapRealMatrix m)
throws MatrixDimensionMismatchException {
MatrixUtils.checkAdditionCompatible(this, m);
final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance();
final int row = iterator.key() / columns;
final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) + iterator.value());
}
return out;
}
示例2: multiply
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @throws NumberIsTooLargeException if {@code m} is an
* {@code OpenMapRealMatrix}, and the total number of entries of the product
* is larger than {@code Integer.MAX_VALUE}.
*/
@Override
public RealMatrix multiply(final RealMatrix m)
throws DimensionMismatchException, NumberIsTooLargeException {
try {
return multiply((OpenMapRealMatrix) m);
} catch (ClassCastException cce) {
MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension();
final BlockRealMatrix out = new BlockRealMatrix(rows, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance();
final double value = iterator.value();
final int key = iterator.key();
final int i = key / columns;
final int k = key % columns;
for (int j = 0; j < outCols; ++j) {
out.addToEntry(i, j, value * m.getEntry(k, j));
}
}
return out;
}
}
示例3: add
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* Compute the sum of this matrix and {@code m}.
*
* @param m Matrix to be added.
* @return {@code this} + {@code m}.
* @throws org.apache.commons.math3.exception.DimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public OpenMapRealMatrix add(OpenMapRealMatrix m) {
// safety check
MatrixUtils.checkAdditionCompatible(this, m);
final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance();
final int row = iterator.key() / columns;
final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) + iterator.value());
}
return out;
}
示例4: multiply
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public RealMatrix multiply(final RealMatrix m) {
try {
return multiply((OpenMapRealMatrix) m);
} catch (ClassCastException cce) {
// safety check
MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension();
final BlockRealMatrix out = new BlockRealMatrix(rows, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance();
final double value = iterator.value();
final int key = iterator.key();
final int i = key / columns;
final int k = key % columns;
for (int j = 0; j < outCols; ++j) {
out.addToEntry(i, j, value * m.getEntry(k, j));
}
}
return out;
}
}
示例5: updateTile
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/** Update the tile according to the Digital Elevation Model.
* @param tile to update
* @exception RuggedException if tile cannot be updated
*/
public void updateTile(final UpdatableTile tile)
throws RuggedException {
tile.setGeometry(minLatitude, minLongitude,
latitudeStep, longitudeStep,
latitudeRows, longitudeColumns);
final OpenIntToDoubleHashMap.Iterator iterator = elevations.iterator();
while (iterator.hasNext()) {
iterator.advance();
final int index = iterator.key();
final int latitudeIndex = index / longitudeColumns;
final int longitudeIndex = index % longitudeColumns;
final double elevation = iterator.value();
tile.setElevation(latitudeIndex, longitudeIndex, elevation);
}
}
示例6: add
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的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) {
checkVectorDimensions(v.getDimension());
boolean copyThis = entries.size() > v.entries.size();
OpenMapRealVector res = copyThis ? this.copy() : v.copy();
OpenIntToDoubleHashMap.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; //导入方法依赖的package包/类
@Override
public OpenMapRealVector getSubVector(int index, int n) {
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;
OpenIntToDoubleHashMap.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: isInfinite
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
@Override
public boolean isInfinite() {
boolean infiniteFound = false;
OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
double value = iter.value();
if (Double.isNaN(value)) {
return false;
}
if (Double.isInfinite(value)) {
infiniteFound = true;
}
}
return infiniteFound;
}
示例9: subtract
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的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) {
checkVectorDimensions(v.getDimension());
OpenMapRealVector res = copy();
OpenIntToDoubleHashMap.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;
}
示例10: hashCode
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的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() {
int prime = 31;
int result = 1;
long temp = Double.doubleToLongBits(epsilon);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + virtualSize;
OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
temp = Double.doubleToLongBits(iter.value());
result = prime * result + (int) (temp ^ (temp >>32));
}
return result;
}
示例11: subtract
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* Subtract {@code m} from this matrix.
*
* @param m Matrix to be subtracted.
* @return {@code this} - {@code m}.
* @throws MatrixDimensionMismatchException if {@code m} is not the same
* size as {@code this}.
*/
public OpenMapRealMatrix subtract(OpenMapRealMatrix m)
throws MatrixDimensionMismatchException {
MatrixUtils.checkAdditionCompatible(this, m);
final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance();
final int row = iterator.key() / columns;
final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) - iterator.value());
}
return out;
}
示例12: subtract
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* Subtract {@code m} from this matrix.
*
* @param m Matrix to be subtracted.
* @return {@code this} - {@code m}.
* @throws org.apache.commons.math3.exception.DimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public OpenMapRealMatrix subtract(OpenMapRealMatrix m) {
// Safety check.
MatrixUtils.checkAdditionCompatible(this, m);
final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext();) {
iterator.advance();
final int row = iterator.key() / columns;
final int col = iterator.key() - row * columns;
out.setEntry(row, col, getEntry(row, col) - iterator.value());
}
return out;
}
示例13: multiply
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
/**
* Postmultiply this matrix by {@code m}.
*
* @param m Matrix to postmultiply by.
* @return {@code this} * {@code m}.
* @throws DimensionMismatchException if the number of rows of {@code m}
* differ from the number of columns of {@code this} matrix.
* @throws NumberIsTooLargeException if the total number of entries of the
* product is larger than {@code Integer.MAX_VALUE}.
*/
public OpenMapRealMatrix multiply(OpenMapRealMatrix m)
throws DimensionMismatchException, NumberIsTooLargeException {
// Safety check.
MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension();
OpenMapRealMatrix out = new OpenMapRealMatrix(rows, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance();
final double value = iterator.value();
final int key = iterator.key();
final int i = key / columns;
final int k = key % columns;
for (int j = 0; j < outCols; ++j) {
final int rightKey = m.computeKey(k, j);
if (m.entries.containsKey(rightKey)) {
final int outKey = out.computeKey(i, j);
final double outValue =
out.entries.get(outKey) + value * m.entries.get(rightKey);
if (outValue == 0.0) {
out.entries.remove(outKey);
} else {
out.entries.put(outKey, outValue);
}
}
}
}
return out;
}
示例14: append
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的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());
OpenIntToDoubleHashMap.Iterator iter = v.entries.iterator();
while (iter.hasNext()) {
iter.advance();
res.setEntry(iter.key() + virtualSize, iter.value());
}
return res;
}
示例15: ebeMultiply
import org.apache.commons.math3.util.OpenIntToDoubleHashMap; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Deprecated
@Override
public OpenMapRealVector ebeMultiply(RealVector v) {
checkVectorDimensions(v.getDimension());
OpenMapRealVector res = new OpenMapRealVector(this);
OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
}
/*
* MATH-803: the above loop assumes that 0d * x = 0d for any double x,
* which allows to consider only the non-zero entries of this. However,
* this fails if this[i] == 0d and (v[i] = NaN or v[i] = Infinity).
*
* These special cases are handled below.
*/
if (v.isNaN() || v.isInfinite()) {
int n = getDimension();
for (int i = 0; i < n; i++) {
double y = v.getEntry(i);
if (Double.isNaN(y)) {
res.setEntry(i, Double.NaN);
} else if (Double.isInfinite(y)) {
double x = this.getEntry(i);
res.setEntry(i, x * y);
}
}
}
return res;
}