Class MatrixIO

java.lang.Object
org.moeaframework.util.io.MatrixIO

public class MatrixIO extends Object
Static methods for reading and writing matrices. Each row in the matrix maps to a row in the file, and each row is expected to contain the same number of values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[][]
    load(File file)
    Loads the content of the file into a matrix.
    static double[][]
    load(Reader reader)
    Loads the content of the reader into a matrix.
    static double[]
    loadColumn(File file, int index)
    Loads a single column from the file into a matrix.
    static double[]
    loadColumn(Reader reader, int index)
    Loads a single column from the reader into a matrix.
    static void
    save(File file, double[][] matrix)
    Saves a matrix to a file.
    static void
    save(File file, Iterable<double[]> matrix)
    Saves a matrix to a file.
    static void
    save(Writer writer, double[][] matrix)
    Saves a matrix to the writer.
    static void
    save(Writer writer, Iterable<double[]> matrix)
    Saves a matrix to the writer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • load

      public static double[][] load(Reader reader) throws IOException
      Loads the content of the reader into a matrix.
      Parameters:
      reader - the reader containing the matrix
      Returns:
      the matrix values
      Throws:
      IOException - if an I/O error occurred while reading the file
    • load

      public static double[][] load(File file) throws FileNotFoundException, IOException
      Loads the content of the file into a matrix.
      Parameters:
      file - the file containing the matrix
      Returns:
      the matrix values
      Throws:
      FileNotFoundException - if the file was not found
      IOException - if an I/O error occurred while reading the file
    • loadColumn

      public static double[] loadColumn(Reader reader, int index) throws IOException
      Loads a single column from the reader into a matrix.
      Parameters:
      reader - the reader containing the matrix
      index - the index of the column
      Returns:
      the column values
      Throws:
      IOException - if an I/O error occurred while reading the file
      IndexOutOfBoundsException - if the index is not a valid column
    • loadColumn

      public static double[] loadColumn(File file, int index) throws FileNotFoundException, IOException
      Loads a single column from the file into a matrix.
      Parameters:
      file - the file containing the matrix
      index - the index of the column
      Returns:
      the column values
      Throws:
      FileNotFoundException - if the file was not found
      IOException - if an I/O error occurred while reading the file
      IndexOutOfBoundsException - if the index is not a valid column
    • save

      public static void save(Writer writer, double[][] matrix)
      Saves a matrix to the writer.
      Parameters:
      writer - the writer
      matrix - a 2D array containing the matrix
    • save

      public static void save(File file, double[][] matrix) throws IOException
      Saves a matrix to a file.
      Parameters:
      file - the file
      matrix - a 2D array containing the matrix
      Throws:
      IOException - if an I/O error occurred while writing the file
    • save

      public static void save(Writer writer, Iterable<double[]> matrix)
      Saves a matrix to the writer.
      Parameters:
      writer - the writer
      matrix - an iterator over the rows in the matrix
    • save

      public static void save(File file, Iterable<double[]> matrix) throws IOException
      Saves a matrix to a file.
      Parameters:
      file - the file
      matrix - an iterator over the rows in the matrix
      Throws:
      IOException - if an I/O error occurred while writing the file