@@ -35,22 +35,14 @@ elemental module function elu_${rk}$( x , a ) result ( y )
35
35
${rt}$, intent(in) :: x
36
36
${rt}$, intent(in) :: a
37
37
${rt}$ :: y
38
- if(x >= 0._${rk}$)then
39
- y = x
40
- else
41
- y = a * (exp(x) - 1._${rk}$)
42
- end if
38
+ y = merge( x , a * (exp(x) - 1._${rk}$), x >= 0._${rk}$)
43
39
end function
44
40
45
41
elemental module function elu_grad_${rk}$( x , a ) result ( y )
46
42
${rt}$, intent(in) :: x
47
43
${rt}$, intent(in) :: a
48
44
${rt}$ :: y
49
- if(x >= 0._${rk}$)then
50
- y = 1._${rk}$
51
- else
52
- y = a * exp(x)
53
- end if
45
+ y = merge( 1._${rk}$ , a * exp(x), x >= 0._${rk}$)
54
46
end function
55
47
56
48
#:endfor
@@ -68,11 +60,7 @@ end function
68
60
elemental module function relu_grad_${rk}$( x ) result( y )
69
61
${rt}$, intent(in) :: x
70
62
${rt}$ :: y
71
- if(x > 0._${rk}$)then
72
- y = 1._${rk}$
73
- else
74
- y = 0._${rk}$
75
- end if
63
+ y = merge( 1._${rk}$ , 0._${rk}$, x > 0._${rk}$)
76
64
end function
77
65
78
66
#:endfor
@@ -121,23 +109,16 @@ elemental module function selu_${rk}$( x ) result( y )
121
109
${rt}$ :: y
122
110
${rt}$, parameter :: scale = 1.0507009873554804934193349852946_${rk}$
123
111
${rt}$, parameter :: alpha = 1.6732632423543772848170429916717_${rk}$
124
- if(x > 0._${rk}$)then
125
- y = scale * x
126
- else
127
- y = scale * (alpha * exp(x) - alpha)
128
- end if
112
+ y = merge( x , alpha * exp(x) - alpha, x > 0._${rk}$)
113
+ y = scale * y
129
114
end function
130
115
131
116
elemental module function selu_grad_${rk}$( x ) result( y )
132
117
${rt}$, intent(in) :: x
133
118
${rt}$ :: y
134
119
${rt}$, parameter :: scale = 1.0507009873554804934193349852946_${rk}$
135
120
${rt}$, parameter :: alpha = 1.6732632423543772848170429916717_${rk}$
136
- if(x > 0._${rk}$)then
137
- y = scale
138
- else
139
- y = scale * alpha * exp(x)
140
- end if
121
+ y = merge( scale , scale * alpha * exp(x), x > 0._${rk}$)
141
122
end function
142
123
143
124
#:endfor
@@ -186,11 +167,7 @@ end function
186
167
elemental module function Step_${rk}$( x ) result( y )
187
168
${rt}$, intent(in) :: x
188
169
${rt}$ :: y
189
- if(x > 0._${rk}$)then
190
- y = 1._${rk}$
191
- else
192
- y = 0._${rk}$
193
- end if
170
+ y = merge( 1._${rk}$ , 0._${rk}$, x > 0._${rk}$)
194
171
end function
195
172
196
173
elemental module function Step_grad_${rk}$( x ) result( y )
@@ -360,16 +337,10 @@ elemental module function ftanh_${rk}$( x ) result( y )
360
337
${rt}$ :: y
361
338
${rt}$ :: x2, a, b
362
339
363
- if (x > 5._${rk}$) then
364
- y = 1._${rk}$
365
- elseif (x < -5._${rk}$) then
366
- y = -1._${rk}$
367
- else
368
- x2 = x*x
369
- a = x * (135135.0_${rk}$ + x2 * (17325.0_${rk}$ + x2 * (378.0_${rk}$ + x2)))
370
- b = 135135.0_${rk}$ + x2 * (62370.0_${rk}$ + x2 * (3150.0_${rk}$ + x2 * 28.0_${rk}$))
371
- y = a / b
372
- end if
340
+ x2 = x*x
341
+ a = x * (135135.0_${rk}$ + x2 * (17325.0_${rk}$ + x2 * (378.0_${rk}$ + x2)))
342
+ b = 135135.0_${rk}$ + x2 * (62370.0_${rk}$ + x2 * (3150.0_${rk}$ + x2 * 28.0_${rk}$))
343
+ y = merge( a / b , sign(1._${rk}$,x) , x2 <= 25._${rk}$ )
373
344
end function
374
345
375
346
elemental module function ferf_${rk}$( x ) result( y )
0 commit comments