Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

activation intrinsics for neural networks #860

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2ff7029
start working on activations module
jalvesz Aug 13, 2024
7d1c6ad
softmax for ranks from 1 to 4
jalvesz Aug 15, 2024
c1303e7
move activations to specialfunctions, add specs
jalvesz Aug 17, 2024
f22756a
fix float constant definition
jalvesz Aug 17, 2024
b1a4180
fix float constant definition
jalvesz Aug 17, 2024
90b8de3
fix float constant definition
jalvesz Aug 17, 2024
b7c8c81
Merge branch 'fortran-lang:master' into activations
jalvesz Aug 19, 2024
1b3bf4f
update src CMakeLists
jalvesz Aug 19, 2024
f4ad250
add tests for activations
jalvesz Aug 19, 2024
9d7eb7c
add tests for sigmoid and gelu
jalvesz Aug 20, 2024
5727921
missing module procedure
jalvesz Aug 20, 2024
2ed7626
missing interface and change of kind definition for elemental module …
jalvesz Aug 20, 2024
f1acf1e
add SiLU activation
jalvesz Aug 21, 2024
230bea9
Merge branch 'fortran-lang:master' into activations
jalvesz Aug 21, 2024
dd7125d
Merge branch 'fortran-lang:master' into activations
jalvesz Sep 15, 2024
b137b36
Merge branch 'fortran-lang:master' into activations
jalvesz Sep 18, 2024
bc2bf5a
Merge branch 'fortran-lang:master' into activations
jalvesz Sep 24, 2024
5c47bf0
add any rank support for softmax and logsoftmax
jalvesz Sep 29, 2024
8f0cd69
Merge branch 'fortran-lang:master' into activations
jalvesz Oct 26, 2024
1a2245a
Merge branch 'activations' of https://github.com/jalvesz/stdlib into …
jalvesz Oct 26, 2024
5d0419e
homogenize arguments
jalvesz Oct 30, 2024
21851d0
add selu activation
jalvesz Dec 21, 2024
ef6e3e6
Merge branch 'activations' of https://github.com/jalvesz/stdlib into …
jalvesz Dec 22, 2024
1914e78
Add SELU documentation
jalvesz Dec 22, 2024
4c1afde
add tests
jalvesz Dec 23, 2024
bccbdd4
examples
jalvesz Dec 23, 2024
9b4ed49
fix relu example
jalvesz Dec 23, 2024
564c99c
fix tests
jalvesz Dec 23, 2024
9e9b28b
improve specs
jalvesz Dec 23, 2024
14af3f9
examples bugfix
jalvesz Dec 23, 2024
3789518
replace ifs with merge
jalvesz Dec 24, 2024
b36b143
Merge branch 'fortran-lang:master' into activations
jalvesz Dec 24, 2024
eedfad7
Merge branch 'fortran-lang:master' into activations
jalvesz Dec 26, 2024
2cba1ee
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 2, 2025
8dc0654
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 3, 2025
9e0f026
Merge branch 'activations' of https://github.com/jalvesz/stdlib into …
jalvesz Jan 3, 2025
cdde132
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 5, 2025
4363271
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 17, 2025
f06ab3b
Merge branch 'activations' of https://github.com/jalvesz/stdlib into …
jalvesz Jan 18, 2025
e483325
add leaky relu activation
jalvesz Jan 18, 2025
20ecd43
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 29, 2025
d5cfa36
Merge branch 'fortran-lang:master' into activations
jalvesz Jan 30, 2025
1c3fbda
Merge branch 'fortran-lang:master' into activations
jalvesz Feb 10, 2025
259360f
Merge branch 'fortran-lang:master' into activations
jalvesz Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
765 changes: 765 additions & 0 deletions doc/specs/stdlib_specialfunctions_activations.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions example/specialfunctions_activations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ADD_EXAMPLE(elu)
ADD_EXAMPLE(gaussian)
ADD_EXAMPLE(gelu)
ADD_EXAMPLE(leaky_relu)
ADD_EXAMPLE(relu)
ADD_EXAMPLE(selu)
ADD_EXAMPLE(silu)
ADD_EXAMPLE(softmax)
ADD_EXAMPLE(logsoftmax)
ADD_EXAMPLE(softplus)
ADD_EXAMPLE(step)
13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_elu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_elu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: elu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = elu( x , 1.0 )
print *, y
end program example_elu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_gaussian.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_gaussian
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: gaussian
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = gaussian( x )
print *, y
end program example_gaussian

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_gelu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_gelu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: gelu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = gelu( x )
print *, y
end program example_gelu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_leaky_relu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_gelu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: leaky_relu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = leaky_relu( x , 0.1_sp )
print *, y
end program example_gelu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_logsoftmax.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_logsoftmax
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: logsoftmax
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = logsoftmax( x )
print *, y
end program example_logsoftmax

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_relu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_relu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: relu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = relu( x )
print *, y
end program example_relu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_selu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_selu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: selu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = selu( x )
print *, y
end program example_selu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_silu.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_silu
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: silu
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = silu( x )
print *, y
end program example_silu

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_softmax.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_softmax
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: softmax
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = softmax( x )
print *, y
end program example_softmax

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_softplus.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_softplus
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: softplus
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = softplus( x )
print *, y
end program example_softplus

13 changes: 13 additions & 0 deletions example/specialfunctions_activations/example_step.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program example_step
use stdlib_kinds, only: sp
use stdlib_math, only: linspace
use stdlib_specialfunctions, only: step
implicit none
integer, parameter :: n = 10
real(sp) :: x(n), y(n)

x = linspace(-2._sp, 2._sp, n)
y = step( x )
print *, y
end program example_step

23 changes: 23 additions & 0 deletions include/common.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ ${prefix + joinstr.join([line.strip() for line in txt.split("\n")]) + suffix}$
#:endif
#:enddef

#! Brace enclosed, comma separated Fortran expressions for a shape.
#!
#! It defines an output variable with the same shape as the input variable.
#!
#! Args:
#! varname (str): Name of the variable to be used as origin
#! origrank (int): Rank of the original variable
#!
#! Returns:
#! Shape expression enclosed in braces, so that it can be used as suffix to
#! define array shapes in declarations.
#!
#:def shape(varname, origrank)
#:assert origrank > 0
#:if origrank > 1
#:call join_lines(joinstr=", ", prefix="(", suffix=")")
#:for i in range(1, origrank+1)
size(${varname}$, ${i}$)
#:endfor
#:endcall
#:endif
#:enddef


#! Generates a routine name from a generic name, rank, type and kind
#!
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ set(fppFiles
stdlib_sparse_conversion.fypp
stdlib_sparse_kinds.fypp
stdlib_sparse_spmv.fypp
stdlib_specialfunctions_activations.fypp
stdlib_specialfunctions_gamma.fypp
stdlib_specialfunctions.fypp
stdlib_stats.fypp
stdlib_stats_corr.fypp
stdlib_stats_cov.fypp
Expand Down Expand Up @@ -116,7 +118,6 @@ set(SRC
stdlib_system_subprocess.F90
stdlib_system.F90
stdlib_sparse.f90
stdlib_specialfunctions.f90
stdlib_specialfunctions_legendre.f90
stdlib_quadrature_gauss.f90
stdlib_stringlist_type.f90
Expand Down
34 changes: 0 additions & 34 deletions src/stdlib_specialfunctions.f90

This file was deleted.

Loading
Loading