Skip to content

Commit eaf1145

Browse files
committed
Update README.md
1 parent e56ecf8 commit eaf1145

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

README.md

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,31 @@ Hello, world!
88
=====
99
One of the primary design goals of VecPy is *simplicity*. In just a few lines of code, VecPy translates and compiles a Python function into an efficient, data-parallel native library. The generated library can then be loaded as a Python module, allowing the optimized function to be used as a drop-in replacement for the original Python function. The following program illustrates how simple it can be to use VecPy to significantly improve Python program performance.
1010
```python
11-
#Import VecPy and other modules
12-
from parser import Parser
13-
from compiler import Compiler
14-
from compiler_constants import *
15-
from array import array
16-
from random import uniform
11+
#Import VecPy
12+
from vecpy.runtime import *
13+
from vecpy.compiler_constants import *
1714

1815
#Define the kernel
19-
def shapes(radius, edge, vol_sphere, vol_icos):
20-
"""Calculates sphere and an icosahedron volumes."""
21-
vol_sphere = (4/3 * math.pi) * (radius ** 3)
22-
vol_icos = (5/12) * (3 + math.sqrt(5)) * (edge ** 3)
23-
return (vol_sphere, vol_icos)
16+
def volume(radius, volume):
17+
volume = (4/3 * math.pi) * (radius ** 3)
2418

2519
#Generate some data
26-
n = 1000
27-
def rand():
28-
return array('f', [uniform(0, 1) for i in range(n)])
29-
radii, edges, spheres, icosahedrons = rand(), rand(), rand(), rand()
30-
31-
#Call VecPy to generate the a native module
32-
krnl = Parser.parse(shapes)
33-
opts = Options(Architecture.sse4, DataType.float)
34-
Compiler.compile(krnl, opts)
35-
36-
#Import the newly-minted module and execute the data-parallel kernel
37-
import VecPy_shapes
38-
VecPy_shapes.shapes(radii, edges, spheres, icosahedrons)
39-
40-
#Use the results!
41-
print(spheres, icosahedrons)
20+
def data():
21+
array = get_array('f', 10)
22+
for i in range(len(array)): array[i] = (.1 + i/10)
23+
return array
24+
radii, volumes = data(), data()
25+
26+
#Call VecPy to generate the native module
27+
vectorize(volume, Options(Architecture.avx2, DataType.float))
28+
29+
#Import the newly-minted module and execute kernel
30+
from vecpy_volume import volume
31+
volume(radii, volumes)
32+
33+
#Print the results!
34+
print('Radius:', ', '.join('%.3f'%(r) for r in radii))
35+
print('Volume:', ', '.join('%.3f'%(v) for v in volumes))
4236
```
4337

4438
Features and Functionality
@@ -48,10 +42,10 @@ Other design goals of VecPy include *utility*, *flexibility*, and *efficiency*.
4842
VecPy aims to implement a sufficiently large feature set to be useful for meaningful, real-world applications. Conditional operations within `if-elif-else` blocks and `while` loops are fully implemented, and the following Python operators, functions, and constants are currently available:
4943

5044
- **Operators**
51-
- Unary: +, -, ~
52-
- Arithmetic: +, -, \*, /, %, \*\*
45+
- Arithmetic: +, -, \*, /, //, %, \*\*
5346
- Comparison: ==, !=, >, >=, <, <=
5447
- Boolean: and, or, not
48+
- Bitwise: &, |, ^, ~, <<, >> (integer only)
5549
- **Functions**
5650
- global: abs, max, min, pow, round
5751
- math: acos, acosh, asin, asinh, atan, atan2, atanh, ceil, copysign, cos, cosh, erf, erfc, exp, expm1, fabs, floor, fmod, gamma, hypot, lgamma, log, log10, log1p, log2, pow, sin, sinh, sqrt, tan, tanh, trunc
@@ -62,7 +56,7 @@ VecPy provides many options to allow for extensive customization. The following
6256

6357
- **Data Types**
6458
- 32-bit floats
65-
- 32-bit integers (experimental)
59+
- 32-bit unsigned integers
6660
- **Language Bindings**
6761
- C++
6862
- Python
@@ -80,6 +74,6 @@ VecPy relies on multi-threading and SIMD execution to achieve the fastest possib
8074
Requirements
8175
=====
8276
- Python 3.x (to run VecPy)
83-
- Linux (to compile the native library)
77+
- g++ (to compile the native library)
8478
- Optional: Python 3.x headers if compiling as a Python module
8579
- Optional: JDK if compiling for use with Java via JNI

0 commit comments

Comments
 (0)