本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D.forEachNonZero方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D.forEachNonZero方法的具体用法?Java DoubleMatrix2D.forEachNonZero怎么用?Java DoubleMatrix2D.forEachNonZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.DoubleMatrix2D
的用法示例。
在下文中一共展示了DoubleMatrix2D.forEachNonZero方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logMult
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static DoubleMatrix1D logMult(DoubleMatrix2D M, DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) {
// z = alpha * A * y + beta*z
double lalpha = 0;
if (alpha != 1)
lalpha = Math.log(alpha);
if (beta != 0) {
if (beta != 1) {
double lbeta = Math.log(beta);
for (int i = 0; i < z.size(); z.set(i,z.get(i)+lbeta),i++);
}
} else {
z.assign(RobustMath.LOG0);
}
// in log domain this becomes:
logMult.M = M;
logMult.z = z;
logMult.lalpha = lalpha;
logMult.transposeA = transposeA;
logMult.y = y;
logMult.cnt=0;
M.forEachNonZero(logMult);
// System.out.println("Matrix "+M.size()+" "+M.columns()+ " "+logMult.cnt);
return z;
}
示例2: assign
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Replaces all cell values of the receiver with the values of another matrix.
* Both matrices must have the same number of rows and columns.
* If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>.
*
* @param source the source matrix to copy from (may be identical to the receiver).
* @return <tt>this</tt> (for convenience only).
* @throws IllegalArgumentException if <tt>columns() != source.columns() || rows() != source.rows()</tt>
*/
public DoubleMatrix2D assign(DoubleMatrix2D source) {
// overriden for performance only
if (source==this) return this; // nothing to do
checkShape(source);
if (source instanceof TridiagonalDoubleMatrix2D) {
// quickest
TridiagonalDoubleMatrix2D other = (TridiagonalDoubleMatrix2D) source;
System.arraycopy(other.values, 0, this.values, 0, this.values.length);
System.arraycopy(other.dims, 0, this.dims, 0, this.dims.length);
return this;
}
if (source instanceof RCDoubleMatrix2D || source instanceof SparseDoubleMatrix2D) {
assign(0);
source.forEachNonZero(
new cern.colt.function.IntIntDoubleFunction() {
public double apply(int i, int j, double value) {
setQuick(i,j,value);
return value;
}
}
);
return this;
}
return super.assign(source);
}
示例3: assign
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* Replaces all cell values of the receiver with the values of another matrix.
* Both matrices must have the same number of rows and columns.
* If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>.
*
* @param source the source matrix to copy from (may be identical to the receiver).
* @return <tt>this</tt> (for convenience only).
* @throws IllegalArgumentException if <tt>columns() != source.columns() || rows() != source.rows()</tt>
*/
public DoubleMatrix2D assign(DoubleMatrix2D source) {
if (source==this) return this; // nothing to do
checkShape(source);
// overriden for performance only
if (! (source instanceof RCDoubleMatrix2D)) {
//return super.assign(source);
assign(0);
source.forEachNonZero(
new cern.colt.function.IntIntDoubleFunction() {
public double apply(int i, int j, double value) {
setQuick(i,j,value);
return value;
}
}
);
/*
indexes.clear();
values.clear();
int nonZeros=0;
for (int row=0; row<rows; row++) {
starts[row]=nonZeros;
for (int column=0; column<columns; column++) {
double v = source.getQuick(row,column);
if (v!=0) {
values.add(v);
indexes.add(column);
nonZeros++;
}
}
}
starts[rows]=nonZeros;
*/
return this;
}
// even quicker
RCDoubleMatrix2D other = (RCDoubleMatrix2D) source;
System.arraycopy(other.starts, 0, this.starts, 0, this.starts.length);
int s = other.indexes.size();
this.indexes.setSize(s);
this.values.setSize(s);
this.indexes.replaceFromToWithFrom(0,s-1,other.indexes,0);
this.values.replaceFromToWithFrom(0,s-1,other.values,0);
return this;
}