Skip to content

Commit 2ed7626

Browse files
committed
missing interface and change of kind definition for elemental module functions
1 parent 5727921 commit 2ed7626

File tree

2 files changed

+102
-56
lines changed

2 files changed

+102
-56
lines changed

src/stdlib_specialfunctions.fypp

+62-18
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ module stdlib_specialfunctions
3535
!!
3636
!! gaussian function
3737
#:for rk, rt in REAL_KINDS_TYPES
38-
elemental ${rt}$ module function gaussian_${rk}$( x ) result( y )
38+
elemental module function gaussian_${rk}$( x ) result( y )
3939
${rt}$, intent(in) :: x
40+
${rt}$ :: y
4041
end function
4142
#:endfor
4243
end interface
@@ -47,8 +48,9 @@ module stdlib_specialfunctions
4748
!!
4849
!! gradient of the gaussian function
4950
#:for rk, rt in REAL_KINDS_TYPES
50-
elemental ${rt}$ module function gaussian_grad_${rk}$( x ) result( y )
51+
elemental module function gaussian_grad_${rk}$( x ) result( y )
5152
${rt}$, intent(in) :: x
53+
${rt}$ :: y
5254
end function
5355
#:endfor
5456
end interface
@@ -59,9 +61,10 @@ module stdlib_specialfunctions
5961
!!
6062
!! exponential linear unit function
6163
#:for rk, rt in REAL_KINDS_TYPES
62-
elemental ${rt}$ module function elu_${rk}$( x , a ) result( y )
64+
elemental module function elu_${rk}$( x , a ) result( y )
6365
${rt}$, intent(in) :: x
6466
${rt}$, intent(in) :: a
67+
${rt}$ :: y
6568
end function
6669
#:endfor
6770
end interface
@@ -72,9 +75,10 @@ module stdlib_specialfunctions
7275
!!
7376
!! gradient of the exponential linear unit function
7477
#:for rk, rt in REAL_KINDS_TYPES
75-
elemental ${rt}$ module function elu_grad_${rk}$( x , a ) result( y )
78+
elemental module function elu_grad_${rk}$( x , a ) result( y )
7679
${rt}$, intent(in) :: x
7780
${rt}$, intent(in) :: a
81+
${rt}$ :: y
7882
end function
7983
#:endfor
8084
end interface
@@ -85,8 +89,9 @@ module stdlib_specialfunctions
8589
!!
8690
!! Rectified linear unit function
8791
#:for rk, rt in REAL_KINDS_TYPES
88-
elemental ${rt}$ module function relu_${rk}$( x ) result( y )
92+
elemental module function relu_${rk}$( x ) result( y )
8993
${rt}$, intent(in) :: x
94+
${rt}$ :: y
9095
end function
9196
#:endfor
9297
end interface
@@ -97,8 +102,9 @@ module stdlib_specialfunctions
97102
!!
98103
!! Gradient rectified linear unit function
99104
#:for rk, rt in REAL_KINDS_TYPES
100-
elemental ${rt}$ module function relu_grad_${rk}$( x ) result( y )
105+
elemental module function relu_grad_${rk}$( x ) result( y )
101106
${rt}$, intent(in) :: x
107+
${rt}$ :: y
102108
end function
103109
#:endfor
104110
end interface
@@ -109,8 +115,9 @@ module stdlib_specialfunctions
109115
!!
110116
!! Gaussian error linear unit function
111117
#:for rk, rt in REAL_KINDS_TYPES
112-
elemental ${rt}$ module function gelu_${rk}$( x ) result( y )
118+
elemental module function gelu_${rk}$( x ) result( y )
113119
${rt}$, intent(in) :: x
120+
${rt}$ :: y
114121
end function
115122
#:endfor
116123
end interface
@@ -121,8 +128,9 @@ module stdlib_specialfunctions
121128
!!
122129
!! Gradient of the gaussian error linear unit function
123130
#:for rk, rt in REAL_KINDS_TYPES
124-
elemental ${rt}$ module function gelu_grad_${rk}$( x ) result( y )
131+
elemental module function gelu_grad_${rk}$( x ) result( y )
125132
${rt}$, intent(in) :: x
133+
${rt}$ :: y
126134
end function
127135
#:endfor
128136
end interface
@@ -133,8 +141,9 @@ module stdlib_specialfunctions
133141
!!
134142
!! Approximated gaussian error linear unit function
135143
#:for rk, rt in REAL_KINDS_TYPES
136-
elemental ${rt}$ module function gelu_approx_${rk}$( x ) result( y )
144+
elemental module function gelu_approx_${rk}$( x ) result( y )
137145
${rt}$, intent(in) :: x
146+
${rt}$ :: y
138147
end function
139148
#:endfor
140149
end interface
@@ -145,8 +154,9 @@ module stdlib_specialfunctions
145154
!!
146155
!! Gradient of the approximated gaussian error linear unit function
147156
#:for rk, rt in REAL_KINDS_TYPES
148-
elemental ${rt}$ module function gelu_approx_grad_${rk}$( x ) result( y )
157+
elemental module function gelu_approx_grad_${rk}$( x ) result( y )
149158
${rt}$, intent(in) :: x
159+
${rt}$ :: y
150160
end function
151161
#:endfor
152162
end interface
@@ -157,8 +167,9 @@ module stdlib_specialfunctions
157167
!!
158168
!! Sigmoid function
159169
#:for rk, rt in REAL_KINDS_TYPES
160-
elemental ${rt}$ module function sigmoid_${rk}$( x ) result( y )
170+
elemental module function sigmoid_${rk}$( x ) result( y )
161171
${rt}$, intent(in) :: x
172+
${rt}$ :: y
162173
end function
163174
#:endfor
164175
end interface
@@ -169,8 +180,9 @@ module stdlib_specialfunctions
169180
!!
170181
!! Gradient of the sigmoid function
171182
#:for rk, rt in REAL_KINDS_TYPES
172-
elemental ${rt}$ module function sigmoid_grad_${rk}$( x ) result( y )
183+
elemental module function sigmoid_grad_${rk}$( x ) result( y )
173184
${rt}$, intent(in) :: x
185+
${rt}$ :: y
174186
end function
175187
#:endfor
176188
end interface
@@ -181,8 +193,9 @@ module stdlib_specialfunctions
181193
!!
182194
!! Step function
183195
#:for rk, rt in REAL_KINDS_TYPES
184-
elemental ${rt}$ module function step_${rk}$( x ) result( y )
196+
elemental module function step_${rk}$( x ) result( y )
185197
${rt}$, intent(in) :: x
198+
${rt}$ :: y
186199
end function
187200
#:endfor
188201
end interface
@@ -193,13 +206,40 @@ module stdlib_specialfunctions
193206
!!
194207
!! Gradient of the step function
195208
#:for rk, rt in REAL_KINDS_TYPES
196-
elemental ${rt}$ module function step_grad_${rk}$( x ) result( y )
209+
elemental module function step_grad_${rk}$( x ) result( y )
197210
${rt}$, intent(in) :: x
211+
${rt}$ :: y
198212
end function
199213
#:endfor
200214
end interface
201215
public :: step_grad
202216

217+
interface tanh
218+
!! Version: experimental
219+
!!
220+
!! gaussian function
221+
#:for rk, rt in REAL_KINDS_TYPES
222+
elemental module function tanh_${rk}$( x ) result( y )
223+
${rt}$, intent(in) :: x
224+
${rt}$ :: y
225+
end function
226+
#:endfor
227+
end interface
228+
public :: tanh
229+
230+
interface tanh_grad
231+
!! Version: experimental
232+
!!
233+
!! gradient of the gaussian function
234+
#:for rk, rt in REAL_KINDS_TYPES
235+
elemental module function tanh_grad_${rk}$( x ) result( y )
236+
${rt}$, intent(in) :: x
237+
${rt}$ :: y
238+
end function
239+
#:endfor
240+
end interface
241+
public :: tanh_grad
242+
203243
interface Softmax
204244
!! Version: experimental
205245
!!
@@ -261,8 +301,9 @@ module stdlib_specialfunctions
261301
!!
262302
!! Softplus function
263303
#:for rk, rt in REAL_KINDS_TYPES
264-
elemental ${rt}$ module function Softplus_${rk}$( x ) result( y )
304+
elemental module function Softplus_${rk}$( x ) result( y )
265305
${rt}$, intent(in) :: x
306+
${rt}$ :: y
266307
end function
267308
#:endfor
268309
end interface
@@ -273,8 +314,9 @@ module stdlib_specialfunctions
273314
!!
274315
!! Gradient of the softplus function
275316
#:for rk, rt in REAL_KINDS_TYPES
276-
elemental ${rt}$ module function Softplus_grad_${rk}$( x ) result( y )
317+
elemental module function Softplus_grad_${rk}$( x ) result( y )
277318
${rt}$, intent(in) :: x
319+
${rt}$ :: y
278320
end function
279321
#:endfor
280322
end interface
@@ -286,8 +328,9 @@ module stdlib_specialfunctions
286328
!! Fast approximation of the tanh function
287329
!! Source: https://fortran-lang.discourse.group/t/fastgpt-faster-than-pytorch-in-300-lines-of-fortran/5385/31
288330
#:for rk, rt in REAL_KINDS_TYPES
289-
elemental ${rt}$ module function ftanh_${rk}$( x ) result( y )
331+
elemental module function ftanh_${rk}$( x ) result( y )
290332
${rt}$, intent(in) :: x
333+
${rt}$ :: y
291334
end function
292335
#:endfor
293336
end interface
@@ -299,8 +342,9 @@ module stdlib_specialfunctions
299342
!! Fast approximation of the erf function
300343
!! Source: https://fortran-lang.discourse.group/t/fastgpt-faster-than-pytorch-in-300-lines-of-fortran/5385/31
301344
#:for rk, rt in REAL_KINDS_TYPES
302-
elemental ${rt}$ module function ferf_${rk}$( x ) result( y )
345+
elemental module function ferf_${rk}$( x ) result( y )
303346
${rt}$, intent(in) :: x
347+
${rt}$ :: y
304348
end function
305349
#:endfor
306350
end interface

0 commit comments

Comments
 (0)