Skip to content

Commit cd6efa8

Browse files
committed
feat: Change result to numpy array in numpy functions, add multithreading in some functions
1 parent 1191f83 commit cd6efa8

11 files changed

Lines changed: 100 additions & 344 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rem_math"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55

66
[lib]

benches/common.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,25 @@ fn sum_two_floats32_with_mthreaded_benchmark(c: &mut Criterion) {
5353
fn sum_two_ints32_with_benchmark(c: &mut Criterion) {
5454
let arr = black_box(vec![1; NUM_ITERATIONS]);
5555
c.bench_function("Array accumulation of two integer arrays", |b| {
56-
b.iter(|| sum_two_ints32(&arr, &arr, false))
56+
b.iter(|| sum_two_ints32(&arr, &arr, ""))
5757
});
5858
}
5959

6060
fn sum_two_ints32_with_simd_benchmark(c: &mut Criterion) {
6161
let arr = black_box(vec![1; NUM_ITERATIONS]);
6262
c.bench_function("Array accumulation of two integer arrays with SIMD", |b| {
63-
b.iter(|| sum_two_ints32(&arr, &arr, true))
63+
b.iter(|| sum_two_ints32(&arr, &arr, "simd"))
6464
});
6565
}
6666

67+
fn sum_two_ints32_with_mthreaded_benchmark(c: &mut Criterion) {
68+
let arr = black_box(vec![1; NUM_ITERATIONS]);
69+
c.bench_function(
70+
"Array accumulation of two integer arrays with multi threading",
71+
|b| b.iter(|| sum_two_ints32(&arr, &arr, "threading")),
72+
);
73+
}
74+
6775
fn mul_two_ints32_benchmark(c: &mut Criterion) {
6876
let arr = black_box(vec![1; NUM_ITERATIONS]);
6977
c.bench_function("Array multiply of two integer arrays", |b| {
@@ -95,6 +103,7 @@ criterion_group!(
95103
sum_two_floats32_with_mthreaded_benchmark,
96104
sum_two_ints32_with_benchmark,
97105
sum_two_ints32_with_simd_benchmark,
106+
sum_two_ints32_with_mthreaded_benchmark,
98107
mul_two_ints32_benchmark,
99108
mul_two_ints32_with_simd_benchmark,
100109
mul_two_ints32_with_mthreaded_benchmark,

benches/common_benchmark_test.py

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55

66
NUM_ITERATIONS = 10_000_000
77

8+
89
@pytest.fixture(scope="module")
910
def large_array():
1011
return np.array([i for i in range(NUM_ITERATIONS)], dtype=np.int32)
1112

1213

14+
@pytest.fixture(scope="module")
15+
def large_naive_array():
16+
return [i for i in range(NUM_ITERATIONS)]
17+
18+
1319
@pytest.mark.benchmark(
1420
group="numpy_sum",
1521
min_time=0.1,
@@ -73,7 +79,7 @@ def result():
7379
def test_rm_mul(benchmark, large_array):
7480
@benchmark
7581
def result():
76-
return rm.multiply_two_nparr_ints32(large_array, large_array, method="simd")
82+
return rm.multiply_two_nparr_ints32(large_array, large_array, "threading")
7783

7884
assert result is not None
7985

@@ -107,6 +113,6 @@ def result():
107113
def test_rm_sum_two_ints32(benchmark, large_array):
108114
@benchmark
109115
def result():
110-
return rm.sum_two_nparr_ints32(large_array, large_array)
116+
return rm.sum_two_nparr_ints32(large_array, large_array, "threading")
111117

112118
assert result is not None

benches/mul_of_arrays_benchmark_test.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

benches/sum_of_arrays_benchmark_test.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "rem_math"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = ""
55
authors = [
66
{name = "WrldEngine",email = "kamran_pulatov@outlook.com"}

rem_math/_rem_math.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def sum_two_floats32(arr_1: List[float], arr_2: List[float], method: str) -> Lis
1010
def sum_two_nparr_ints32(
1111
arr_1: List[int] | NDArray, arr_2: List[int] | NDArray, method: str
1212
) -> List: ...
13-
def sum_two_ints32(arr_1: List[int], arr_2: List[int]) -> List: ...
13+
def sum_two_ints32(arr_1: List[int], arr_2: List[int], method: str) -> List: ...
1414
def multiply_two_nparr_ints32(
15-
arr_1: List[int] | NDArray, arr_2: List[int] | NDArray
15+
arr_1: List[int] | NDArray, arr_2: List[int] | NDArray, method: str
1616
) -> List: ...
1717
def multiply_two_ints32(arr_1: List[int], arr_2: List[int], method: str) -> List: ...

0 commit comments

Comments
 (0)