Skip to content

Commit

Permalink
added target attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Apr 1, 2024
1 parent 59961f2 commit 66c6121
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION "3.14" )

project(FORWARDDIFF LANGUAGES Fortran VERSION "0.1.0")
project(FORWARDDIFF LANGUAGES Fortran VERSION "0.1.1")
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules")

add_subdirectory(src)
Expand Down
16 changes: 8 additions & 8 deletions src/forwarddiff_derivative.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ function derivative_sig(x) result(res)

function gradient_sig(x) result(res)
import :: dual
type(dual), intent(in) :: x(:)
type(dual), target, intent(in) :: x(:)
type(dual) :: res
end function

subroutine jacobian_sig(x, f)
import :: dual
type(dual), intent(in) :: x(:)
type(dual), intent(out) :: f(:)
type(dual), target, intent(in) :: x(:)
type(dual), target, intent(out) :: f(:)
end subroutine
end interface

Expand All @@ -46,7 +46,7 @@ subroutine gradient(fcn, x, f, dfdx, err)
real(wp), intent(in) :: x(:)
real(wp), intent(out) :: f
real(wp), intent(out) :: dfdx(:)
character(:), allocatable :: err
character(:), allocatable, intent(out) :: err

type(dual) :: xx(size(x))
type(dual) :: ff
Expand Down Expand Up @@ -87,7 +87,7 @@ subroutine jacobian(fcn, x, f, dfdx, jt, bandwidth, blocksize, err)
integer, optional, intent(in) :: jt
integer, optional, intent(in) :: bandwidth
integer, optional, intent(in) :: blocksize
character(:), allocatable :: err
character(:), allocatable, intent(out) :: err

integer :: jt_

Expand Down Expand Up @@ -130,7 +130,7 @@ subroutine jacobian_dense(fcn, x, f, dfdx, err)
real(wp), intent(in) :: x(:)
real(wp), intent(out) :: f(:)
real(wp), intent(out) :: dfdx(:,:)
character(:), allocatable :: err
character(:), allocatable, intent(out) :: err

type(dual) :: xx(size(x))
type(dual) :: ff(size(x))
Expand Down Expand Up @@ -176,7 +176,7 @@ subroutine jacobian_banded(fcn, x, f, dfdx, bandwidth, err)
real(wp), intent(out) :: f(:)
real(wp), intent(out) :: dfdx(:,:)
integer, intent(in) :: bandwidth
character(:), allocatable :: err
character(:), allocatable, intent(out) :: err

type(dual) :: xx(size(x))
type(dual) :: ff(size(x))
Expand Down Expand Up @@ -266,7 +266,7 @@ subroutine jacobian_blockdiagonal(fcn, x, f, dfdx, blocksize, err)
real(wp), intent(out) :: f(:)
real(wp), intent(out) :: dfdx(:,:)
integer, intent(in) :: blocksize
character(:), allocatable :: err
character(:), allocatable, intent(out) :: err

type(dual) :: xx(size(x))
type(dual) :: ff(size(x))
Expand Down
4 changes: 2 additions & 2 deletions test/fypp_example.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ contains
#:if NAME == 'dual'
use forwarddiff
#:endif
${TYPE1}$, intent(in) :: u(:)
${TYPE1}$, intent(out) :: du(:)
${TYPE1}$, target, intent(in) :: u(:)
${TYPE1}$, target, intent(out) :: du(:)

${TYPE1}$ :: tmp1, tmp2

Expand Down
12 changes: 6 additions & 6 deletions test/test_forwarddiff.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ function func_intrinsics2(x) result(res)

function func_grad1(x) result(res)
use forwarddiff
type(dual), intent(in) :: x(:)
type(dual), target, intent(in) :: x(:)
type(dual) :: res
res = x(1)*x(1)*x(2) + x(1) + x(2)
end function

function func_grad2(x) result(res)
use forwarddiff
type(dual), intent(in) :: x(:)
type(dual), target, intent(in) :: x(:)
type(dual) :: res
res = sum(x*3.14_wp)
end function
Expand Down Expand Up @@ -132,8 +132,8 @@ subroutine test_jacobian()

subroutine rhs_rober_dual(u, du)
use forwarddiff
type(dual), intent(in) :: u(:)
type(dual), intent(out) :: du(:)
type(dual), target, intent(in) :: u(:)
type(dual), target, intent(out) :: du(:)

real(wp), parameter :: k1 = 0.04_wp, &
k2 = 3.0e7_wp, &
Expand All @@ -146,8 +146,8 @@ subroutine rhs_rober_dual(u, du)
end subroutine

subroutine rhs_rober(u, du)
real(wp), intent(in) :: u(:)
real(wp), intent(out) :: du(:)
real(wp), target, intent(in) :: u(:)
real(wp), target, intent(out) :: du(:)

real(wp), parameter :: k1 = 0.04_wp, &
k2 = 3.0e7_wp, &
Expand Down
12 changes: 6 additions & 6 deletions test/test_sparse.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ subroutine test_banded()

subroutine rhs_banded_dual(u, du)
use forwarddiff
type(dual), intent(in) :: u(:)
type(dual), intent(out) :: du(:)
type(dual), target, intent(in) :: u(:)
type(dual), target, intent(out) :: du(:)
integer :: i

du(1) = 3.0_wp*u(2) - u(1)
Expand Down Expand Up @@ -139,8 +139,8 @@ subroutine test_blockdiagonal2()

subroutine rhs_blocked1_dual(u, du)
use forwarddiff
type(dual), intent(in) :: u(:)
type(dual), intent(out) :: du(:)
type(dual), target, intent(in) :: u(:)
type(dual), target, intent(out) :: du(:)
integer :: i

du(1) = u(1) + u(2)*u(1)
Expand All @@ -156,8 +156,8 @@ subroutine rhs_blocked1_dual(u, du)

subroutine rhs_blocked2_dual(u, du)
use forwarddiff
type(dual), intent(in) :: u(:)
type(dual), intent(out) :: du(:)
type(dual), target, intent(in) :: u(:)
type(dual), target, intent(out) :: du(:)
integer :: i

du(1) = u(1) + u(2)*u(1)
Expand Down

0 comments on commit 66c6121

Please sign in to comment.