From 3f28e3c1a2379c17382fc2a411f76f1ae678500f Mon Sep 17 00:00:00 2001 From: Dousery Date: Sat, 7 Jun 2025 23:23:55 +0300 Subject: [PATCH] docs: Add docstrings and type hints via Dousery Applied 3 improvements: - docstring: Added docstring for class 'TensorboardLogger' - docstring: Added comprehensive docstring for function '__init__' - docstring: Added comprehensive docstring for function 'set_step' Generated by Dousery for better code documentation. --- mambavision/tensorboard.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/mambavision/tensorboard.py b/mambavision/tensorboard.py index 50de85c..e5e40d1 100644 --- a/mambavision/tensorboard.py +++ b/mambavision/tensorboard.py @@ -2,12 +2,43 @@ from tensorboardX import SummaryWriter class TensorboardLogger(object): - def __init__(self, log_dir): + """Logs data to TensorBoard. + + Attributes: + writer: SummaryWriter instance used for logging. + step: Current step in the training process. + """ +def __init__(self, log_dir: str): + """Initializes a SummaryWriter for tensorboard logging. + + Args: + log_dir (str): The directory where the logs will be written. + + Returns: + None + + Raises: + None + """ self.writer = SummaryWriter(logdir=log_dir) self.step = 0 - def set_step(self, step=None): +def set_step(self, step: int = None) -> None: + """Sets the step value. If no step is provided, increments the current step. + + Args: + step (int, optional): The new step value. If None, the current step is incremented. Defaults to None. + + Returns: + None. + + Raises: + TypeError: If step is provided and is not an integer. + + """ if step is not None: + if not isinstance(step, int): + raise TypeError("Step must be an integer or None.") self.step = step else: self.step += 1