scalar_power Module Function

module function scalar_power(scalar, a) result(c)

Arguments

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

Return Value type(array_type), pointer


Source Code

  module function scalar_power(scalar, a) result(c)
    implicit none
    real(real32), intent(in) :: scalar
    class(array_type), intent(in), target :: a
    type(array_type), pointer :: c
    type(array_type), pointer :: b_array

    c => a%create_result()
    c%val = scalar ** a%val

    c%get_partial_left => get_partial_power_base
    if(a%requires_grad)then
       c%requires_grad = .true.
       c%is_forward = a%is_forward
       c%operation = 'scalar_power'
       c%right_operand => a
       c%owns_right_operand = a%is_temporary
    end if
    allocate(b_array)
    b_array%is_scalar = .true.
    b_array%is_sample_dependent = .false.
    b_array%requires_grad = .false.
    call b_array%allocate(array_shape=[1, 1])
    b_array%val(1, 1) = scalar
    c%left_operand => b_array
    c%owns_left_operand = .true.

  end function scalar_power