001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math;
006
007import edu.wpi.first.math.numbers.N1;
008import java.util.Objects;
009import org.ejml.simple.SimpleMatrix;
010
011@Deprecated
012public final class MatrixUtils {
013  private MatrixUtils() {
014    throw new AssertionError("utility class");
015  }
016
017  /**
018   * Creates a new matrix of zeros.
019   *
020   * @param rows The number of rows in the matrix.
021   * @param cols The number of columns in the matrix.
022   * @param <R> The number of rows in the matrix as a generic.
023   * @param <C> The number of columns in the matrix as a generic.
024   * @return An RxC matrix filled with zeros.
025   */
026  @SuppressWarnings("LineLength")
027  public static <R extends Num, C extends Num> Matrix<R, C> zeros(Nat<R> rows, Nat<C> cols) {
028    return new Matrix<>(
029        new SimpleMatrix(
030            Objects.requireNonNull(rows).getNum(), Objects.requireNonNull(cols).getNum()));
031  }
032
033  /**
034   * Creates a new vector of zeros.
035   *
036   * @param nums The size of the desired vector.
037   * @param <N> The size of the desired vector as a generic.
038   * @return A vector of size N filled with zeros.
039   */
040  public static <N extends Num> Matrix<N, N1> zeros(Nat<N> nums) {
041    return new Matrix<>(new SimpleMatrix(Objects.requireNonNull(nums).getNum(), 1));
042  }
043
044  /**
045   * Creates the identity matrix of the given dimension.
046   *
047   * @param dim The dimension of the desired matrix.
048   * @param <D> The dimension of the desired matrix as a generic.
049   * @return The DxD identity matrix.
050   */
051  public static <D extends Num> Matrix<D, D> eye(Nat<D> dim) {
052    return new Matrix<>(SimpleMatrix.identity(Objects.requireNonNull(dim).getNum()));
053  }
054
055  /**
056   * Entrypoint to the MatBuilder class for creation of custom matrices with the given dimensions
057   * and contents.
058   *
059   * @param rows The number of rows of the desired matrix.
060   * @param cols The number of columns of the desired matrix.
061   * @param <R> The number of rows of the desired matrix as a generic.
062   * @param <C> The number of columns of the desired matrix as a generic.
063   * @return A builder to construct the matrix.
064   */
065  public static <R extends Num, C extends Num> MatBuilder<R, C> mat(Nat<R> rows, Nat<C> cols) {
066    return new MatBuilder<>(rows, cols);
067  }
068
069  /**
070   * Entrypoint to the VecBuilder class for creation of custom vectors with the given size and
071   * contents.
072   *
073   * @param dim The dimension of the vector.
074   * @param <D> The dimension of the vector as a generic.
075   * @return A builder to construct the vector.
076   */
077  public static <D extends Num> VecBuilder<D> vec(Nat<D> dim) {
078    return new VecBuilder<>(dim);
079  }
080}