From a5e29a51399441b8fec2999aaff1f70b825d0ba7 Mon Sep 17 00:00:00 2001 From: bmosk54 <34865867+bmosk54@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:26:27 -0700 Subject: [PATCH 1/2] Fixed collections issue --- bindsnet/datasets/collate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindsnet/datasets/collate.py b/bindsnet/datasets/collate.py index 3f9c1211..1a30cbb6 100644 --- a/bindsnet/datasets/collate.py +++ b/bindsnet/datasets/collate.py @@ -11,7 +11,8 @@ import torch from torch.utils.data._utils import collate as pytorch_collate - +collections.Mapping = collections.abc.Mapping +collections.Sequence = collections.abc.Sequence def safe_worker_check(): # language=rst From c4c213a3a213c19edbd0ab1fb1950d2cea720dc6 Mon Sep 17 00:00:00 2001 From: bmosk54 <34865867+bmosk54@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:45:21 -0700 Subject: [PATCH 2/2] Updated to collections.abc --- bindsnet/datasets/collate.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bindsnet/datasets/collate.py b/bindsnet/datasets/collate.py index 1a30cbb6..d84263f3 100644 --- a/bindsnet/datasets/collate.py +++ b/bindsnet/datasets/collate.py @@ -7,12 +7,11 @@ Modifications exist to have [time, batch, n_0, ... n_k] instead of batch in dimension 0. """ -import collections +import collections.abc import torch from torch.utils.data._utils import collate as pytorch_collate -collections.Mapping = collections.abc.Mapping -collections.Sequence = collections.abc.Sequence + def safe_worker_check(): # language=rst @@ -75,11 +74,11 @@ def time_aware_collate(batch): return torch.tensor(batch, dtype=torch.float64) elif isinstance(elem, int): return torch.tensor(batch) - elif isinstance(elem, collections.Mapping): + elif isinstance(elem, collections.abc.Mapping): return {key: time_aware_collate([d[key] for d in batch]) for key in elem} elif isinstance(elem, tuple) and hasattr(elem, "_fields"): # namedtuple return elem_type(*(time_aware_collate(samples) for samples in zip(*batch))) - elif isinstance(elem, collections.Sequence): + elif isinstance(elem, collections.abc.Sequence): transposed = zip(*batch) return [time_aware_collate(samples) for samples in transposed]