Scipy
zenml.integrations.scipy
special
Initialization of the Scipy integration.
ScipyIntegration (Integration)
Definition of scipy integration for ZenML.
Source code in zenml/integrations/scipy/__init__.py
class ScipyIntegration(Integration):
"""Definition of scipy integration for ZenML."""
NAME = SCIPY
REQUIREMENTS = ["scipy"]
@classmethod
def activate(cls) -> None:
"""Activates the integration."""
from zenml.integrations.scipy import materializers # noqa
activate()
classmethod
Activates the integration.
Source code in zenml/integrations/scipy/__init__.py
@classmethod
def activate(cls) -> None:
"""Activates the integration."""
from zenml.integrations.scipy import materializers # noqa
materializers
special
Initialization of the Scipy materializers.
sparse_materializer
Implementation of the Scipy Sparse Materializer.
SparseMaterializer (BaseMaterializer)
Materializer to read and write scipy sparse matrices.
Source code in zenml/integrations/scipy/materializers/sparse_materializer.py
class SparseMaterializer(BaseMaterializer):
"""Materializer to read and write scipy sparse matrices."""
ASSOCIATED_TYPES = (spmatrix,)
ASSOCIATED_ARTIFACT_TYPES = (DataArtifact,)
def handle_input(self, data_type: Type[Any]) -> spmatrix:
"""Reads spmatrix from npz file.
Args:
data_type: The type of the spmatrix to load.
Returns:
A spmatrix object.
"""
super().handle_input(data_type)
with fileio.open(
os.path.join(self.artifact.uri, DATA_FILENAME), "rb"
) as f:
mat = load_npz(f)
return mat
def handle_return(self, mat: spmatrix) -> None:
"""Writes a spmatrix to the artifact store as a npz file.
Args:
mat: The spmatrix to write.
"""
super().handle_return(mat)
with fileio.open(
os.path.join(self.artifact.uri, DATA_FILENAME), "wb"
) as f:
save_npz(f, mat)
handle_input(self, data_type)
Reads spmatrix from npz file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type |
Type[Any] |
The type of the spmatrix to load. |
required |
Returns:
Type | Description |
---|---|
spmatrix |
A spmatrix object. |
Source code in zenml/integrations/scipy/materializers/sparse_materializer.py
def handle_input(self, data_type: Type[Any]) -> spmatrix:
"""Reads spmatrix from npz file.
Args:
data_type: The type of the spmatrix to load.
Returns:
A spmatrix object.
"""
super().handle_input(data_type)
with fileio.open(
os.path.join(self.artifact.uri, DATA_FILENAME), "rb"
) as f:
mat = load_npz(f)
return mat
handle_return(self, mat)
Writes a spmatrix to the artifact store as a npz file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mat |
spmatrix |
The spmatrix to write. |
required |
Source code in zenml/integrations/scipy/materializers/sparse_materializer.py
def handle_return(self, mat: spmatrix) -> None:
"""Writes a spmatrix to the artifact store as a npz file.
Args:
mat: The spmatrix to write.
"""
super().handle_return(mat)
with fileio.open(
os.path.join(self.artifact.uri, DATA_FILENAME), "wb"
) as f:
save_npz(f, mat)