Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
3d64e9e5
Commit
3d64e9e5
authored
May 29, 2014
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add (modified) spectral_norm millibenchmark from the language shootout.
Implement zip2
parent
ccc8fda6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
millibenchmarks/spectral_norm.py
millibenchmarks/spectral_norm.py
+73
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+17
-0
test/tests/builtins.py
test/tests/builtins.py
+2
-0
No files found.
millibenchmarks/spectral_norm.py
0 → 100644
View file @
3d64e9e5
# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
#
# Contributed by Sebastien Loisel
# Fixed by Isaac Gouy
# Sped up by Josh Goldfoot
# Dirtily sped up by Simon Descarpentries
# Used list comprehension by Vadim Zelenin
# 2to3
from
math
import
sqrt
from
sys
import
argv
# pyston does not yet support enumerate
def
_enumerate
(
sequence
):
n
=
0
rtn
=
[]
for
elem
in
sequence
:
rtn
.
append
((
n
,
elem
))
n
+=
1
return
rtn
def
eval_A
(
i
,
j
):
ij
=
i
+
j
return
1.0
/
(
ij
*
(
ij
+
1
)
/
2
+
i
+
1
)
def
eval_A_times_u
(
u
):
local_eval_A
=
eval_A
return
[
sum
([
local_eval_A
(
i
,
j
)
*
u_j
for
j
,
u_j
in
_enumerate
(
u
)
]
)
for
i
in
range
(
len
(
u
))
]
def
eval_At_times_u
(
u
):
local_eval_A
=
eval_A
return
[
sum
([
local_eval_A
(
j
,
i
)
*
u_j
for
j
,
u_j
in
_enumerate
(
u
)
]
)
for
i
in
range
(
len
(
u
))
]
def
eval_AtA_times_u
(
u
):
return
eval_At_times_u
(
eval_A_times_u
(
u
))
def
main
():
#n = int(argv[1])
n
=
1000
# when pyston gets faster we should increase this
u
=
[
1
]
*
n
local_eval_AtA_times_u
=
eval_AtA_times_u
for
dummy
in
range
(
10
):
v
=
local_eval_AtA_times_u
(
u
)
u
=
local_eval_AtA_times_u
(
v
)
vBv
=
vv
=
0
for
ue
,
ve
in
zip
(
u
,
v
):
vBv
+=
ue
*
ve
vv
+=
ve
*
ve
print
(
"%0.9f"
%
(
sqrt
(
vBv
/
vv
)))
main
()
src/runtime/builtin_modules/builtins.cpp
View file @
3d64e9e5
...
...
@@ -310,6 +310,22 @@ Box* map2(Box* f, Box* container) {
return
rtn
;
}
Box
*
zip2
(
Box
*
container1
,
Box
*
container2
)
{
BoxedList
*
rtn
=
new
BoxedList
();
llvm
::
iterator_range
<
BoxIterator
>
range1
=
container1
->
pyElements
();
llvm
::
iterator_range
<
BoxIterator
>
range2
=
container2
->
pyElements
();
BoxIterator
it1
=
range1
.
begin
();
BoxIterator
it2
=
range2
.
begin
();
for
(;
it1
!=
range1
.
end
()
&&
it2
!=
range2
.
end
();
++
it1
,
++
it2
)
{
BoxedTuple
::
GCVector
elts
{
*
it1
,
*
it2
};
listAppendInternal
(
rtn
,
new
BoxedTuple
(
std
::
move
(
elts
)));
}
return
rtn
;
}
extern
"C"
const
ObjectFlavor
notimplemented_flavor
(
&
boxGCHandler
,
NULL
);
BoxedClass
*
notimplemented_cls
;
BoxedModule
*
builtins_module
;
...
...
@@ -459,6 +475,7 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"open"
,
open_obj
);
builtins_module
->
giveAttr
(
"map"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
map2
,
LIST
,
2
,
false
)));
builtins_module
->
giveAttr
(
"zip"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
zip2
,
LIST
,
2
,
false
)));
builtins_module
->
setattr
(
"str"
,
str_cls
,
NULL
,
NULL
);
builtins_module
->
setattr
(
"int"
,
int_cls
,
NULL
,
NULL
);
...
...
test/tests/builtins.py
View file @
3d64e9e5
...
...
@@ -26,3 +26,5 @@ class C(object):
return
self
print
sum
([
C
(
1
),
C
(
2
),
C
(
3
)],
C
(
4
)).
n
print
zip
([
1
,
2
,
3
,
0
],
[
"one"
,
"two"
,
"three"
])
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