Skip to content

Commit

Permalink
Adding dpnp, python implementations of Rambo
Browse files Browse the repository at this point in the history
  • Loading branch information
adarshyoga committed Apr 4, 2023
1 parent 3c1565f commit 9808163
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_dpex_n.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 9808163

Please sign in to comment.