Class SelectedSparseObjectMatrix2D
- All Implemented Interfaces:
Serializable
,Cloneable
Implementation:
Objects of this class are typically constructed via viewIndexes methods on some source matrix. The interface introduced in abstract super classes defines everything a user can do. From a user point of view there is nothing special about this class; it presents the same functionality with the same signatures and semantics as its abstract superclass(es) while introducing no additional functionality. Thus, this class need not be visible to users. By the way, the same principle applies to concrete DenseXXX and SparseXXX classes: they presents the same functionality with the same signatures and semantics as abstract superclass(es) while introducing no additional functionality. Thus, they need not be visible to users, either. Factory methods could hide all these concrete types.
This class uses no delegation. Its instances point directly to the data. Cell addressing overhead is 1 additional int addition and 2 additional array index accesses per get/set.
Note that this implementation is not synchronized.
Memory requirements:
memory [bytes] = 4*(rowIndexes.length+columnIndexes.length). Thus, an index view with 1000 x 1000 indexes additionally uses 8 KB.
Time complexity:
Depends on the parent view holding cells.
- Version:
- 1.0, 09/24/99
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int[]
protected AbstractIntObjectMap
protected int
The offset.protected int[]
The offsets of the visible cells of this matrix.Fields inherited from class cern.colt.matrix.impl.AbstractMatrix2D
columns, columnStride, columnZero, rows, rowStride, rowZero
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix
isNoView
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SelectedSparseObjectMatrix2D
(int rows, int columns, AbstractIntObjectMap elements, int rowZero, int columnZero, int rowStride, int columnStride, int[] rowOffsets, int[] columnOffsets, int offset) Constructs a matrix view with the given parameters.protected
SelectedSparseObjectMatrix2D
(AbstractIntObjectMap elements, int[] rowOffsets, int[] columnOffsets, int offset) Constructs a matrix view with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
_columnOffset
(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array.protected int
_rowOffset
(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array.getQuick
(int row, int column) Returns the matrix cell value at coordinate [row,column].protected boolean
haveSharedCellsRaw
(ObjectMatrix2D other) Returns true if both matrices share common cells.protected int
index
(int row, int column) Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array.like
(int rows, int columns) Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns.like1D
(int size) Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver.protected ObjectMatrix1D
like1D
(int size, int zero, int stride) Construct and returns a new 1-d matrix of the corresponding dynamic type, sharing the same cells.void
Sets the matrix cell at coordinate [row,column] to the specified value.protected void
setUp
(int rows, int columns) Sets up a matrix with a given number of rows and columns.protected AbstractMatrix2D
vDice()
Self modifying version of viewDice().viewColumn
(int column) Constructs and returns a new slice view representing the rows of the given column.viewRow
(int row) Constructs and returns a new slice view representing the columns of the given row.protected ObjectMatrix2D
viewSelectionLike
(int[] rowOffsets, int[] columnOffsets) Construct and returns a new selection view.Methods inherited from class cern.colt.matrix.ObjectMatrix2D
aggregate, aggregate, assign, assign, assign, assign, assign, cardinality, copy, equals, equals, get, getContent, getNonZeros, haveSharedCells, like, set, toArray, toString, view, viewColumnFlip, viewDice, viewPart, viewRowFlip, viewSelection, viewSelection, viewSorted, viewStrides
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix2D
_columnRank, _rowRank, checkBox, checkColumn, checkColumnIndexes, checkRow, checkRowIndexes, checkShape, checkShape, columns, rows, setUp, size, toStringShort, vColumnFlip, vPart, vRowFlip, vStrides
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix
ensureCapacity, isView, trimToSize
Methods inherited from class cern.colt.PersistentObject
clone
-
Field Details
-
elements
-
rowOffsets
protected int[] rowOffsetsThe offsets of the visible cells of this matrix. -
columnOffsets
protected int[] columnOffsets -
offset
protected int offsetThe offset.
-
-
Constructor Details
-
SelectedSparseObjectMatrix2D
protected SelectedSparseObjectMatrix2D(int rows, int columns, AbstractIntObjectMap elements, int rowZero, int columnZero, int rowStride, int columnStride, int[] rowOffsets, int[] columnOffsets, int offset) Constructs a matrix view with the given parameters.- Parameters:
rows
- the number of rows the matrix shall have.columns
- the number of columns the matrix shall have.elements
- the cells.rowZero
- the position of the first element.columnZero
- the position of the first element.rowStride
- the number of elements between two rows, i.e. index(i+1,j)-index(i,j).columnStride
- the number of elements between two columns, i.e. index(i,j+1)-index(i,j).rowOffsets
- The row offsets of the cells that shall be visible.columnOffsets
- The column offsets of the cells that shall be visible.offset
-
-
SelectedSparseObjectMatrix2D
protected SelectedSparseObjectMatrix2D(AbstractIntObjectMap elements, int[] rowOffsets, int[] columnOffsets, int offset) Constructs a matrix view with the given parameters.- Parameters:
elements
- the cells.rowOffsets
- The row offsets of the cells that shall be visible.columnOffsets
- The column offsets of the cells that shall be visible.offset
-
-
-
Method Details
-
_columnOffset
protected int _columnOffset(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. Default implementation. Override, if necessary.- Overrides:
_columnOffset
in classAbstractMatrix2D
- Parameters:
rank
- the absolute rank of the element.- Returns:
- the position.
-
_rowOffset
protected int _rowOffset(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. Default implementation. Override, if necessary.- Overrides:
_rowOffset
in classAbstractMatrix2D
- Parameters:
rank
- the absolute rank of the element.- Returns:
- the position.
-
getQuick
Returns the matrix cell value at coordinate [row,column].Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() invalid input: '&'invalid input: '&' 0 <= row < rows().
- Specified by:
getQuick
in classObjectMatrix2D
- Parameters:
row
- the index of the row-coordinate.column
- the index of the column-coordinate.- Returns:
- the value at the specified coordinate.
-
index
protected int index(int row, int column) Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array.- Overrides:
index
in classAbstractMatrix2D
- Parameters:
row
- the index of the row-coordinate.column
- the index of the column-coordinate.
-
like
Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns. For example, if the receiver is an instance of type DenseObjectMatrix2D the new matrix must also be of type DenseObjectMatrix2D, if the receiver is an instance of type SparseObjectMatrix2D the new matrix must also be of type SparseObjectMatrix2D, etc. In general, the new matrix should have internal parametrization as similar as possible.- Specified by:
like
in classObjectMatrix2D
- Parameters:
rows
- the number of rows the matrix shall have.columns
- the number of columns the matrix shall have.- Returns:
- a new empty matrix of the same dynamic type.
-
like1D
Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseObjectMatrix2D the new matrix must be of type DenseObjectMatrix1D, if the receiver is an instance of type SparseObjectMatrix2D the new matrix must be of type SparseObjectMatrix1D, etc.- Specified by:
like1D
in classObjectMatrix2D
- Parameters:
size
- the number of cells the matrix shall have.- Returns:
- a new matrix of the corresponding dynamic type.
-
like1D
Construct and returns a new 1-d matrix of the corresponding dynamic type, sharing the same cells. For example, if the receiver is an instance of type DenseObjectMatrix2D the new matrix must be of type DenseObjectMatrix1D, if the receiver is an instance of type SparseObjectMatrix2D the new matrix must be of type SparseObjectMatrix1D, etc.- Specified by:
like1D
in classObjectMatrix2D
- Parameters:
size
- the number of cells the matrix shall have.zero
- the index of the first element.stride
- the number of indexes between any two elements, i.e. index(i+1)-index(i).- Returns:
- a new matrix of the corresponding dynamic type.
-
setQuick
Sets the matrix cell at coordinate [row,column] to the specified value.Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() invalid input: '&'invalid input: '&' 0 <= row < rows().
- Specified by:
setQuick
in classObjectMatrix2D
- Parameters:
row
- the index of the row-coordinate.column
- the index of the column-coordinate.value
- the value to be filled into the specified cell.
-
setUp
protected void setUp(int rows, int columns) Sets up a matrix with a given number of rows and columns.- Overrides:
setUp
in classAbstractMatrix2D
- Parameters:
rows
- the number of rows the matrix shall have.columns
- the number of columns the matrix shall have.- Throws:
IllegalArgumentException
- if (Object)columns*rows > Integer.MAX_VALUE.
-
vDice
Self modifying version of viewDice().- Overrides:
vDice
in classAbstractMatrix2D
-
viewColumn
Constructs and returns a new slice view representing the rows of the given column. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. To obtain a slice view on subranges, construct a sub-ranging view (viewPart(...)), then apply this method to the sub-range view.Example:
2 x 3 matrix:
1, 2, 3
4, 5, 6viewColumn(0) ==> Matrix1D of size 2:
1, 4- Overrides:
viewColumn
in classObjectMatrix2D
- Parameters:
column
- the column to fix.the
- column to fix.- Returns:
- a new slice view.
- Throws:
IllegalArgumentException
- if column invalid input: '<' 0 || column >= columns().- See Also:
-
viewRow
Constructs and returns a new slice view representing the columns of the given row. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. To obtain a slice view on subranges, construct a sub-ranging view (viewPart(...)), then apply this method to the sub-range view.Example:
2 x 3 matrix:
1, 2, 3
4, 5, 6viewRow(0) ==> Matrix1D of size 3:
1, 2, 3- Overrides:
viewRow
in classObjectMatrix2D
- Parameters:
row
- the row to fix.the
- row to fix.- Returns:
- a new slice view.
- Throws:
IndexOutOfBoundsException
- if row invalid input: '<' 0 || row >= rows().- See Also:
-
viewSelectionLike
Construct and returns a new selection view.- Specified by:
viewSelectionLike
in classObjectMatrix2D
- Parameters:
rowOffsets
- the offsets of the visible elements.columnOffsets
- the offsets of the visible elements.- Returns:
- a new view.
-