Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate and reduce update frequency (#98)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.284 → v0.0.290](astral-sh/ruff-pre-commit@v0.0.284...v0.0.290)
- [github.com/psf/black: 23.7.0 → 23.9.1](psf/black@23.7.0...23.9.1)

* use isinstance instead of type

* set pre-commit auto-update schedule to monthly

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: niksirbi <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and niksirbi authored Sep 22, 2023
1 parent e6d5819 commit 73e28aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
exclude: '^neuralplayground/experiments/.*_20.*|^documents/'
# Configuring https://pre-commit.ci/ bot
ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -14,10 +17,10 @@ repos:
- id: trailing-whitespace
exclude: 'README.md'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.0.290
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def f_p(self, p):
"""
activation = (
[utils.leaky_relu(torch.clamp(p_f, min=-1, max=1)) for p_f in p]
if type(p) is list
if isinstance(p, list)
else utils.leaky_relu(torch.clamp(p, min=-1, max=1))
)
return activation
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def __init__(self, in_dim, out_dim, activation=(torch.nn.functional.elu, None),
super(MLP, self).__init__()
# Check if this network consists of module: are input and output dimensions lists? If not, make them
# (but remember it wasn't)
if type(in_dim) is list:
if isinstance(in_dim, list):
self.is_list = True
else:
in_dim = [in_dim]
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def set_weights(self, from_layer, value):
value: value to set weights to
"""
# If single value is provided: copy it for each module
if type(value) is not list:
if not isinstance(value, list):
input_value = [value for n in range(self.N)]
else:
input_value = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def squared_error(value, target):
Tensor of mean squared errors
"""
# Return torch MSE loss
if type(value) is list:
if isinstance(value, list):
loss = [0.5 * torch.sum(torch.nn.MSELoss(reduction="none")(value[i], target[i]), dim=-1) for i in range(len(value))]
else:
loss = 0.5 * torch.sum(torch.nn.MSELoss(reduction="none")(value, target), dim=-1)
Expand All @@ -97,7 +97,7 @@ def cross_entropy(value, target):
Tensor of binary cross entropies
"""
# Return torch BCE loss
if type(value) is list:
if isinstance(value, list):
loss = [torch.nn.CrossEntropyLoss(reduction="none")(val, targ) for val, targ in zip(value, target)]
else:
loss = torch.nn.CrossEntropyLoss(reduction="none")(value, target)
Expand Down

0 comments on commit 73e28aa

Please sign in to comment.