Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: infer input size of forward and LSTM layers #808

Merged
merged 9 commits into from
May 29, 2024
Prev Previous commit
Next Next commit
docs: remove pointless docstrings
lars-reimann committed May 29, 2024
commit 82322a9fb82fa41acfd34e879b157ace8db0c4a6
58 changes: 0 additions & 58 deletions src/safeds/ml/nn/layers/_convolutional2d_layer.py
Original file line number Diff line number Diff line change
@@ -191,14 +191,6 @@ def _set_input_size(self, input_size: int | ModelImageSize) -> None:
self._output_size = None

def __hash__(self) -> int:
"""
Return a deterministic hash value for this convolutional 2d layer.

Returns
-------
hash:
the hash value
"""
return _structural_hash(
self._output_channel,
self._kernel_size,
@@ -209,19 +201,6 @@ def __hash__(self) -> int:
)

def __eq__(self, other: object) -> bool:
"""
Compare two convolutional 2d layer.

Parameters
----------
other:
The convolutional 2d layer to compare to.

Returns
-------
equals:
Whether the two convolutional 2d layer are the same.
"""
if not isinstance(other, Convolutional2DLayer) or isinstance(other, ConvolutionalTranspose2DLayer):
return NotImplemented
return (self is other) or (
@@ -234,14 +213,6 @@ def __eq__(self, other: object) -> bool:
)

def __sizeof__(self) -> int:
"""
Return the complete size of this object.

Returns
-------
size:
Size of this object in bytes.
"""
return (
sys.getsizeof(self._output_channel)
+ sys.getsizeof(self._kernel_size)
@@ -336,30 +307,9 @@ def output_size(self) -> ModelImageSize:
return self._output_size

def __hash__(self) -> int:
"""
Return a deterministic hash value for this convolutional transpose 2d layer.

Returns
-------
hash:
the hash value
"""
return _structural_hash(super().__hash__(), self._output_padding)

def __eq__(self, other: object) -> bool:
"""
Compare two convolutional transpose 2d layer.

Parameters
----------
other:
The convolutional transpose 2d layer to compare to.

Returns
-------
equals:
Whether the two convolutional transpose 2d layer are the same.
"""
if not isinstance(other, ConvolutionalTranspose2DLayer):
return NotImplemented
return (self is other) or (
@@ -373,12 +323,4 @@ def __eq__(self, other: object) -> bool:
)

def __sizeof__(self) -> int:
"""
Return the complete size of this object.

Returns
-------
size:
Size of this object in bytes.
"""
return sys.getsizeof(self._output_padding) + super().__sizeof__()
29 changes: 0 additions & 29 deletions src/safeds/ml/nn/layers/_flatten_layer.py
Original file line number Diff line number Diff line change
@@ -92,41 +92,12 @@ def _set_input_size(self, input_size: int | ModelImageSize) -> None:
self._output_size = None

def __hash__(self) -> int:
"""
Return a deterministic hash value for this flatten layer.

Returns
-------
hash:
the hash value
"""
return _structural_hash(self._input_size, self._output_size)

def __eq__(self, other: object) -> bool:
"""
Compare two flatten layer.

Parameters
----------
other:
The flatten layer to compare to.

Returns
-------
equals:
Whether the two flatten layer are the same.
"""
if not isinstance(other, FlattenLayer):
return NotImplemented
return (self is other) or (self._input_size == other._input_size and self._output_size == other._output_size)

def __sizeof__(self) -> int:
"""
Return the complete size of this object.

Returns
-------
size:
Size of this object in bytes.
"""
return sys.getsizeof(self._input_size) + sys.getsizeof(self._output_size)
24 changes: 0 additions & 24 deletions src/safeds/ml/nn/layers/_forward_layer.py
Original file line number Diff line number Diff line change
@@ -82,40 +82,16 @@ def _set_input_size(self, input_size: int | ModelImageSize) -> None:
self._input_size = input_size

def __hash__(self) -> int:
"""
Return a deterministic hash value for this forward layer.

Returns
-------
hash:
the hash value
"""
return _structural_hash(self._input_size, self._output_size)

def __eq__(self, other: object) -> bool:
"""
Compare two forward layer instances.

Returns
-------
equals:
'True' if input and output size are equal, 'False' otherwise.
"""
if not isinstance(other, ForwardLayer):
return NotImplemented
if self is other:
return True
return self._input_size == other._input_size and self._output_size == other._output_size

def __sizeof__(self) -> int:
"""
Return the complete size of this object.

Returns
-------
size:
Size of this object in bytes.
"""
import sys

return sys.getsizeof(self._input_size) + sys.getsizeof(self._output_size)
29 changes: 0 additions & 29 deletions src/safeds/ml/nn/layers/_pooling2d_layer.py
Original file line number Diff line number Diff line change
@@ -102,14 +102,6 @@ def _set_input_size(self, input_size: int | ModelImageSize) -> None:
self._output_size = None

def __hash__(self) -> int:
"""
Return a deterministic hash value for this pooling 2d layer.

Returns
-------
hash:
the hash value
"""
return _structural_hash(
self._strategy,
self._kernel_size,
@@ -120,19 +112,6 @@ def __hash__(self) -> int:
)

def __eq__(self, other: object) -> bool:
"""
Compare two pooling 2d layer.

Parameters
----------
other:
The pooling 2d layer to compare to.

Returns
-------
equals:
Whether the two pooling 2d layer are the same.
"""
if not isinstance(other, type(self)):
return NotImplemented
return (self is other) or (
@@ -145,14 +124,6 @@ def __eq__(self, other: object) -> bool:
)

def __sizeof__(self) -> int:
"""
Return the complete size of this object.

Returns
-------
size:
Size of this object in bytes.
"""
return (
sys.getsizeof(self._input_size)
+ sys.getsizeof(self._output_size)