add_scalar Module Function

module function add_scalar(a, b) result(c)

Add a scalar to an autodiff array

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
real(kind=real32), intent(in) :: b

Return Value type(array_type), pointer


Source Code

  module function add_scalar(a, b) result(c)
    !! Add a scalar to an autodiff array
    implicit none
    class(array_type), intent(in), target :: a
    real(real32), intent(in) :: b
    type(array_type), pointer :: c

    c => a%create_result()
    c%val = a%val + b

    c%get_partial_left => get_partial_add
    c%get_partial_left_val => get_partial_add_val
    if(a%requires_grad)then
       c%requires_grad = .true.
       c%is_forward = a%is_forward
       c%operation = 'add'
       c%left_operand => a
       c%owns_left_operand = a%is_temporary
    end if
  end function add_scalar