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
Show file tree
Hide file tree
Changes from 14 commits
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
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 <[email protected]>", "Dikshant <[email protected]"]
authors = ["Shreyas Atre <[email protected]>", "Dikshant <[email protected]>"]
edition = "2021"
readme = "README.md"
repository = "https://github.com/STEllAR-GROUP/hpx-rs"
Expand Down
191 changes: 179 additions & 12 deletions hpx-sys/include/wrapper.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
#pragma once

#include <hpx/hpx_init.hpp>
#include <hpx/algorithm.hpp>
#include <iostream>
#include <cstdint>
#include <vector>

#include "rust/cxx.h"


/*inline std::int32_t start() { return hpx::start(nullptr, 0, nullptr); }*/

/*inline std::int32_t start(rust::Fn<int(int, char **)> rust_fn, int argc, char **argv) {*/
/* return hpx::start(*/
/* [&](int argc, char **argv) {*/
/* return rust_fn(argc, argv);*/
/* },*/
/* argc, argv);*/
/*}*/

inline std::int32_t init(rust::Fn<int(int, char **)> rust_fn, int argc, char **argv) {
return hpx::init(
[&](int argc, char **argv) {
Expand All @@ -44,4 +34,181 @@ inline std::int32_t disconnect_with_timeout(double shutdown_timeout, double loca

inline std::int32_t finalize() { return hpx::finalize(); }

/*inline std::int32_t stop() { return hpx::stop(); }*/
inline void hpx_copy(const rust::Vec<int32_t>& src, rust::Vec<int32_t>& dest) {
std::vector<int32_t> cpp_src(src.begin(), src.end());
std::vector<int32_t> cpp_dest(dest.size());

hpx::copy(hpx::execution::par, cpp_src.begin(), cpp_src.end(), cpp_dest.begin());
pingu-73 marked this conversation as resolved.
Show resolved Hide resolved

dest.clear();
dest.reserve(cpp_dest.size());
for (const auto& item : cpp_dest) {
dest.push_back(item);
}
pingu-73 marked this conversation as resolved.
Show resolved Hide resolved
}

inline void hpx_copy_n(const rust::Vec<int32_t>& src, size_t count, rust::Vec<int32_t>& dest) {
std::vector<int32_t> cpp_src(src.begin(), src.end());
std::vector<int32_t> cpp_dest(count);

hpx::copy_n(hpx::execution::par, cpp_src.begin(), count, cpp_dest.begin());

dest.clear();
dest.reserve(cpp_dest.size());
for (const auto& item : cpp_dest) {
dest.push_back(item);
}
}
pingu-73 marked this conversation as resolved.
Show resolved Hide resolved

inline void hpx_copy_if(const rust::Vec<int32_t>& src, rust::Vec<int32_t>& dest,
rust::Fn<bool(int32_t)> pred) {
std::vector<int32_t> cpp_src(src.begin(), src.end());
std::vector<int32_t> cpp_dest(cpp_src.size());

auto result = hpx::copy_if(hpx::execution::par,
cpp_src.begin(), cpp_src.end(),
cpp_dest.begin(),
[&](int32_t value) { return pred(value); });

cpp_dest.resize(std::distance(cpp_dest.begin(), result));

dest.clear();
dest.reserve(cpp_dest.size());
for (const auto& item : cpp_dest) {
dest.push_back(item);
}
}

inline std::int64_t hpx_count(const rust::Vec<int32_t>& vec, int32_t value) {
return hpx::count(hpx::execution::par, vec.begin(), vec.end(), value);
}


inline int64_t hpx_count_if(const rust::Vec<int32_t>& vec, rust::Fn<bool(int32_t)> pred) {
std::vector<int32_t> cpp_vec(vec.begin(), vec.end());

auto result = hpx::count_if(hpx::execution::par,
cpp_vec.begin(),
cpp_vec.end(),
[&](int32_t value) { return pred(value); });

return static_cast<int64_t>(result);
}

inline bool hpx_ends_with(rust::Slice<const int32_t> src,
rust::Slice<const int32_t> dest) {
return hpx::ends_with(hpx::execution::par,
src.begin(), src.end(),
dest.begin(), dest.end(),
std::equal_to<int32_t>());
}

inline bool hpx_equal(rust::Slice<const int32_t> src, rust::Slice<const int32_t> dest) {
return hpx::equal(
hpx::execution::par,
src.begin(), src.end(),
dest.begin(), dest.end()
);
}

inline void hpx_fill(rust::Vec<int32_t>& src, int32_t value) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::fill(hpx::execution::par, cpp_vec.begin(), cpp_vec.end(), value);

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}

inline int64_t hpx_find(const rust::Vec<int32_t>& src, int32_t value) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

auto result = hpx::find(hpx::execution::par,
cpp_vec.begin(),
cpp_vec.end(),
value);

if (result != cpp_vec.end()) {
return static_cast<int64_t>(std::distance(cpp_vec.begin(), result));
}
return -1;
}

inline void hpx_sort(rust::Vec<int32_t>& src) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::sort(hpx::execution::par, cpp_vec.begin(), cpp_vec.end());

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}

inline void hpx_sort_comp(rust::Vec<int32_t>& src, rust::Fn<bool(int32_t, int32_t)> comp) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::sort(hpx::execution::par, cpp_vec.begin(), cpp_vec.end(),
[&](int32_t a, int32_t b) { return comp(a, b); });

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}

inline void hpx_merge(const rust::Vec<int32_t>& src1,
const rust::Vec<int32_t>& src2,
rust::Vec<int32_t>& dest) {
std::vector<int32_t> cpp_src1(src1.begin(), src1.end());
std::vector<int32_t> cpp_src2(src2.begin(), src2.end());
std::vector<int32_t> cpp_dest(cpp_src1.size() + cpp_src2.size());

hpx::merge(hpx::execution::par,
cpp_src1.begin(), cpp_src1.end(),
cpp_src2.begin(), cpp_src2.end(),
cpp_dest.begin());

dest.clear();
dest.reserve(cpp_dest.size());
for (const auto& item : cpp_dest) {
dest.push_back(item);
}
}

inline void hpx_partial_sort(rust::Vec<int32_t>& src, size_t last) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::partial_sort(hpx::execution::par,
cpp_vec.begin(),
cpp_vec.begin() + last,
cpp_vec.end());

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}

inline void hpx_partial_sort_comp(rust::Vec<int32_t>& src, size_t last,
rust::Fn<bool(int32_t, int32_t)> comp) {
std::vector<int32_t> cpp_vec(src.begin(), src.end());

hpx::partial_sort(hpx::execution::par,
cpp_vec.begin(),
cpp_vec.begin() + last,
cpp_vec.end(),
[&](int32_t a, int32_t b) { return comp(a, b); });

src.clear();
src.reserve(cpp_vec.size());
for (const auto& item : cpp_vec) {
src.push_back(item);
}
}
Loading
Loading