Skip to content

Commit

Permalink
chore: start fixing mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisborn committed May 23, 2024
1 parent b32f188 commit 2ea2ccc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 12 additions & 8 deletions src/gt4sd/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from __future__ import annotations

import collections
from collections.abc import Hashable
import logging
import os
import shutil
Expand Down Expand Up @@ -233,7 +233,7 @@ def sample(self, number_of_items: int = 100) -> Iterator[S]:
try:
valid_item = self.configuration.validate_item(item)
# check if sample is hashable
if not isinstance(item, collections.Hashable):
if not isinstance(item, Hashable):
yield valid_item
item_set.add(str(index))
else:
Expand Down Expand Up @@ -623,9 +623,11 @@ def save_version_from_training_pipeline_arguments(
target_version,
)
filepaths_mapping = {
filename: source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
filename: (
source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
)
for filename, source_filepath in filepaths_mapping.items()
}
logger.info(f"Saving artifacts into {target_path}...")
Expand Down Expand Up @@ -713,9 +715,11 @@ def upload_version_from_training_pipeline_arguments(

# mapping between filenames and paths for a version.
filepaths_mapping = {
filename: source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
filename: (
source_filepath
if os.path.exists(source_filepath)
else os.path.join(source_missing_path, filename)
)
for filename, source_filepath in filepaths_mapping.items()
}

Expand Down
8 changes: 3 additions & 5 deletions src/gt4sd/frameworks/cgcnn/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import logging
import os
import random
from typing import Any, Callable, List, Tuple, Union
from typing import Any, Callable, List, Tuple, Union, Optional

import numpy as np
import torch
Expand All @@ -49,7 +49,7 @@ def get_train_val_test_loader(
dataset: torch.utils.data.Dataset,
collate_fn: Callable[[List[Any]], Any] = default_collate,
batch_size: int = 64,
train_ratio: float = None,
train_ratio: Optional[float] = None,
val_ratio: float = 0.1,
test_ratio: float = 0.1,
return_test: bool = False,
Expand Down Expand Up @@ -241,9 +241,7 @@ def expand(self, distances: np.ndarray) -> np.ndarray:
Expanded distance matrix with the last dimension of length
len(self.filter).
"""
return np.exp(
-((distances[..., np.newaxis] - self.filter) ** 2) / self.var**2
)
return np.exp(-((distances[..., np.newaxis] - self.filter) ** 2) / self.var**2)


class AtomInitializer:
Expand Down

0 comments on commit 2ea2ccc

Please sign in to comment.