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
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
ee07366a
Commit
ee07366a
authored
4 years ago
by
Jean-Baptiste Bayle
Browse files
Options
Downloads
Patches
Plain Diff
Use implicit broadcasting to ForEachMOSA
parent
d83e7378
No related branches found
No related tags found
1 merge request
!30
Resolve "Define arithmetics and transformations on containers"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lisainstrument/containers.py
+50
-0
50 additions, 0 deletions
lisainstrument/containers.py
tests/test_containers.py
+22
-0
22 additions, 0 deletions
tests/test_containers.py
with
72 additions
and
0 deletions
lisainstrument/containers.py
+
50
−
0
View file @
ee07366a
...
...
@@ -240,6 +240,31 @@ class ForEachSC(ForEachObject):
"""
Return a ForEachMOSA instance by sharing the spacecraft values on both MOSAs.
"""
return
ForEachMOSA
(
lambda
mosa
:
self
[
ForEachMOSA
.
sc
(
mosa
)])
def
__add__
(
self
,
other
):
if
isinstance
(
other
,
ForEachMOSA
):
return
self
.
for_each_mosa
()
+
other
return
super
().
__add__
(
other
)
def
__sub__
(
self
,
other
):
if
isinstance
(
other
,
ForEachMOSA
):
return
self
.
for_each_mosa
()
-
other
return
super
().
__sub__
(
other
)
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
ForEachMOSA
):
return
self
.
for_each_mosa
()
*
other
return
super
().
__mul__
(
other
)
def
__floordiv__
(
self
,
other
):
if
isinstance
(
other
,
ForEachMOSA
):
return
self
.
for_each_mosa
()
//
other
return
super
().
__floordiv__
(
other
)
def
__truediv__
(
self
,
other
):
if
isinstance
(
other
,
ForEachMOSA
):
return
self
.
for_each_mosa
()
/
other
return
super
().
__truediv__
(
other
)
class
ForEachMOSA
(
ForEachObject
):
"""
Represents a dictionary of values for each moveable optical subassembly (MOSA).
"""
...
...
@@ -283,3 +308,28 @@ class ForEachMOSA(ForEachObject):
def
adjacent
(
self
):
"""
Return a ForEachMOSA instance for adjacent MOSAs.
"""
return
ForEachMOSA
(
lambda
mosa
:
self
[
ForEachMOSA
.
adjacent_mosa
(
mosa
)])
def
__add__
(
self
,
other
):
if
isinstance
(
other
,
ForEachSC
):
return
self
+
other
.
for_each_mosa
()
return
super
().
__add__
(
other
)
def
__sub__
(
self
,
other
):
if
isinstance
(
other
,
ForEachSC
):
return
self
-
other
.
for_each_mosa
()
return
super
().
__sub__
(
other
)
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
ForEachSC
):
return
self
*
other
.
for_each_mosa
()
return
super
().
__mul__
(
other
)
def
__floordiv__
(
self
,
other
):
if
isinstance
(
other
,
ForEachSC
):
return
self
//
other
.
for_each_mosa
()
return
super
().
__floordiv__
(
other
)
def
__truediv__
(
self
,
other
):
if
isinstance
(
other
,
ForEachSC
):
return
self
/
other
.
for_each_mosa
()
return
super
().
__truediv__
(
other
)
This diff is collapsed.
Click to expand it.
tests/test_containers.py
+
22
−
0
View file @
ee07366a
...
...
@@ -368,6 +368,28 @@ def test_foreachsc_to_foreachmosa():
assert
my_mosa
[
'
32
'
]
==
30
def
test_auto_foreachsc_to_foreachmosa
():
"""
Test that ForEachSC turn automatically into ForEachMOSA during operations.
"""
my_sc
=
ForEachSC
(
int
)
my_mosa
=
ForEachMOSA
(
int
)
my_add_1
=
my_sc
+
my_mosa
my_add_2
=
my_mosa
+
my_sc
assert
my_add_1
==
my_sc
.
for_each_mosa
()
+
my_mosa
assert
my_add_1
==
my_add_2
my_sub_1
=
my_sc
-
my_mosa
my_sub_2
=
my_mosa
-
my_sc
assert
my_sub_1
==
my_sc
.
for_each_mosa
()
-
my_mosa
assert
my_sub_1
==
-
my_sub_2
my_mult_1
=
my_sc
*
my_mosa
my_mult_2
=
my_mosa
*
my_sc
assert
my_mult_1
==
my_sc
.
for_each_mosa
()
*
my_mosa
assert
my_mult_1
==
my_mult_2
def
test_foreachmosa_distant
():
"""
Test that one can generate a ForEachMOSA instant for distant MOSAs.
"""
...
...
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