-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1e2ec3
commit c839e5c
Showing
3 changed files
with
205 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
//================================================================================================== | ||
//====================================================================================================================== | ||
/** | ||
KIWAKU - Containers Well Made | ||
Copyright : KIWAKU Project Contributors | ||
SPDX-License-Identifier: BSL-1.0 | ||
**/ | ||
//================================================================================================== | ||
//====================================================================================================================== | ||
#pragma once | ||
|
||
#include <kwk/concepts/container.hpp> | ||
#include <kwk/algorithm/algos/for_each.hpp> | ||
#include <kwk/detail/abi.hpp> | ||
#include <cstddef> | ||
#include <utility> | ||
#include <kwk/context/context.hpp> | ||
|
||
namespace kwk | ||
{ | ||
// Transform is not a required part of contexts anymore | ||
template< typename Context, typename Func, concepts::container Out | ||
, concepts::container C0, concepts::container... Cs | ||
> | ||
constexpr void transform(Context& ctx,Func&& f, Out& out, C0 const& c0, Cs const&... cs) | ||
{ | ||
ctx.map ( [&](auto& o, auto const& i0, auto const&... in) { o = KWK_FWD(f)(i0, in...); } | ||
, ctx.out(out), ctx.in(c0), ctx.in(cs)... | ||
); | ||
} | ||
|
||
template< typename Func, concepts::container Out | ||
, concepts::container C0, concepts::container... Cs | ||
> | ||
constexpr auto transform(Func f, Out& out, C0&& c0, Cs&&... cs) | ||
constexpr void transform(Func&& f, Out& out, C0&& c0, Cs&&... cs) | ||
{ | ||
kwk::for_each([&](auto... is) { out(is...) = f(KWK_FWD(c0)(is...), KWK_FWD(cs)(is...)...); }, out.shape() ); | ||
kwk::transform(cpu, KWK_FWD(f), out, KWK_FWD(c0), KWK_FWD(cs)...); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//====================================================================================================================== | ||
/* | ||
KIWAKU - Containers Well Made | ||
Copyright : KIWAKU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#include <kwk/algorithm/algos/for_each.hpp> | ||
#include <kwk/algorithm/algos/transform.hpp> | ||
#include <kwk/container.hpp> | ||
#include "test.hpp" | ||
#include "../generic/transform.hpp" | ||
|
||
// TODO: update these tests | ||
|
||
TTS_CASE("Check for kwk::transform(value, new_value) 1D - CPU context") | ||
{ | ||
kwk::test::transform_value_new_value_1D(kwk::cpu); | ||
}; | ||
|
||
TTS_CASE("Check for kwk::transform(value, new_value) 2D - CPU context") | ||
{ | ||
kwk::test::transform_value_new_value_2D(kwk::cpu); | ||
}; | ||
|
||
TTS_CASE("Check for kwk::transform(value, new_value) 3D - CPU context") | ||
{ | ||
kwk::test::transform_value_new_value_3D(kwk::cpu); | ||
}; | ||
|
||
TTS_CASE("Check for kwk::transform(value, new_value) 4D - CPU context") | ||
{ | ||
kwk::test::transform_value_new_value_4D(kwk::cpu); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters