Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MolDyn
lib4neuro
Commits
60828673
Commit
60828673
authored
Dec 07, 2017
by
Martin Mrovec
Browse files
ENH: Implementation of the connection container
parent
ac48b28d
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
60828673
...
...
@@ -8,3 +8,4 @@ compilers.env
*_fun.f90
src/funit.tmp
*.swp
/Release/
src/connection_m.f90
View file @
60828673
...
...
@@ -384,12 +384,108 @@ module connection_m
!> Constructor of connection_container_t class
!! @return Instance of the class connection_container_t with nullified content
function
new_connection_container_empty
()
result
(
new_obj
)
type
(
connection_container_t
),
intent
(
out
)
::
new_obj
new_o
type
(
connection_container_t
)
::
new_obj
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
new_obj
%
content
=>
null
()
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'new_connection_container_empty'
)
#endif
end
function
new_connection_container_empty
module
procedure
::
new_connection_container_empty
!> Constructor of connection_container_t class
!! @param[in] content_in connection to be contained (type connection_t, pointer)
!! @return Pointer to the instance of the class connection_t with assigned content
function
new_connection_container_assigned
(
content_in
)
result
(
new_obj
)
class
(
connection_t
),
pointer
,
intent
(
in
)
::
content_in
type
(
connection_container_t
)
::
new_obj
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
new_obj
%
content
=>
content_in
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'new_connection_container_assigned'
)
#endif
end
function
new_connection_container_assigned
!--------------!------------------------------------------------------------------------
! Destructors !
!--------------!
!> Scalar desctructor for single instances of the class connection_container_t
subroutine
destroy_connection_container
(
this
)
type
(
connection_container_t
),
intent
(
inout
)
::
this
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
nullify
(
this
%
content
)
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'destroy_connection_container'
)
#endif
end
subroutine
destroy_connection_container
!> Array desctructor for arrays of instances of the class connection_container_t
subroutine
destroy_connection_container_array
(
this
)
type
(
connection_container_t
),
intent
(
inout
)
::
this
(:)
integer
::
i
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
do
i
=
1
,
size
(
this
)
nullify
(
this
(
i
)
%
content
)
end
do
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'destroy_connection_container_array'
)
#endif
end
subroutine
destroy_connection_container_array
!-------------------!------------------------------------------------------------------
! Getters & Setters !
!-------------------!
!> Getter for the private 'content' component
!! @return Pointer to the contained connection (type connection_t, pointer)
function
get_content_connection_container_impl
(
this
)
result
(
content
)
class
(
connection_container_t
),
intent
(
in
)
::
this
class
(
connection_t
),
pointer
::
content
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
content
=>
this
%
content
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'get_content_connection_container_impl'
)
#endif
end
function
get_content_connection_container_impl
!> Setter for the private 'content' component
!! @param[in] content Pointer to the connection (type connection_t, pointer)
subroutine
set_content_connection_container_impl
(
this
,
content
)
class
(
connection_container_t
),
intent
(
inout
)
::
this
class
(
connection_t
),
pointer
,
intent
(
in
)
::
content
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
this
%
content
=>
content
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'set_content_connection_container_impl'
)
#endif
end
subroutine
set_content_connection_container_impl
!----------------!---------------------------------------------------------------------
! Common methods !
!----------------!
! empty !
!----------------!
!-----------------------------!
! class interval_connection_t !
...
...
src/connection_m.fun
View file @
60828673
!>
Unit
test
suite
for
connections
(
synapses
)
!!
in
neural
networks
.
!!
!!
@author
Martin
Beseda
!!
@author
Martin
Mrovec
!!
@date
2017
test_suite
connection_m
!
Global
variables
declaration
class
(
neuron_t
),
pointer
::
n1_p
class
(
neuron_t
),
pointer
::
n2_p
class
(
neuron_t
),
pointer
::
dummy_p
type
(
connection_t
)
,
pointer
::
con
!------------------------!---------------------------------------------------------------
!
Setup
before
each
test
!
!------------------------!
setup
write
(*
,*)
'
+------------------------+
'
write
(*
,*)
'
|
SETUP
BEFORE
UNIT
TEST
|
'
write
(*
,*)
'
+------------------------+
'
write
(*
,*)
'Creating
instances
of
the
class
mock_neuron_t
.
..
'
n1_p
=>
mock_neuron_t
()
n2_p
=>
mock_neuron_t
()
write
(*
,*)
'Creating
an
instance
of
the
class
interval_connection_t
.
..
'
con
=>
connection_t
(
n1_p
,
n2_p
,
real
(
5.25
,
real_4neuro
))
nullify
(
dummy_p
)
write
(*
,*)
'Ready
for
test
.
'
end
setup
!-------------------------!--------------------------------------------------------------
!
Cleanup
after
each
test
!
!-------------------------!
teardown
write
(*
,*)
'+-------------------------+'
write
(*
,*)
'
|
CLEANUP
AFTER
UNIT
TEST
|
'
write
(*
,*)
'+-------------------------+'
write
(*
,*)
'Deallocating
everything
.
'
deallocate
(
con
)
nullify
(
dummy_p
)
write
(*
,*)
'Cleaned
succesfully
.
'
end
teardown
!-------!--------------------------------------------------------------------------------
!
Tests
!
!-------!
!-----------------------------!
!
Test
of
getters
and
setters
!
!-----------------------------!
test
getters_setters
write
(*
,*)
'+++
Test
of
getters
and
setters
...
'
!
Test
of
get_weight
assert_real_equal
(
con%get_weight
(),
5.25
e+
0
)
!
Test
of
adjust_weight
call
con%adjust_weight
(
real
(
1.0
,
real_4neuro
))
assert_real_equal
(
con%get_weight
(),
6.25
e+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
!----------------------------------!
!
Test
of
input
and
output
neurons
!
!----------------------------------!
test
input_and_output_neurons
write
(*
,*)
'+++
Test
of
input
and
output
neurons
...
'
!
Input
neuron
dummy_p
=>
con%get_input_neuron
()
assert_real_equal
(
dummy_p%get_state
(),
15.0
e+
0
)
!
Output
neuron
dummy_p
=>
con%get_output_neuron
()
assert_real_equal
(
dummy_p%get_state
(),
15.0
e+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
!--------------------------!
!
Test
of
passing
a
signal
!
!--------------------------!
test
pass_signal
write
(*
,*)
'+++
Test
of
passing
a
signal
...
'
dummy_p
=>
con%get_output_neuron
()
call
con%pass_signal
()
assert_real_equal
(
dummy_p%get_potential
(),
78.75
e+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
end
test_suite
!>
Unit
test
suite
for
connections
(
synapses
)
!!
in
neural
networks
.
!!
!!
@author
Martin
Beseda
!!
@author
Martin
Mrovec
!!
@date
2017
test_suite
connection_m
!
Global
variables
declaration
type
(
neuron_t
)
,
target
::
n1
type
(
neuron_t
)
,
target
::
n2
type
(
neuron_t
)
,
pointer
::
n1_p
type
(
neuron_t
)
,
pointer
::
n2_p
type
(
neuron_t
)
,
pointer
::
dummy_p
type
(
connection_t
)
,
pointer
::
con
!------------------------!---------------------------------------------------------------
!
Setup
before
each
test
!
!------------------------!
setup
write
(*
,*)
'
+------------------------+
'
write
(*
,*)
'
|
SETUP
BEFORE
UNIT
TEST
|
'
write
(*
,*)
'
+------------------------+
'
write
(*
,*)
'Creating
instances
of
the
class
neuron_t
.
..
'
n1
=
neuron_t
(
21.3
)
n2
=
neuron_t
(
13.7
)
write
(*
,*)
'Assigning
instances
to
pointer
.
..
'
n1_p
=>
n1
n2_p
=>
n2
write
(*
,*)
'Creating
an
instance
of
the
class
interval_connection_t
.
..
'
con
=>
connection_t
(
n1_p
,
n2_p
,
5.25
)
nullify
(
dummy_p
)
write
(*
,*)
'Ready
for
test
.
'
end
setup
!-------------------------!--------------------------------------------------------------
!
Cleanup
after
each
test
!
!-------------------------!
teardown
write
(*
,*)
'+-------------------------+'
write
(*
,*)
'
|
CLEANUP
AFTER
UNIT
TEST
|
'
write
(*
,*)
'+-------------------------+'
write
(*
,*)
'Deallocating
everything
.
'
deallocate
(
con
)
nullify
(
dummy_p
)
write
(*
,*)
'Cleaned
succesfully
.
'
end
teardown
!-------!--------------------------------------------------------------------------------
!
Tests
!
!-------!
!-----------------------------!
!
Test
of
getters
and
setters
!
!-----------------------------!
test
getters_setters
write
(*
,*)
'+++
Test
of
getters
and
setters
...
'
!
Test
of
get_weight
assert_real_equal
(
con%get_weight
(),
5.25
e+
0
)
!
Test
of
adjust_weight
call
con%adjust_weight
(
1.0
)
assert_real_equal
(
con%get_weight
(),
6.25
e+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
!----------------------------------!
!
Test
of
input
and
output
neurons
!
!----------------------------------!
test
input_and_output_neurons
write
(*
,*)
'+++
Test
of
input
and
output
neurons
...
'
!
Input
neuron
dummy_p
=>
con%get_input_neuron
()
assert_real_equal
(
dummy_p%get_state
(),
21.3
d+
0
)
!
Output
neuron
dummy_p
=>
con%get_output_neuron
()
assert_real_equal
(
dummy_p%get_state
(),
13.7
d+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
!--------------------------!
!
Test
of
passing
a
signal
!
!--------------------------!
test
pass_signal
write
(*
,*)
'+++
Test
of
passing
a
signal
...
'
dummy_p
=>
con%get_output_neuron
()
call
con%pass_signal
()
assert_real_equal
(
dummy_p%get_state
(),
111.825
d+
0
)
write
(*
,*)
'
.
..
finished
+++'
end
test
end
test_suite
src/neuron_m.f90
View file @
60828673
...
...
@@ -237,6 +237,7 @@ module neuron_m
call
time_profiling_start
(
start_time
)
#endif
potential
=
this
%
potential
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'get_potential_impl'
)
#endif
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment