Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kwant
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Wimmer
kwant
Commits
3d739054
Commit
3d739054
authored
11 years ago
by
Christoph Groth
Browse files
Options
Downloads
Patches
Plain Diff
digest: add work-around for python 2.6
parent
d5f9f776
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kwant/digest.py
+26
-8
26 additions, 8 deletions
kwant/digest.py
with
26 additions
and
8 deletions
kwant/digest.py
+
26
−
8
View file @
3d739054
...
...
@@ -21,9 +21,10 @@ this module.
from
__future__
import
division
from
math
import
pi
,
log
,
sqrt
,
sin
,
cos
from
math
import
pi
,
log
,
sqrt
,
cos
from
hashlib
import
md5
from
struct
import
unpack
import
sys
__all__
=
[
'
uniform
'
,
'
gauss
'
,
'
test
'
]
...
...
@@ -34,13 +35,30 @@ BPF_MASK = 2**53 - 1
RECIP_BPF
=
2
**-
BPF
def
uniform2
(
input
,
salt
=
''
):
"""
Return two independent [0,1)-distributed numbers.
"""
input
=
memoryview
(
input
).
tobytes
()
+
salt
a
,
b
=
unpack
(
'
qq
'
,
md5
(
input
).
digest
())
a
&=
BPF_MASK
b
&=
BPF_MASK
return
a
*
RECIP_BPF
,
b
*
RECIP_BPF
# TODO: Remove the following workaround for Python 2.6 once we do not support it
# anymore.
if
sys
.
version_info
<
(
2
,
7
):
def
uniform2
(
input
,
salt
=
''
):
"""
Return two independent [0,1)-distributed numbers.
"""
try
:
input
=
bytes
(
buffer
(
input
))
+
salt
except
TypeError
:
# Tinyarray does not provide the old buffer protocol, so buffer does
# not work. However, bytearray does work!
input
=
bytearray
(
input
)
+
salt
a
,
b
=
unpack
(
'
qq
'
,
md5
(
input
).
digest
())
a
&=
BPF_MASK
b
&=
BPF_MASK
return
a
*
RECIP_BPF
,
b
*
RECIP_BPF
else
:
def
uniform2
(
input
,
salt
=
''
):
"""
Return two independent [0,1)-distributed numbers.
"""
input
=
memoryview
(
input
).
tobytes
()
+
salt
a
,
b
=
unpack
(
'
qq
'
,
md5
(
input
).
digest
())
a
&=
BPF_MASK
b
&=
BPF_MASK
return
a
*
RECIP_BPF
,
b
*
RECIP_BPF
def
uniform
(
input
,
salt
=
''
):
...
...
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