本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.verifyValues方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.verifyValues方法的具体用法?Java MathArrays.verifyValues怎么用?Java MathArrays.verifyValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathArrays
的用法示例。
在下文中一共展示了MathArrays.verifyValues方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeAndSlice
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Remove the occurrence of a given value in a copied slice of array
* defined by the array part from [begin, begin+length).
* @param values the input array
* @param begin start index of the array to include
* @param length number of elements to include from begin
* @param removedValue the value to be removed from the sliced array
* @return the copy of the sliced array after removing the removedValue
*/
private static double[] removeAndSlice(final double[] values,
final int begin, final int length,
final double removedValue) {
MathArrays.verifyValues(values, begin, length);
final double[] temp;
//BitSet(length) to indicate where the removedValue is located
final BitSet bits = new BitSet(length);
for (int i = begin; i < begin+length; i++) {
if (Precision.equalsIncludingNaN(removedValue, values[i])) {
bits.set(i - begin);
}
}
//Check if empty then create a new copy
if (bits.isEmpty()) {
temp = copyOf(values, begin, length); // Nothing removed, just copy
} else if(bits.cardinality() == length){
temp = new double[0]; // All removed, just empty
}else { // Some removable, so new
temp = new double[length - bits.cardinality()];
int start = begin; //start index from source array (i.e values)
int dest = 0; //dest index in destination array(i.e temp)
int nextOne = -1; //nextOne is the index of bit set of next one
int bitSetPtr = 0; //bitSetPtr is start index pointer of bitset
while ((nextOne = bits.nextSetBit(bitSetPtr)) != -1) {
final int lengthToCopy = nextOne - bitSetPtr;
System.arraycopy(values, start, temp, dest, lengthToCopy);
dest += lengthToCopy;
start = begin + (bitSetPtr = bits.nextClearBit(nextOne));
}
//Copy any residue past start index till begin+length
if (start < begin + length) {
System.arraycopy(values,start,temp,dest,begin + length - start);
}
}
return temp;
}
示例2: test
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* This method is used by <code>evaluate(double[], int, int)</code> methods
* to verify that the input parameters designate a subarray of positive length.
* <p>
* <ul>
* <li>returns <code>true</code> iff the parameters designate a subarray of
* positive length</li>
* <li>throws <code>MathIllegalArgumentException</code> if the array is null or
* or the indices are invalid</li>
* <li>returns <code>false</li> if the array is non-null, but
* <code>length</code> is 0.
* </ul></p>
*
* @param values the input array
* @param begin index of the first array element to include
* @param length the number of elements to include
* @return true if the parameters are valid and designate a subarray of positive length
* @throws MathIllegalArgumentException if the indices are invalid or the array is null
*/
protected boolean test(
final double[] values,
final int begin,
final int length) throws MathIllegalArgumentException {
return MathArrays.verifyValues(values, begin, length, false);
}
示例3: copyOf
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Make a copy of the array for the slice defined by array part from
* [begin, begin+length)
* @param values the input array
* @param begin start index of the array to include
* @param length number of elements to include from begin
* @return copy of a slice of the original array
*/
private static double[] copyOf(final double[] values, final int begin, final int length) {
MathArrays.verifyValues(values, begin, length);
return MathArrays.copyOfRange(values, begin, begin + length);
}