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
beat
beat.backend.python
Commits
8f372b5e
Commit
8f372b5e
authored
Jul 12, 2019
by
Samuel GAIST
Browse files
[test][prefix] Make loop and loop user algorithm use different dataformat
This will ensure that exporting algorithm works correctly.
parent
3ac4751a
Changes
6
Hide whitespace changes
Inline
Side-by-side
beat/backend/python/test/prefix/algorithms/autonomous/loop/1.json
View file @
8f372b5e
...
...
@@ -12,10 +12,10 @@
},
"loop"
:
{
"request"
:
{
"type"
:
"user/
single
_integer/1"
"type"
:
"user/
1d_array_of
_integer
s
/1"
},
"answer"
:
{
"type"
:
"user/single_integer/1"
"type"
:
"user/single_integer
64
/1"
}
}
}
...
...
beat/backend/python/test/prefix/algorithms/autonomous/loop/1.py
View file @
8f372b5e
...
...
@@ -33,16 +33,17 @@
# #
###################################################################################
import
numpy
as
np
class
Algorithm
:
class
Algorithm
:
def
__init__
(
self
):
self
.
threshold
=
None
def
setup
(
self
,
parameters
):
self
.
threshold
=
parameters
[
'
threshold
'
]
self
.
threshold
=
parameters
[
"
threshold
"
]
return
True
def
validate
(
self
,
result
):
value
=
result
.
value
return
(
value
<
self
.
threshold
,
{
'
value
'
:
value
})
value
=
result
.
value
[
0
]
return
(
value
<
self
.
threshold
,
{
"
value
"
:
np
.
int64
(
value
)
})
beat/backend/python/test/prefix/algorithms/autonomous/loop_user/1.json
View file @
8f372b5e
...
...
@@ -18,10 +18,10 @@
},
"loop"
:
{
"request"
:
{
"type"
:
"user/
single
_integer/1"
"type"
:
"user/
1d_array_of
_integer
s
/1"
},
"answer"
:
{
"type"
:
"user/single_integer/1"
"type"
:
"user/single_integer
64
/1"
}
}
}
...
...
beat/backend/python/test/prefix/algorithms/autonomous/loop_user/1.py
View file @
8f372b5e
...
...
@@ -36,26 +36,22 @@
import
numpy
as
np
class
Algorithm
:
class
Algorithm
:
def
process
(
self
,
data_loaders
,
outputs
,
loop_channel
):
cnt
=
10
is_valid
,
_
=
loop_channel
.
validate
({
'
value
'
:
np
.
int32
(
cnt
)})
is_valid
,
_
=
loop_channel
.
validate
({
"
value
"
:
np
.
full
(
10
,
cnt
)})
while
not
is_valid
:
cnt
=
cnt
-
1
is_valid
,
_
=
loop_channel
.
validate
({
'
value
'
:
np
.
int32
(
cnt
)})
is_valid
,
_
=
loop_channel
.
validate
({
"
value
"
:
np
.
full
(
10
,
cnt
)})
data_loader
=
data_loaders
.
loaderOf
(
'
in
'
)
data_loader
=
data_loaders
.
loaderOf
(
"
in
"
)
for
i
in
range
(
data_loader
.
count
()):
view
=
data_loader
.
view
(
'
in
'
,
i
)
view
=
data_loader
.
view
(
"
in
"
,
i
)
(
data
,
start
,
end
)
=
view
[
view
.
count
()
-
1
]
value
=
data
[
'
in
'
].
value
value
=
data
[
"
in
"
].
value
new_value
=
value
+
cnt
outputs
[
'out'
].
write
({
'value'
:
np
.
int32
(
new_value
),
},
end
)
outputs
[
"out"
].
write
({
"value"
:
np
.
int32
(
new_value
)},
end
)
return
True
beat/backend/python/test/prefix/algorithms/sequential/loop_user/1.json
View file @
8f372b5e
...
...
@@ -18,10 +18,10 @@
},
"loop"
:
{
"request"
:
{
"type"
:
"user/
single
_integer/1"
"type"
:
"user/
1d_array_of
_integer
s
/1"
},
"answer"
:
{
"type"
:
"user/single_integer/1"
"type"
:
"user/single_integer
64
/1"
}
}
}
...
...
beat/backend/python/test/prefix/algorithms/sequential/loop_user/1.py
View file @
8f372b5e
...
...
@@ -40,10 +40,10 @@ import numpy as np
class
Algorithm
:
def
process
(
self
,
inputs
,
data_loaders
,
outputs
,
loop_channel
):
cnt
=
10
is_valid
,
_
=
loop_channel
.
validate
({
"value"
:
np
.
int32
(
cnt
)})
is_valid
,
_
=
loop_channel
.
validate
({
"value"
:
np
.
full
(
10
,
cnt
)})
while
not
is_valid
:
cnt
=
cnt
-
1
is_valid
,
_
=
loop_channel
.
validate
({
"value"
:
np
.
int32
(
cnt
)})
is_valid
,
_
=
loop_channel
.
validate
({
"value"
:
np
.
full
(
10
,
cnt
)})
value
=
inputs
[
"in"
].
data
.
value
new_value
=
value
+
cnt
...
...
Write
Preview
Markdown
is supported
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