Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(FunctionalPlus VERSION 0.2.26)
project(FunctionalPlus VERSION 0.2.27)

# ---- Warning guard ----

Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Just add a *conanfile.txt* with FunctionalPlus as a requirement and chose the ge

```
[requires]
functionalplus/0.2.26
functionalplus/0.2.27

[generators]
cmake
Expand Down
1 change: 1 addition & 0 deletions include/fplus/curry_instances.autogenerated_defines
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ fplus_curry_define_fn_1(apply_functions)
fplus_curry_define_fn_2(apply_function_n_times)
fplus_curry_define_fn_1(transform_parallelly)
fplus_curry_define_fn_2(transform_parallelly_n_threads)
fplus_curry_define_fn_1(transform_convert_parallelly)
fplus_curry_define_fn_2(reduce_parallelly)
fplus_curry_define_fn_3(reduce_parallelly_n_threads)
fplus_curry_define_fn_1(reduce_1_parallelly)
Expand Down
2 changes: 2 additions & 0 deletions include/fplus/fwd_instances.autogenerated_defines
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ fplus_fwd_define_fn_1(apply_functions)
fplus_fwd_define_fn_2(apply_function_n_times)
fplus_fwd_define_fn_1(transform_parallelly)
fplus_fwd_define_fn_2(transform_parallelly_n_threads)
fplus_fwd_define_fn_1(transform_convert_parallelly)
fplus_fwd_define_fn_2(reduce_parallelly)
fplus_fwd_define_fn_3(reduce_parallelly_n_threads)
fplus_fwd_define_fn_1(reduce_1_parallelly)
Expand Down Expand Up @@ -710,6 +711,7 @@ fplus_fwd_flip_define_fn_1(shuffle)
fplus_fwd_flip_define_fn_1(random_element)
fplus_fwd_flip_define_fn_1(apply_functions)
fplus_fwd_flip_define_fn_1(transform_parallelly)
fplus_fwd_flip_define_fn_1(transform_convert_parallelly)
fplus_fwd_flip_define_fn_1(reduce_1_parallelly)
fplus_fwd_flip_define_fn_1(keep_if_parallelly)
fplus_fwd_flip_define_fn_1(show_cont_with)
Expand Down
29 changes: 29 additions & 0 deletions include/fplus/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,35 @@ auto transform_parallelly_n_threads(std::size_t n, F f, const ContainerIn& xs)
thread_results);
}

// API search type: transform_convert_parallelly : ((a -> b), [a]) -> [b]
// fwd bind count: 1
// transform_convert_parallelly((*2), [1, 3, 4]) == [2, 6, 8]
// Same as transform_convert, but can utilize multiple CPUs by using std::launch::async.
// Only makes sense if one run of the provided function
// takes enough time to justify the synchronization overhead.
// One thread per container element is spawned.
template <typename ContainerOut, typename F, typename ContainerIn>
ContainerOut transform_convert_parallelly(F f, const ContainerIn& xs)
{
using X = typename ContainerIn::value_type;
internal::trigger_static_asserts<internal::unary_function_tag, F, X>();
auto handles = transform([&f](const X& x) {
return std::async(std::launch::async, [&x, &f]() {
return internal::invoke(f, x);
});
},
xs);

internal::trigger_static_asserts<internal::unary_function_tag, F, typename ContainerIn::value_type>();
ContainerOut ys;
internal::prepare_container(ys, size_of_cont(xs));
auto it = internal::get_back_inserter<ContainerOut>(ys);
for (auto& handle : handles) {
*it = handle.get();
}
return ys;
}

// API search type: reduce_parallelly : (((a, a) -> a), a, [a]) -> a
// fwd bind count: 2
// reduce_parallelly((+), 0, [1, 2, 3]) == (0+1+2+3) == 6
Expand Down
32 changes: 32 additions & 0 deletions include_all_in_one/include/fplus/fplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11414,6 +11414,35 @@ auto transform_parallelly_n_threads(std::size_t n, F f, const ContainerIn& xs)
thread_results);
}

// API search type: transform_convert_parallelly : ((a -> b), [a]) -> [b]
// fwd bind count: 1
// transform_convert_parallelly((*2), [1, 3, 4]) == [2, 6, 8]
// Same as transform_convert, but can utilize multiple CPUs by using std::launch::async.
// Only makes sense if one run of the provided function
// takes enough time to justify the synchronization overhead.
// One thread per container element is spawned.
template <typename ContainerOut, typename F, typename ContainerIn>
ContainerOut transform_convert_parallelly(F f, const ContainerIn& xs)
{
using X = typename ContainerIn::value_type;
internal::trigger_static_asserts<internal::unary_function_tag, F, X>();
auto handles = transform([&f](const X& x) {
return std::async(std::launch::async, [&x, &f]() {
return internal::invoke(f, x);
});
},
xs);

internal::trigger_static_asserts<internal::unary_function_tag, F, typename ContainerIn::value_type>();
ContainerOut ys;
internal::prepare_container(ys, size_of_cont(xs));
auto it = internal::get_back_inserter<ContainerOut>(ys);
for (auto& handle : handles) {
*it = handle.get();
}
return ys;
}

// API search type: reduce_parallelly : (((a, a) -> a), a, [a]) -> a
// fwd bind count: 2
// reduce_parallelly((+), 0, [1, 2, 3]) == (0+1+2+3) == 6
Expand Down Expand Up @@ -15159,6 +15188,7 @@ fplus_curry_define_fn_1(apply_functions)
fplus_curry_define_fn_2(apply_function_n_times)
fplus_curry_define_fn_1(transform_parallelly)
fplus_curry_define_fn_2(transform_parallelly_n_threads)
fplus_curry_define_fn_1(transform_convert_parallelly)
fplus_curry_define_fn_2(reduce_parallelly)
fplus_curry_define_fn_3(reduce_parallelly_n_threads)
fplus_curry_define_fn_1(reduce_1_parallelly)
Expand Down Expand Up @@ -15768,6 +15798,7 @@ fplus_fwd_define_fn_1(apply_functions)
fplus_fwd_define_fn_2(apply_function_n_times)
fplus_fwd_define_fn_1(transform_parallelly)
fplus_fwd_define_fn_2(transform_parallelly_n_threads)
fplus_fwd_define_fn_1(transform_convert_parallelly)
fplus_fwd_define_fn_2(reduce_parallelly)
fplus_fwd_define_fn_3(reduce_parallelly_n_threads)
fplus_fwd_define_fn_1(reduce_1_parallelly)
Expand Down Expand Up @@ -16057,6 +16088,7 @@ fplus_fwd_flip_define_fn_1(shuffle)
fplus_fwd_flip_define_fn_1(random_element)
fplus_fwd_flip_define_fn_1(apply_functions)
fplus_fwd_flip_define_fn_1(transform_parallelly)
fplus_fwd_flip_define_fn_1(transform_convert_parallelly)
fplus_fwd_flip_define_fn_1(reduce_1_parallelly)
fplus_fwd_flip_define_fn_1(keep_if_parallelly)
fplus_fwd_flip_define_fn_1(show_cont_with)
Expand Down
1 change: 1 addition & 0 deletions test/transform_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ TEST_CASE("transform_test - transform")
REQUIRE_EQ(transform_parallelly(squareLambda, intList), IntList({ 1, 4, 4, 9, 4 }));
REQUIRE_EQ(transform_parallelly_n_threads(3, squareLambda, intList), IntList({ 1, 4, 4, 9, 4 }));
REQUIRE_EQ(transform_convert<IntList>(squareLambda, xs), IntList({ 1, 4, 4, 9, 4 }));
REQUIRE_EQ(transform_convert_parallelly<IntList>(squareLambda, xs), IntList({ 1, 4, 4, 9, 4 }));

REQUIRE_EQ(transform(squareLambda, std::set<int>({ 1, 2, 3, -3 })), std::set<int>({ 1, 4, 9 }));
REQUIRE_EQ(transform_inner(intTimes2, IntVectors({ { 1, 3, 4 }, { 1, 2 } })), IntVectors({ { 2, 6, 8 }, { 2, 4 } }));
Expand Down
Loading