Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
c2e05fe8
Commit
c2e05fe8
authored
May 07, 2012
by
Peter Eastman
Browse files
Defined a sum() function that works with Quantities. Also fixed a doctest.
parent
94a31b8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
wrappers/python/simtk/unit/unit_math.py
wrappers/python/simtk/unit/unit_math.py
+22
-2
No files found.
wrappers/python/simtk/unit/unit_math.py
View file @
c2e05fe8
...
@@ -143,6 +143,26 @@ def sqrt(val):
...
@@ -143,6 +143,26 @@ def sqrt(val):
except
AttributeError
:
except
AttributeError
:
return
math
.
sqrt
(
val
)
return
math
.
sqrt
(
val
)
###########
### SUM ###
###########
def
sum
(
val
):
"""
>>> sum((1.0, 2.0))
3.0
>>> sum((2.0*meter, 3.0*meter))
Quantity(value=5.0, unit=meter)
>>> sum((2.0*meter, 30.0*centimeter))
Quantity(value=2.3, unit=meter)
"""
if
len
(
val
)
==
0
:
return
0
result
=
val
[
0
]
for
i
in
range
(
1
,
len
(
val
)):
result
+=
val
[
i
]
return
result
###################
###################
### VECTOR MATH ###
### VECTOR MATH ###
###################
###################
...
@@ -159,8 +179,8 @@ def dot(x, y):
...
@@ -159,8 +179,8 @@ def dot(x, y):
def
norm
(
x
):
def
norm
(
x
):
"""
"""
>>>norm((3, 4)*meter)
>>>
norm((3, 4)*meter)
Quantity(value=5, unit=meter
*
)
Quantity(value=5
.0
, unit=meter)
"""
"""
return
sqrt
(
dot
(
x
,
x
))
return
sqrt
(
dot
(
x
,
x
))
...
...
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