daf.typing.matrices¶
The types here describe 2D data without names (that is, not in a pandas.DataFrame
), which is how 2D data is stored
in daf
. Currently there are only two such types:
Dense
is a 2Dnumpy.ndarray
matrix.Sparse
is a compressed sparse matrix (eitherscipy.sparse.csr_matrix
orscipy.sparse.csc_matrix
).
The Matrix
type annotations is simply their union, that is, allows for “any” 2D data without names. While this isn’t
very useful to directly perform operation on, it is very useful as the return type of fetching 2D data stored in
daf
, as the caller has no control over whether the data was stored as sparse, and forcing it to be dense would not
be practical for large data sets.
Note
The Matrix
type should be only be directly used in computations with great care, as some operations are
subtly different for numpy
2D arrays and scipy.sparse
compressed matrices. It is typically better to use one
of the concrete types instead.
Data:
Any 2D data, in either |
|
Any 2D data in |
|
Any 2D data in |
Functions:
|
Assert that some |
|
Assert that some |
Access the internal 2D matrix, if possible; otherwise, or if |
|
|
Assert that some |
|
Assert that some |
|
Assert that some |
|
Assert that some |
- daf.typing.matrices.Matrix(*args, **kwargs)¶
Any 2D data, in either
ROW_MAJOR
orCOLUMN_MAJOR
layout, without names.Note
This is not to be confused with the deprecated
numpy.matrix
type which must never be used.alias of
Union
[DenseInRows
,DenseInColumns
,SparseInRows
,SparseInColumns
]
- daf.typing.matrices.is_matrix(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[_layouts.AnyMajor] = None) TypeGuard[Matrix] [source]¶
Assert that some
data
is aMatrix
, optionally only of somedtype
, optionally only of someshape
, optionally only of somelayout
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.
- daf.typing.matrices.be_matrix(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[AnyMajor] = None) Union[DenseInRows, DenseInColumns, SparseInRows, SparseInColumns] [source]¶
Assert that some
data
is aMatrix
, optionally only of somedtype
, optionally only of someshape
, optionally only of somelayout
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.
- daf.typing.matrices.as_matrix(data: DenseInRows, *, force_copy: bool = False) DenseInRows [source]¶
- daf.typing.matrices.as_matrix(data: DenseInColumns, *, force_copy: bool = False) DenseInColumns
- daf.typing.matrices.as_matrix(data: SparseInRows, *, force_copy: bool = False) SparseInRows
- daf.typing.matrices.as_matrix(data: SparseInColumns, *, force_copy: bool = False) SparseInColumns
- daf.typing.matrices.as_matrix(data: spmatrix, *, force_copy: bool = False) Union[SparseInRows, SparseInColumns]
- daf.typing.matrices.as_matrix(data: FrameInRows, *, force_copy: bool = False) DenseInRows
- daf.typing.matrices.as_matrix(data: FrameInColumns, *, force_copy: bool = False) DenseInColumns
- daf.typing.matrices.as_matrix(data: DataFrame, *, force_copy: bool = False) Union[DenseInRows, DenseInColumns]
- daf.typing.matrices.as_matrix(data: Union[Sequence[Any], ndarray, _fake_sparse.spmatrix, Series, DataFrame], *, force_copy: bool = False) Union[DenseInRows, DenseInColumns, SparseInRows, SparseInColumns]
Access the internal 2D matrix, if possible; otherwise, or if
force_copy
, return a copy of the 2D data as anumpy
array.If the input is a
pandas.DataFrame
, this will only work if all the data in the frame has the same type.
- daf.typing.matrices.MatrixInRows(*args, **kwargs)¶
Any 2D data in
ROW_MAJOR
layout, without names.alias of
Union
[DenseInRows
,SparseInRows
]
- daf.typing.matrices.is_matrix_in_rows(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[MatrixInRows] [source]¶
Assert that some
data
is aMatrixInRows
, optionally only of somedtype
, optionally only of someshape
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.
- daf.typing.matrices.be_matrix_in_rows(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) Union[DenseInRows, SparseInRows] [source]¶
Assert that some
data
is aMatrixInRows
, optionally only of somedtype
, optionally only of someshape
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.
- daf.typing.matrices.MatrixInColumns(*args, **kwargs)¶
Any 2D data in
COLUMN_MAJOR
layout, without names.alias of
Union
[DenseInColumns
,SparseInColumns
]
- daf.typing.matrices.is_matrix_in_columns(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[MatrixInColumns] [source]¶
Assert that some
data
is aMatrixInColumns
, optionally only of somedtype
, optionally only of someshape
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.
- daf.typing.matrices.be_matrix_in_columns(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) Union[DenseInColumns, SparseInColumns] [source]¶
Assert that some
data
is aMatrixInColumns
, optionally only of somedtype
, optionally only of someshape
, and return it as such formypy
.By default, checks that the data type is one of
ALL_DTYPES
.