本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.buildArray方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.buildArray方法的具体用法?Java MathArrays.buildArray怎么用?Java MathArrays.buildArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathArrays
的用法示例。
在下文中一共展示了MathArrays.buildArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copy
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Copy a two-dimensions array.
* @param field field to which elements belong
* @param original original array (may be null)
* @return copied array or null if original array was null
*/
protected T[][] copy(final Field<T> field, final T[][] original) {
// special handling of null arrays
if (original == null) {
return null;
}
// allocate the array
final T[][] copied = MathArrays.buildArray(field, original.length, -1);
// copy content
for (int i = 0; i < original.length; ++i) {
copied[i] = original[i].clone();
}
return copied;
}
示例2: getA
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[][] getA() {
final T two = getField().getZero().add(2);
final T sqrtTwo = two.sqrt();
final T[][] a = MathArrays.buildArray(getField(), 3, -1);
for (int i = 0; i < a.length; ++i) {
a[i] = MathArrays.buildArray(getField(), i + 1);
}
a[0][0] = fraction(1, 2);
a[1][0] = sqrtTwo.subtract(1).multiply(0.5);
a[1][1] = sqrtTwo.subtract(2).multiply(-0.5);
a[2][0] = getField().getZero();
a[2][1] = sqrtTwo.multiply(-0.5);
a[2][2] = sqrtTwo.add(2).multiply(0.5);
return a;
}
示例3: buildP
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Build the P matrix.
* <p>The P matrix general terms are shifted (j+1) (-i)<sup>j</sup> terms
* with i being the row number starting from 1 and j being the column
* number starting from 1:
* <pre>
* [ -2 3 -4 5 ... ]
* [ -4 12 -32 80 ... ]
* P = [ -6 27 -108 405 ... ]
* [ -8 48 -256 1280 ... ]
* [ ... ]
* </pre></p>
* @param rows number of rows of the matrix
* @return P matrix
*/
private FieldMatrix<T> buildP(final int rows) {
final T[][] pData = MathArrays.buildArray(field, rows, rows);
for (int i = 1; i <= pData.length; ++i) {
// build the P matrix elements from Taylor series formulas
final T[] pI = pData[i - 1];
final int factor = -i;
T aj = field.getZero().add(factor);
for (int j = 1; j <= pI.length; ++j) {
pI[j - 1] = aj.multiply(j + 1);
aj = aj.multiply(factor);
}
}
return new Array2DRowFieldMatrix<T>(pData, false);
}
示例4: operate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public T[] operate(final T[] v) throws DimensionMismatchException {
final int nRows = this.getRowDimension();
final int nCols = this.getColumnDimension();
if (v.length != nCols) {
throw new DimensionMismatchException(v.length, nCols);
}
final T[] out = MathArrays.buildArray(getField(), nRows);
for (int row = 0; row < nRows; row++) {
final T[] dataRow = data[row];
T sum = getField().getZero();
for (int i = 0; i < nCols; i++) {
sum = sum.add(dataRow[i].multiply(v[i]));
}
out[row] = sum;
}
return out;
}
示例5: multiply
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Postmultiplying this matrix by {@code m}.
*
* @param m Matrix to postmultiply by.
* @return {@code this} * m.
* @throws DimensionMismatchException if the number of columns of this
* matrix is not equal to the number of rows of {@code m}.
*/
public Array2DRowFieldMatrix<T> multiply(final Array2DRowFieldMatrix<T> m)
throws DimensionMismatchException {
// safety check
checkMultiplicationCompatible(m);
final int nRows = this.getRowDimension();
final int nCols = m.getColumnDimension();
final int nSum = this.getColumnDimension();
final T[][] outData = MathArrays.buildArray(getField(), nRows, nCols);
for (int row = 0; row < nRows; row++) {
final T[] dataRow = data[row];
final T[] outDataRow = outData[row];
for (int col = 0; col < nCols; col++) {
T sum = getField().getZero();
for (int i = 0; i < nSum; i++) {
sum = sum.add(dataRow[i].multiply(m.data[i][col]));
}
outDataRow[col] = sum;
}
}
return new Array2DRowFieldMatrix<T>(getField(), outData, false);
}
示例6: BlockFieldMatrix
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Create a new dense matrix copying entries from block layout data.
* <p>The input array <em>must</em> already be in blocks layout.</p>
* @param rows the number of rows in the new matrix
* @param columns the number of columns in the new matrix
* @param blockData data for new matrix
* @param copyArray if true, the input array will be copied, otherwise
* it will be referenced
*
* @throws DimensionMismatchException if the {@code blockData} shape is
* inconsistent with block layout.
* @throws NotStrictlyPositiveException if row or column dimension is not
* positive.
* @see #createBlocksLayout(Field, int, int)
* @see #toBlocksLayout(FieldElement[][])
* @see #BlockFieldMatrix(FieldElement[][])
*/
public BlockFieldMatrix(final int rows, final int columns,
final T[][] blockData, final boolean copyArray)
throws DimensionMismatchException, NotStrictlyPositiveException {
super(extractField(blockData), rows, columns);
this.rows = rows;
this.columns = columns;
// number of blocks
blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE;
blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE;
if (copyArray) {
// allocate storage blocks, taking care of smaller ones at right and bottom
blocks = MathArrays.buildArray(getField(), blockRows * blockColumns, -1);
} else {
// reference existing array
blocks = blockData;
}
int index = 0;
for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
final int iHeight = blockHeight(iBlock);
for (int jBlock = 0; jBlock < blockColumns; ++jBlock, ++index) {
if (blockData[index].length != iHeight * blockWidth(jBlock)) {
throw new DimensionMismatchException(blockData[index].length,
iHeight * blockWidth(jBlock));
}
if (copyArray) {
blocks[index] = blockData[index].clone();
}
}
}
}
示例7: getA
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[][] getA() {
final T[][] a = MathArrays.buildArray(getField(), 3, -1);
for (int i = 0; i < a.length; ++i) {
a[i] = MathArrays.buildArray(getField(), i + 1);
}
a[0][0] = fraction(1, 2);
a[1][0] = getField().getZero();
a[1][1] = a[0][0];
a[2][0] = getField().getZero();
a[2][1] = getField().getZero();
a[2][2] = getField().getOne();
return a;
}
示例8: getColumn
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[] getColumn(final int column) throws OutOfRangeException {
checkColumnIndex(column);
final int nRows = getRowDimension();
final T[] out = MathArrays.buildArray(field, nRows);
for (int i = 0; i < nRows; ++i) {
out[i] = getEntry(i, column);
}
return out;
}
示例9: getB
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[] getB() {
final T[] b = MathArrays.buildArray(getField(), 7);
b[0] = fraction( 1, 20);
b[1] = getField().getZero();
b[2] = fraction(16, 45);
b[3] = getField().getZero();
b[4] = fraction(49, 180);
b[5] = b[4];
b[6] = b[0];
return b;
}
示例10: extractEquationData
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Extract equation data from a complete state or derivative array.
* @param index index of the equation, must be between 0 included and
* {@link #getNumberOfEquations()} (excluded)
* @param complete complete state or derivative array from which
* equation data should be retrieved
* @return equation data
* @exception MathIllegalArgumentException if index is out of range
* @exception DimensionMismatchException if complete state has not enough elements
*/
public T[] extractEquationData(final int index, final T[] complete)
throws MathIllegalArgumentException, DimensionMismatchException {
checkIndex(index);
final int begin = start[index];
final int end = start[index + 1];
if (complete.length < end) {
throw new DimensionMismatchException(complete.length, end);
}
final int dimension = end - begin;
final T[] equationData = MathArrays.buildArray(complete[0].getField(), dimension);
System.arraycopy(complete, begin, equationData, 0, dimension);
return equationData;
}
示例11: getA
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[][] getA() {
final T[][] a = MathArrays.buildArray(getField(), 3, -1);
for (int i = 0; i < a.length; ++i) {
a[i] = MathArrays.buildArray(getField(), i + 1);
}
a[0][0] = fraction(1, 3);
a[1][0] = a[0][0].negate();
a[1][1] = getField().getOne();
a[2][0] = getField().getOne();
a[2][1] = getField().getOne().negate();
a[2][2] = getField().getOne();
return a;
}
示例12: mapStateAndDerivative
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Map flat arrays to a state and derivative.
* @param t time
* @param y state array to map, including primary and secondary components
* @param yDot state derivative array to map, including primary and secondary components
* @return mapped state
* @exception DimensionMismatchException if an array does not match total dimension
*/
public FieldODEStateAndDerivative<T> mapStateAndDerivative(final T t, final T[] y, final T[] yDot)
throws DimensionMismatchException {
if (y.length != getTotalDimension()) {
throw new DimensionMismatchException(y.length, getTotalDimension());
}
if (yDot.length != getTotalDimension()) {
throw new DimensionMismatchException(yDot.length, getTotalDimension());
}
final int n = getNumberOfEquations();
int index = 0;
final T[] state = extractEquationData(index, y);
final T[] derivative = extractEquationData(index, yDot);
if (n < 2) {
return new FieldODEStateAndDerivative<T>(t, state, derivative);
} else {
final T[][] secondaryState = MathArrays.buildArray(t.getField(), n - 1, -1);
final T[][] secondaryDerivative = MathArrays.buildArray(t.getField(), n - 1, -1);
while (++index < getNumberOfEquations()) {
secondaryState[index - 1] = extractEquationData(index, y);
secondaryDerivative[index - 1] = extractEquationData(index, yDot);
}
return new FieldODEStateAndDerivative<T>(t, state, derivative, secondaryState, secondaryDerivative);
}
}
示例13: getB
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public T[] getB() {
final T[] b = MathArrays.buildArray(getField(), 7);
b[0] = fraction( 1, 12);
b[1] = getField().getZero();
b[2] = fraction( 27, 32);
b[3] = fraction( -4, 3);
b[4] = fraction(125, 96);
b[5] = fraction( 5, 48);
b[6] = getField().getZero();
return b;
}
示例14: buildArray
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Create a dimension 3 array.
* @param a0 first array element
* @param a1 second array element
* @param a2 third array element
* @return new array
*/
private T[] buildArray(final T a0, final T a1, final T a2) {
final T[] array = MathArrays.buildArray(a0.getField(), 3);
array[0] = a0;
array[1] = a1;
array[2] = a2;
return array;
}
示例15: mapAdd
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public FieldVector<T> mapAdd(T d) throws NullArgumentException {
T[] out = MathArrays.buildArray(field, data.length);
for (int i = 0; i < data.length; i++) {
out[i] = data[i].add(d);
}
return new ArrayFieldVector<T>(field, out, false);
}