<filename>Test/AddLayer.py
import numpy as np
import matplotlib.pylab as plt
from MulLayer import MulLayer

class AddLayer:
        def __init__ (self):
                pass
        
        def forward(self, x, y):
                out = x + y
                return out

        def backward(self, dout):
                dx = dout * 1
                dy = dout * 1
                return dx,dy


def test_add_layer():
        apple = 100
        apple_num = 2
        orange = 150
        orange_num = 3
        tax = 1.1


        mul_apple_layer = MulLayer()
        mul_orange_layer = MulLayer()
        add_apple_orange_layer = AddLayer()
        mul_tax_layer = MulLayer()

        apple_price = mul_apple_layer.forward( apple, apple_num)
        orange_price = mul_orange_layer.forward( orange, orange_num)
        all_price = add_apple_orange_layer.forward( apple_price, orange_price)
        price = mul_tax_layer.forward( all_price, tax)


        dprice = 1
        dall_price, dtax = mul_tax_layer.backward( dprice)
        dapple_price, dorange_price = add_apple_orange_layer.backward(dall_price)
        dorange, dorange_num = mul_orange_layer.backward(dorange_price)
        dapple, dapple_num = mul_apple_layer.backward( dapple_price)

        print("price=", price)
        print(dapple_num, dapple, dorange, dorange_num, dtax)



<filename>Test/AddLayer.py
import numpy as np
import matplotlib.pylab as plt
from MulLayer import MulLayer

class AddLayer:
        def __init__ (self):
                pass
        
        def forward(self, x, y):
                out = x + y
                return out

        def backward(self, dout):
                dx = dout * 1
                dy = dout * 1
                return dx,dy


def test_add_layer():
        apple = 100
        apple_num = 2
        orange = 150
        orange_num = 3
        tax = 1.1


        mul_apple_layer = MulLayer()
        mul_orange_layer = MulLayer()
        add_apple_orange_layer = AddLayer()
        mul_tax_layer = MulLayer()

        apple_price = mul_apple_layer.forward( apple, apple_num)
        orange_price = mul_orange_layer.forward( orange, orange_num)
        all_price = add_apple_orange_layer.forward( apple_price, orange_price)
        price = mul_tax_layer.forward( all_price, tax)


        dprice = 1
        dall_price, dtax = mul_tax_layer.backward( dprice)
        dapple_price, dorange_price = add_apple_orange_layer.backward(dall_price)
        dorange, dorange_num = mul_orange_layer.backward(dorange_price)
        dapple, dapple_num = mul_apple_layer.backward( dapple_price)

        print("price=", price)
        print(dapple_num, dapple, dorange, dorange_num, dtax)


