Class VariableMatrix

java.lang.Object
org.wpilib.math.autodiff.VariableMatrix
All Implemented Interfaces:
AutoCloseable, Iterable<Variable>

public class VariableMatrix extends Object implements AutoCloseable, Iterable<Variable>
A matrix of autodiff variables.
  • Constructor Details

    • VariableMatrix

      public VariableMatrix(int rows, int cols, long[] handles)
      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

      public VariableMatrix(int rows)
      Constructs a zero-initialized VariableMatrix column vector with the given rows.
      Parameters:
      rows - The number of matrix rows.
    • VariableMatrix

      public VariableMatrix(int rows, int cols)
      Constructs a zero-initialized VariableMatrix with the given dimensions.
      Parameters:
      rows - The number of matrix rows.
      cols - The number of matrix columns.
    • VariableMatrix

      public VariableMatrix(double[][] list)
      Constructs a scalar VariableMatrix from a nested list of doubles.
      Parameters:
      list - The nested list of Variables.
    • VariableMatrix

      public VariableMatrix(Variable[][] list)
      Constructs a scalar VariableMatrix from a nested list of Variables.
      Parameters:
      list - The nested list of Variables.
    • VariableMatrix

      public VariableMatrix(org.ejml.simple.SimpleMatrix values)
      Constructs a VariableMatrix from an EJML matrix.
      Parameters:
      values - EJML matrix of values.
    • VariableMatrix

      public VariableMatrix(Variable variable)
      Constructs a scalar VariableMatrix from a Variable.
      Parameters:
      variable - Variable.
    • VariableMatrix

      public VariableMatrix(VariableBlock values)
      Constructs a VariableMatrix from a VariableBlock.
      Parameters:
      values - VariableBlock of values.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • set

      public VariableMatrix set(double[][] values)
      Assigns a double array to a VariableMatrix.
      Parameters:
      values - Double array of values.
      Returns:
      This VariableMatrix.
    • set

      public VariableMatrix set(org.ejml.simple.SimpleMatrix values)
      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

      public VariableMatrix set(VariableBlock values)
      Assigns a VariableBlock to a VariableMatrix.
      Parameters:
      values - VariableBlock of values.
      Returns:
      This VariableMatrix.
    • set

      public VariableMatrix set(double value)
      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

      public VariableMatrix set(Variable value)
      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

      public void set(int row, int col, Variable value)
      Sets an element to the given value.
      Parameters:
      row - The row.
      col - The column.
      value - The value.
    • set

      public void set(int row, int col, double value)
      Sets an element to the given value.
      Parameters:
      row - The row.
      col - The column.
      value - The value.
    • set

      public void set(int index, double value)
      Sets an element to the given value.
      Parameters:
      index - The index of the element.
      value - The value.
    • set

      public void set(int index, Variable value)
      Sets an element to the given value.
      Parameters:
      index - The index of the element.
      value - The value.
    • setValue

      public void setValue(double[][] values)
      Sets the VariableMatrix's internal values.
      Parameters:
      values - Double array of values.
    • setValue

      public void setValue(org.ejml.simple.SimpleMatrix values)
      Sets the VariableMatrix's internal values.
      Parameters:
      values - EJML matrix of values.
    • get

      public Variable get(int row, int col)
      Returns the element at the given row and column.
      Parameters:
      row - The row.
      col - The column.
      Returns:
      The element at the given row and column.
    • get

      public Variable get(int index)
      Returns the element at the given index.
      Parameters:
      index - The index.
      Returns:
      The element at the given index.
    • get

      public VariableBlock get(int row, Slice.None colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      row - The row.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(int row, Slice colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      row - The row.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice.None rowSlice, int col)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      col - The column.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice rowSlice, int col)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      col - The column.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice.None rowSlice, Slice.None colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice.None rowSlice, Slice colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice rowSlice, Slice.None colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • get

      public VariableBlock get(Slice rowSlice, Slice colSlice)
      Returns a slice of the variable matrix.
      Parameters:
      rowSlice - The row slice.
      colSlice - The column slice.
      Returns:
      A slice of the variable matrix.
    • block

      public VariableBlock block(int rowOffset, int colOffset, int blockRows, int blockCols)
      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

      public VariableBlock segment(int offset, int length)
      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

      public VariableBlock row(int row)
      Returns a row slice of the variable matrix.
      Parameters:
      row - The row to slice.
      Returns:
      A row slice of the variable matrix.
    • col

      public VariableBlock col(int 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

      public VariableMatrix times(org.ejml.simple.SimpleMatrix rhs)
      Matrix multiplication operator.
      Parameters:
      rhs - Operator right-hand side.
      Returns:
      Result of matrix multiplication.
    • times

      public VariableMatrix times(double rhs)
      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

      public VariableMatrix div(double rhs)
      Binary division operator.
      Parameters:
      rhs - Operator right-hand side.
      Returns:
      Result of division.
    • div

      public VariableMatrix div(Variable rhs)
      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

      public VariableMatrix plus(org.ejml.simple.SimpleMatrix rhs)
      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

      public VariableMatrix minus(org.ejml.simple.SimpleMatrix rhs)
      Binary subtraction operator.
      Parameters:
      rhs - Operator right-hand side.
      Returns:
      Result of subtraction.
    • unaryMinus

      Unary minus operator.
      Returns:
      Result of unary minus.
    • T

      public VariableMatrix T()
      Returns the transpose of the variable matrix.
      Returns:
      The transpose of the variable matrix.
    • rows

      public int rows()
      Returns the number of rows in the matrix.
      Returns:
      The number of rows in the matrix.
    • cols

      public int cols()
      Returns the number of columns in the matrix.
      Returns:
      The number of columns in the matrix.
    • value

      public double value(int row, int col)
      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

      public double value(int index)
      Returns an element of the variable matrix.
      Parameters:
      index - The index of the element to return.
      Returns:
      An element of the variable matrix.
    • value

      public org.ejml.simple.SimpleMatrix 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

      public int size()
      Returns number of elements in matrix.
      Returns:
      Number of elements in matrix.
    • iterator

      Specified by:
      iterator in interface Iterable<Variable>
    • stream

      public Stream<Variable> stream()
      Creates a Stream of VariableMatrix elements.
      Returns:
      A Stream of VariableMatrix elements.
    • zero

      public static VariableMatrix zero(int rows, int cols)
      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

      public static VariableMatrix one(int rows, int cols)
      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

      public static VariableMatrix constant(int rows, int cols, double 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

      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

      public static VariableMatrix block(VariableMatrix[][] list)
      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.