Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindings for hpx/algorithm.hpp #7

Merged
merged 20 commits into from
Sep 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
moved wrappers from tests to main
Signed-off-by: Dikshant <dikshant.073@gmail.com>
pingu-73 committed Aug 10, 2024
commit fa1e347a9d1f0c1b48e1b53ab84a5882d92b41ed
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hpx-rs"
version = "0.1.0"
authors = ["Shreyas Atre <shreyasatre16@gmail.com>", "Dikshant <dikshant.073@gmail.com"]
authors = ["Shreyas Atre <shreyasatre16@gmail.com>", "Dikshant <dikshant.073@gmail.com>"]
edition = "2021"
readme = "README.md"
repository = "https://github.com/STEllAR-GROUP/hpx-rs"
94 changes: 51 additions & 43 deletions hpx-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -36,58 +36,66 @@ pub mod ffi {
}

// ================================================================================================
// Tests (to be shifted to systests crate within hpx-rs workspace)
// Wrapper for the above Bindings.
// reffer to tests to understand how to use them. [NOTE: Not all bindings have wrapper.]
// ================================================================================================
#[cfg(test)]
mod tests {
use super::ffi;
use serial_test::serial;
use std::ffi::CString;
use std::os::raw::c_char;
use std::thread;
use std::time::Duration;
use std::ffi::CString;
use std::os::raw::c_char;

fn create_c_args(args: &[&str]) -> (i32, Vec<*mut c_char>) {
let c_args: Vec<CString> = args.iter().map(|s| CString::new(*s).unwrap()).collect();
let ptrs: Vec<*mut c_char> = c_args.iter().map(|s| s.as_ptr() as *mut c_char).collect();
(ptrs.len() as i32, ptrs)
}
pub fn create_c_args(args: &[&str]) -> (i32, Vec<*mut c_char>) {
let c_args: Vec<CString> = args.iter().map(|s| CString::new(*s).unwrap()).collect();
let ptrs: Vec<*mut c_char> = c_args.iter().map(|s| s.as_ptr() as *mut c_char).collect();
(ptrs.len() as i32, ptrs)
}

fn copy_vector(src: &Vec<i32>) -> Vec<i32> {
let mut dest = vec![0; src.len()];
ffi::hpx_copy(src, &mut dest);
dest
}
pub fn copy_vector(src: &Vec<i32>) -> Vec<i32> {
let mut dest = vec![0; src.len()];
ffi::hpx_copy(src, &mut dest);
dest
}

fn copy_vector_range(src: &Vec<i32>, start: usize, end: usize) -> Vec<i32> {
let slice = &src[start..end];
let mut dest = vec![0; slice.len()];
ffi::hpx_copy(&slice.to_vec(), &mut dest);
dest
}
pub fn copy_vector_range(src: &Vec<i32>, start: usize, end: usize) -> Vec<i32> {
let slice = &src[start..end];
let mut dest = vec![0; slice.len()];
ffi::hpx_copy(&slice.to_vec(), &mut dest);
dest
}

fn copy_n(src: &[i32], count: usize) -> Vec<i32> {
let mut dest = Vec::with_capacity(count);
ffi::hpx_copy_n(&src.to_vec(), count, &mut dest);
dest
}
pub fn copy_n(src: &[i32], count: usize) -> Vec<i32> {
let mut dest = Vec::with_capacity(count);
ffi::hpx_copy_n(&src.to_vec(), count, &mut dest);
dest
}

fn copy_if_positive(src: &Vec<i32>) -> Vec<i32> {
let mut dest = Vec::new();
ffi::hpx_copy_if(src, &mut dest, |x| x % 3 == 0);
dest
}
pub fn copy_if_positive(src: &Vec<i32>) -> Vec<i32> {
let mut dest = Vec::new();
ffi::hpx_copy_if(src, &mut dest, |x| x % 3 == 0);
dest
}

fn count(vec: &Vec<i32>, value: i32) -> i64 {
ffi::hpx_count(vec, value)
}
pub fn count(vec: &Vec<i32>, value: i32) -> i64 {
ffi::hpx_count(vec, value)
}

fn find(vec: &Vec<i32>, value: i32) -> Option<usize> {
match ffi::hpx_find(vec, value) {
-1 => None,
index => Some(index as usize),
}
pub fn find(vec: &Vec<i32>, value: i32) -> Option<usize> {
match ffi::hpx_find(vec, value) {
-1 => None,
index => Some(index as usize),
}
}

// ================================================================================================
// Tests (to be shifted to systests crate within hpx-rs workspace)
// ================================================================================================
#[cfg(test)]
mod tests {
use super::ffi;
use crate::{
copy_if_positive, copy_n, copy_vector, copy_vector_range, count, create_c_args, find,
};
use serial_test::serial;
use std::ffi::CString;
use std::os::raw::c_char;

#[test]
#[serial]