Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
d34f3a55
Commit
d34f3a55
authored
2 years ago
by
Jean-Baptiste Bayle
Browse files
Options
Downloads
Patches
Plain Diff
Allow multiplication of ForEachObject with arrays
parent
cf9bc90e
No related branches found
No related tags found
1 merge request
!143
Resolve "Bug when computing THE with respect to TCB"
Pipeline
#216090
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lisainstrument/containers.py
+4
-0
4 additions, 0 deletions
lisainstrument/containers.py
tests/test_containers.py
+27
-0
27 additions, 0 deletions
tests/test_containers.py
with
31 additions
and
0 deletions
lisainstrument/containers.py
+
4
−
0
View file @
d34f3a55
...
@@ -20,6 +20,10 @@ logger = logging.getLogger(__name__)
...
@@ -20,6 +20,10 @@ logger = logging.getLogger(__name__)
class
ForEachObject
(
abc
.
ABC
):
class
ForEachObject
(
abc
.
ABC
):
"""
Abstract class which represents a dictionary holding a value for each object.
"""
"""
Abstract class which represents a dictionary holding a value for each object.
"""
# Used to bypass Numpy's vectorization and use
# this class `__rmul__()` method for multiplication from both sides
__array_priority__
=
10000
def
__init__
(
self
,
values
,
concurrent
=
False
):
def
__init__
(
self
,
values
,
concurrent
=
False
):
"""
Initialize an object with a value or a function of the mosa index.
"""
Initialize an object with a value or a function of the mosa index.
...
...
This diff is collapsed.
Click to expand it.
tests/test_containers.py
+
27
−
0
View file @
d34f3a55
...
@@ -195,6 +195,33 @@ def test_multiplication():
...
@@ -195,6 +195,33 @@ def test_multiplication():
result
=
object_2
*
object_3
result
=
object_2
*
object_3
def
test_multiplication_array
():
"""
Check that we can multiply a ForEachObject instance with an array.
"""
array
=
np
.
random
.
normal
(
size
=
10
)
object_1
=
ForEachAB
({
'
A
'
:
1
,
'
B
'
:
2
})
object_2
=
ForEachAB
({
'
A
'
:
np
.
random
.
normal
(
size
=
10
),
'
B
'
:
np
.
random
.
normal
(
size
=
10
),
})
result
=
object_1
*
array
assert
np
.
all
(
result
[
'
A
'
]
==
array
)
assert
np
.
all
(
result
[
'
B
'
]
==
2
*
array
)
result
=
array
*
object_1
assert
np
.
all
(
result
[
'
A
'
]
==
array
)
assert
np
.
all
(
result
[
'
B
'
]
==
2
*
array
)
result
=
object_2
*
array
assert
np
.
all
(
result
[
'
A
'
]
==
object_2
[
'
A
'
]
*
array
)
assert
np
.
all
(
result
[
'
B
'
]
==
object_2
[
'
B
'
]
*
array
)
result
=
array
*
object_2
assert
np
.
all
(
result
[
'
A
'
]
==
object_2
[
'
A
'
]
*
array
)
assert
np
.
all
(
result
[
'
B
'
]
==
object_2
[
'
B
'
]
*
array
)
def
test_floor_division
():
def
test_floor_division
():
"""
Check that we can apply floor division on two ForEachObject subclasses, or a scalar.
"""
"""
Check that we can apply floor division on two ForEachObject subclasses, or a scalar.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment