Class WrapRows

All Implemented Interfaces:
Iterable<Long>

public class WrapRows extends Matrix
Wraps a list of tensors into a matrix with the tensors as rows. Does not allocate additional elements. Editing the matrix edits the original tensors and conversely.
Author:
Emmanouil Krasanakis
  • Constructor Details

    • WrapRows

      public WrapRows(Tensor... rows)
    • WrapRows

      public WrapRows(List<Tensor> rows)
  • Method Details

    • estimateNumNonZeroElements

      public long estimateNumNonZeroElements()
      Description copied from class: Tensor
      Provides an estimation for the non-zero number of elements stored in the tensor, where this number is equal to the size for dense tensors, but equal to the actual number of non-zero elements for sparse tensors. Basically, this quantity is proportional to the allocated memory.
      Overrides:
      estimateNumNonZeroElements in class Tensor
      Returns:
      A long number equal to or less to the tensor size.
      See Also:
    • setZeroCopyType

      public WrapRows setZeroCopyType(Matrix zeroCopyType)
      Sets a prototype matrix from which to borrow copying operations.
      Parameters:
      zeroCopyType - A Matrix instance from which to borrow zeroCopy(long, long).
      Returns:
      this object
    • zeroCopy

      public Matrix zeroCopy(long rows, long cols)
      Description copied from class: Matrix
      Creates a matrix of the same class and all element set to zero, but with a given number of rows and columns.
      Specified by:
      zeroCopy in class Matrix
      Parameters:
      rows - The number of rows of the matrix.
      cols - The number of columns of the matrix.
      Returns:
      A Matrix of the same class.
      See Also:
    • allocate

      protected void allocate(long size)
      Specified by:
      allocate in class Tensor
    • put

      public Tensor put(long pos, double value)
      Description copied from class: Tensor
      Assign a value to a tensor element. All tensor operations use this function to wrap element assignments.
      Specified by:
      put in class Tensor
      Parameters:
      pos - The position of the tensor element.
      value - The value to assign.
      Returns:
      this Tensor instance.
      See Also:
    • get

      public double get(long pos)
      Description copied from class: Tensor
      Retrieves the value of a tensor element at a given position. All tensor operations use this function to wrap element retrieval.
      Specified by:
      get in class Tensor
      Parameters:
      pos - The position of the tensor element
      Returns:
      The value of the tensor element
    • traverseNonZeroElements

      public Iterator<Long> traverseNonZeroElements()
      Description copied from class: Tensor
      Retrieves positions within the tensor that may hold non-zero elements. This guarantees that all non-zero elements positions are traversed but some of the returned positions could hold zero elements. For example, DenseTensor traverses all of its elements this way, whereas SparseTensor indeed traverses only non-zero elements.
      Specified by:
      traverseNonZeroElements in class Tensor
      Returns:
      An iterator that traverses positions within the tensor.
    • getNonZeroEntries

      public Iterable<Map.Entry<Long,Long>> getNonZeroEntries()
      Description copied from class: Matrix
      Retrieves an iterable that traverses (row, col) entry pairs of non zero entries.
      Specified by:
      getNonZeroEntries in class Matrix
      Returns:
      An Entry iterable.
      See Also:
    • accessRow

      public Tensor accessRow(long row)
      Description copied from class: Matrix
      Retrieves the given row as a tensor. Editing the result also edits the original matrix. No new memory is allocated for matrix values.
      Overrides:
      accessRow in class Matrix
      Parameters:
      row - The given row.
      Returns:
      An AccessRow instance of the corresponding row.
      See Also:
    • release

      public void release()
      Description copied from class: Tensor
      If the subclassed tensor allows it, release all memory it takes up so that the garbage collector will eventually clean it up. This memory will be released anyway by Java once there are no more references to the object.
      Specified by:
      release in class Tensor
      See Also:
    • persist

      public void persist()
      Description copied from class: Tensor
      If supported by the subclassed tensor, invalidates calls to Tensor.release() so that memory is de-allocated only when object references expire.
      Specified by:
      persist in class Tensor
      See Also: