Impliment layer abstract class

This commit is contained in:
Koshin S Hegde 2024-05-08 16:39:22 +05:30
parent 6f855c426d
commit c09dc9f7ec
2 changed files with 36 additions and 0 deletions

0
src/.gitkeep Normal file
View File

36
src/layer.py Normal file
View File

@ -0,0 +1,36 @@
import numpy as np
from abc import ABC, abstractmethod
class Layer(ABC):
@abstractmethod
def forward(self, x: np.ndarray) -> np.ndarray:
"""
x = inputs
if should_cache = True,
additional caching will be done.
Set this to true and then call forward right before calling backward
"""
@property
@abstractmethod
def parameters(self) -> tuple[np.ndarray, ...]:
"""
Returns the different parameters.
The order is defined as per the sub class's convinience
"""
@parameters.setter
@abstractmethod
def parameters(self, parameters: tuple[np.ndarray, ...]) -> None:
"""
Write to parameters property
"""
@abstractmethod
def d_output_wrt_parameters(self, inputs: np.ndarray) -> tuple[np.ndarray, ...]:
pass
@abstractmethod
def d_output_wrt_inputs(self) -> np.ndarray:
pass