Add two learnable layers together
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(in) | :: | a |
Instances of layers |
||
| class(learnable_layer_type), | intent(in) | :: | b |
Instances of layers |
Output layer
module function add_learnable(a, b) result(output) !! Add two learnable layers together implicit none ! Arguments class(learnable_layer_type), intent(in) :: a, b !! Instances of layers class(learnable_layer_type), allocatable :: output !! Output layer ! Local variables integer :: i !! Loop index output = a if(allocated(a%params).and.allocated(b%params))then if(size(a%params).ne.size(b%params))then call stop_program("add_learnable: incompatible parameter sizes") return end if do i = 1, size(a%params,1) output%params(i)%grad => null() output%params(i) = a%params(i) + b%params(i) if(associated(a%params(i)%grad).and.& associated(b%params(i)%grad))then allocate(output%params(i)%grad) output%params(i)%grad = a%params(i)%grad + & b%params(i)%grad end if end do else call stop_program("add_learnable: unallocated parameter arrays") return end if end function add_learnable