Skip to content

Commit

Permalink
Merge pull request #196 from IntelPython/rambo_dpnp_numpy
Browse files Browse the repository at this point in the history
Adding implementations of Rambo using numpy-like vector operations
  • Loading branch information
Diptorup Deb authored Apr 6, 2023
2 parents 800b6fc + f27c43d commit 09dc9ed
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
17 changes: 17 additions & 0 deletions dpbench/benchmarks/rambo/rambo_dpnp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

import dpnp as np


def rambo(nevts, nout, C1, F1, Q1, output):
C = 2.0 * C1 - 1.0
S = np.sqrt(1 - np.square(C))
F = 2.0 * np.pi * F1
Q = -np.log(Q1)

output[:, :, 0] = Q
output[:, :, 1] = Q * S * np.sin(F)
output[:, :, 2] = Q * S * np.cos(F)
output[:, :, 3] = Q * C
19 changes: 19 additions & 0 deletions dpbench/benchmarks/rambo/rambo_numba_np.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

import numba as nb
import numpy as np


@nb.njit(parallel=True, fastmath=True)
def rambo(nevts, nout, C1, F1, Q1, output):
C = 2.0 * C1 - 1.0
S = np.sqrt(1 - np.square(C))
F = 2.0 * np.pi * F1
Q = -np.log(Q1)

output[:, :, 0] = Q
output[:, :, 1] = Q * S * np.sin(F)
output[:, :, 2] = Q * S * np.cos(F)
output[:, :, 3] = Q * C
18 changes: 8 additions & 10 deletions dpbench/benchmarks/rambo/rambo_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@


def rambo(nevts, nout, C1, F1, Q1, output):
for i in range(nevts):
for j in range(nout):
C = 2.0 * C1[i, j] - 1.0
S = np.sqrt(1 - np.square(C))
F = 2.0 * np.pi * F1[i, j]
Q = -np.log(Q1[i, j])
C = 2.0 * C1 - 1.0
S = np.sqrt(1 - np.square(C))
F = 2.0 * np.pi * F1
Q = -np.log(Q1)

output[i, j, 0] = Q
output[i, j, 1] = Q * S * np.sin(F)
output[i, j, 2] = Q * S * np.cos(F)
output[i, j, 3] = Q * C
output[:, :, 0] = Q
output[:, :, 1] = Q * S * np.sin(F)
output[:, :, 2] = Q * S * np.cos(F)
output[:, :, 3] = Q * C
19 changes: 19 additions & 0 deletions dpbench/benchmarks/rambo/rambo_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

import numpy as np


def rambo(nevts, nout, C1, F1, Q1, output):
for i in range(nevts):
for j in range(nout):
C = 2.0 * C1[i, j] - 1.0
S = np.sqrt(1 - np.square(C))
F = 2.0 * np.pi * F1[i, j]
Q = -np.log(Q1[i, j])

output[i, j, 0] = Q
output[i, j, 1] = Q * S * np.sin(F)
output[i, j, 2] = Q * S * np.cos(F)
output[i, j, 3] = Q * C

0 comments on commit 09dc9ed

Please sign in to comment.