Class VariableMatrix
java.lang.Object
org.wpilib.math.autodiff.VariableMatrix
- All Implemented Interfaces:
AutoCloseable, Iterable<Variable>
A matrix of autodiff variables.
-
Constructor Summary
ConstructorsConstructorDescriptionVariableMatrix(double[][] list) Constructs a scalar VariableMatrix from a nested list of doubles.VariableMatrix(int rows) Constructs a zero-initialized VariableMatrix column vector with the given rows.VariableMatrix(int rows, int cols) Constructs a zero-initialized VariableMatrix with the given dimensions.VariableMatrix(int rows, int cols, long[] handles) Constructs a VariableMatrix from Variable internal handles.VariableMatrix(org.ejml.simple.SimpleMatrix values) Constructs a VariableMatrix from an EJML matrix.VariableMatrix(Variable variable) Constructs a scalar VariableMatrix from a Variable.VariableMatrix(Variable[][] list) Constructs a scalar VariableMatrix from a nested list of Variables.VariableMatrix(VariableBlock values) Constructs a VariableMatrix from a VariableBlock. -
Method Summary
Modifier and TypeMethodDescriptionblock(int rowOffset, int colOffset, int blockRows, int blockCols) Returns a block of the variable matrix.static VariableMatrixblock(VariableMatrix[][] list) Assembles a VariableMatrix from a nested list of blocks.voidclose()col(int col) Returns a column slice of the variable matrix.intcols()Returns the number of columns in the matrix.static VariableMatrixconstant(int rows, int cols, double constant) Returns a variable matrix filled with a constant.cwiseMap(UnaryOperator<Variable> unaryOp) Maps the matrix coefficient-wise with an unary operator.static VariableMatrixcwiseReduce(VariableMatrix lhs, VariableMatrix rhs, BinaryOperator<Variable> binaryOp) Applies a coefficient-wise reduce operation to two matrices.div(double rhs) Binary division operator.Binary division operator.get(int index) Returns the element at the given index.get(int row, int col) Returns the element at the given row and column.Returns a slice of the variable matrix.get(int row, Slice.None colSlice) Returns a slice of the variable matrix.get(Slice.None rowSlice, int col) Returns a slice of the variable matrix.get(Slice.None rowSlice, Slice colSlice) Returns a slice of the variable matrix.get(Slice.None rowSlice, Slice.None colSlice) Returns a slice of the variable matrix.Returns a slice of the variable matrix.Returns a slice of the variable matrix.get(Slice rowSlice, Slice.None colSlice) Returns a slice of the variable matrix.iterator()minus(org.ejml.simple.SimpleMatrix rhs) Binary subtraction operator.minus(VariableBlock rhs) Binary subtraction operator.minus(VariableMatrix rhs) Binary subtraction operator.static VariableMatrixone(int rows, int cols) Returns a variable matrix filled with ones.plus(org.ejml.simple.SimpleMatrix rhs) Binary addition operator.plus(VariableBlock rhs) Binary addition operator.plus(VariableMatrix rhs) Binary addition operator.row(int row) Returns a row slice of the variable matrix.introws()Returns the number of rows in the matrix.segment(int offset, int length) Returns a segment of the variable vector.set(double value) Assigns a double to the matrix.set(double[][] values) Assigns a double array to a VariableMatrix.voidset(int index, double value) Sets an element to the given value.voidset(int row, int col, double value) Sets an element to the given value.voidSets an element to the given value.voidSets an element to the given value.set(org.ejml.simple.SimpleMatrix values) Assigns an EJML matrix to a VariableMatrix.Assigns a Variable to the matrix.set(VariableBlock values) Assigns a VariableBlock to a VariableMatrix.set(VariableMatrix values) Assigns a VariableMatrix to a VariableMatrix.voidsetValue(double[][] values) Sets the VariableMatrix's internal values.voidsetValue(org.ejml.simple.SimpleMatrix values) Sets the VariableMatrix's internal values.intsize()Returns number of elements in matrix.static VariableMatrixSolves the VariableMatrix equation AX = B for X.stream()Creates a Stream of VariableMatrix elements.T()Returns the transpose of the variable matrix.times(double rhs) Matrix-scalar multiplication operator.times(org.ejml.simple.SimpleMatrix rhs) Matrix multiplication operator.Matrix-scalar multiplication operator.times(VariableBlock rhs) Matrix multiplication operator.times(VariableMatrix rhs) Matrix multiplication operator.Unary minus operator.org.ejml.simple.SimpleMatrixvalue()Returns the contents of the variable matrix.doublevalue(int index) Returns an element of the variable matrix.doublevalue(int row, int col) Returns an element of the variable matrix.static VariableMatrixzero(int rows, int cols) Returns a variable matrix filled with zeroes.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
VariableMatrix
Constructs a VariableMatrix from Variable internal handles.This constructor is for internal use only.
- Parameters:
rows- The number of matrix rows.cols- The number of matrix columns.handles- Variable handles.
-
VariableMatrix
Constructs a zero-initialized VariableMatrix column vector with the given rows.- Parameters:
rows- The number of matrix rows.
-
VariableMatrix
Constructs a zero-initialized VariableMatrix with the given dimensions.- Parameters:
rows- The number of matrix rows.cols- The number of matrix columns.
-
VariableMatrix
Constructs a scalar VariableMatrix from a nested list of doubles.- Parameters:
list- The nested list of Variables.
-
VariableMatrix
Constructs a scalar VariableMatrix from a nested list of Variables.- Parameters:
list- The nested list of Variables.
-
VariableMatrix
Constructs a VariableMatrix from an EJML matrix.- Parameters:
values- EJML matrix of values.
-
VariableMatrix
Constructs a scalar VariableMatrix from a Variable.- Parameters:
variable- Variable.
-
VariableMatrix
Constructs a VariableMatrix from a VariableBlock.- Parameters:
values- VariableBlock of values.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable
-
set
Assigns a double array to a VariableMatrix.- Parameters:
values- Double array of values.- Returns:
- This VariableMatrix.
-
set
Assigns an EJML matrix to a VariableMatrix.- Parameters:
values- EJML matrix of values.- Returns:
- This VariableMatrix.
-
set
Assigns a VariableMatrix to a VariableMatrix.- Parameters:
values- VariableMatrix of values.- Returns:
- This VariableMatrix.
-
set
Assigns a VariableBlock to a VariableMatrix.- Parameters:
values- VariableBlock of values.- Returns:
- This VariableMatrix.
-
set
Assigns a double to the matrix.This only works for matrices with one row and one column.
- Parameters:
value- Value to assign.- Returns:
- This VariableMatrix.
-
set
Assigns a Variable to the matrix.This only works for matrices with one row and one column.
- Parameters:
value- Value to assign.- Returns:
- This VariableMatrix.
-
set
-
set
Sets an element to the given value.- Parameters:
row- The row.col- The column.value- The value.
-
set
Sets an element to the given value.- Parameters:
index- The index of the element.value- The value.
-
set
-
setValue
Sets the VariableMatrix's internal values.- Parameters:
values- Double array of values.
-
setValue
Sets the VariableMatrix's internal values.- Parameters:
values- EJML matrix of values.
-
get
-
get
-
get
Returns a slice of the variable matrix.- Parameters:
row- The row.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
row- The row.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.col- The column.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.col- The column.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
get
Returns a slice of the variable matrix.- Parameters:
rowSlice- The row slice.colSlice- The column slice.- Returns:
- A slice of the variable matrix.
-
block
Returns a block of the variable matrix.- Parameters:
rowOffset- The row offset of the block selection.colOffset- The column offset of the block selection.blockRows- The number of rows in the block selection.blockCols- The number of columns in the block selection.- Returns:
- A block of the variable matrix.
-
segment
Returns a segment of the variable vector.- Parameters:
offset- The offset of the segment.length- The length of the segment.- Returns:
- A segment of the variable vector.
-
row
Returns a row slice of the variable matrix.- Parameters:
row- The row to slice.- Returns:
- A row slice of the variable matrix.
-
col
Returns a column slice of the variable matrix.- Parameters:
col- The column to slice.- Returns:
- A column slice of the variable matrix.
-
times
Matrix multiplication operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of matrix multiplication.
-
times
Matrix multiplication operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of matrix multiplication.
-
times
Matrix multiplication operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of matrix multiplication.
-
times
Matrix-scalar multiplication operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of matrix-scalar multiplication.
-
times
Matrix-scalar multiplication operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of matrix-scalar multiplication.
-
div
Binary division operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of division.
-
div
Binary division operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of division.
-
plus
Binary addition operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of addition.
-
plus
Binary addition operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of addition.
-
plus
Binary addition operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of addition.
-
minus
Binary subtraction operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of subtraction.
-
minus
Binary subtraction operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of subtraction.
-
minus
Binary subtraction operator.- Parameters:
rhs- Operator right-hand side.- Returns:
- Result of subtraction.
-
unaryMinus
-
T
Returns the transpose of the variable matrix.- Returns:
- The transpose of the variable matrix.
-
rows
Returns the number of rows in the matrix.- Returns:
- The number of rows in the matrix.
-
cols
Returns the number of columns in the matrix.- Returns:
- The number of columns in the matrix.
-
value
Returns an element of the variable matrix.- Parameters:
row- The row of the element to return.col- The column of the element to return.- Returns:
- An element of the variable matrix.
-
value
Returns an element of the variable matrix.- Parameters:
index- The index of the element to return.- Returns:
- An element of the variable matrix.
-
value
Returns the contents of the variable matrix.- Returns:
- The contents of the variable matrix.
-
cwiseMap
Maps the matrix coefficient-wise with an unary operator.- Parameters:
unaryOp- The unary operator to use for the map operation.- Returns:
- Result of the unary operator.
-
size
-
iterator
-
stream
-
zero
Returns a variable matrix filled with zeroes.- Parameters:
rows- The number of matrix rows.cols- The number of matrix columns.- Returns:
- A variable matrix filled with zeroes.
-
one
Returns a variable matrix filled with ones.- Parameters:
rows- The number of matrix rows.cols- The number of matrix columns.- Returns:
- A variable matrix filled with ones.
-
constant
Returns a variable matrix filled with a constant.- Parameters:
rows- The number of matrix rows.cols- The number of matrix columns.constant- The constant.- Returns:
- A variable matrix filled with a constant.
-
cwiseReduce
public static VariableMatrix cwiseReduce(VariableMatrix lhs, VariableMatrix rhs, BinaryOperator<Variable> binaryOp) Applies a coefficient-wise reduce operation to two matrices.- Parameters:
lhs- The left-hand side of the binary operator.rhs- The right-hand side of the binary operator.binaryOp- The binary operator to use for the reduce operation.- Returns:
- Result of binary operator.
-
block
Assembles a VariableMatrix from a nested list of blocks.Each row's blocks must have the same height, and the assembled block rows must have the same width. For example, for the block matrix [[A, B], [C]] to be constructible, the number of rows in A and B must match, and the number of columns in [A, B] and [C] must match.
- Parameters:
list- The nested list of blocks.- Returns:
- Block matrix.
-
solve
Solves the VariableMatrix equation AX = B for X.- Parameters:
A- The left-hand side.B- The right-hand side.- Returns:
- The solution X.
-