Skip to content

Commit 258b22b

Browse files
committed
update codes and add updated plot.
1 parent b19857d commit 258b22b

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

benchmarks/python/acc_pythran.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,22 @@ def compute_accelerations(accelerations, masses, positions):
2626
position0 = positions[index_p0]
2727
mass0 = masses[index_p0]
2828

29-
vectors = position0 - positions[index_p0 + 1: nb_particles]
30-
31-
distances = np.square(vectors).sum(axis = 1)
32-
coefs = distances ** 1.5
33-
34-
_x = np.add(np.sum(
35-
np.divide(
36-
np.multiply(
37-
masses[index_p0 + 1: nb_particles], -1 * vectors.T
38-
),
39-
coefs).T, axis = 0),
40-
accelerations[index_p0]
41-
)
42-
accelerations[index_p0] = _x
43-
44-
_temp = np.add(
45-
np.divide(
46-
np.multiply(
47-
mass0, vectors.T
48-
),
49-
coefs).T,
50-
accelerations[index_p0 + 1: nb_particles]
51-
)
52-
accelerations[index_p0 + 1: nb_particles] = _temp
29+
vector = np.empty(3)
30+
31+
for index_p1 in range(index_p0 + 1, nb_particles):
32+
mass1 = masses[index_p1]
33+
position1 = positions[index_p1]
34+
35+
for i in range(3):
36+
vector[i] = position0[i] - position1[i]
37+
38+
distance = sum(vector ** 2) * math.sqrt(sum(vector ** 2))
39+
coef_m1 = mass0 / distance
40+
coef_m2 = mass1 / distance
41+
42+
for i in range(3):
43+
accelerations[index_p0][i] += coef_m1 * -1 * vector[i]
44+
accelerations[index_p1][i] += coef_m2 * vector[i]
5345

5446
return accelerations
5547

benchmarks/python/plot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ def plot(x, labels, list_df, names):
1313

1414
list1 = []
1515
for ind, list in enumerate(list_df):
16-
if ind < 3:
16+
if ind < 2:
1717
list1.append(list)
1818

1919
for ind, time_taken in enumerate(list1):
2020
rect[ind] = plt.bar(x + width * ind, time_taken, width, align = 'center', label = labels[ind])
2121
plt.bar_label(rect[ind], padding = 3, fontsize = 250)
2222

23-
plt.xticks(x + width, names, fontsize = 300)
23+
plt.xticks(x + width / 2, names, fontsize = 300)
2424
plt.yticks(fontsize = 300)
2525
plt.legend(fontsize = 250)
2626

@@ -34,10 +34,10 @@ def plot(x, labels, list_df, names):
3434

3535
list2 = []
3636
for ind, list in enumerate(list_df):
37-
if ind >= 3:
37+
if ind >= 2:
3838
list2.append(list)
3939

40-
j = 3
40+
j = 2
4141
for ind, time_taken in enumerate(list2):
4242
rect[ind] = plt.bar(x + width * ind, time_taken, width, align = 'center', color = colors[ind % len(colors)], label = labels[j])
4343
j += 1
@@ -55,10 +55,11 @@ def plot(x, labels, list_df, names):
5555
plt.savefig("benchmarking-numpy")
5656

5757
if __name__ == "__main__":
58-
df = pd.read_csv("data.csv")
58+
data_path = "table.csv"
59+
df = pd.read_csv(data_path)
5960
df = df.drop(['Unnamed: 0'], axis = 1)
6061
df = df.T
61-
df.columns = ["Python-NumPy", "Pure-NumPy", "Pure-Python", "C++", "Numba", "Pythran: Transonic"]
62+
df.columns = ["NumPy", "Python", "C++", "Numba", "Pythran: Transonic"]
6263

6364
labels = df.columns
6465
names = ["16", "32", "64", "128"]

content/en/benchmark.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ table, th, td {
183183
</tr>
184184
<tr>
185185
<td><b>Pythran-Naive: Transonic</b></td>
186-
<td>0.0023</td>
187-
<td>0.0011</td>
188-
<td>0.0004</td>
189-
<td>0.0002</td>
186+
<td>0.0111</td>
187+
<td>0.0089</td>
188+
<td>0.0083</td>
189+
<td>0.0078</td>
190190
</tr>
191191
</table>
192192
</body>
Loading

0 commit comments

Comments
 (0)