-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update concatenate view to handle maybe type * add stack * add hstack * add vstack * add stack, vstack, hstack tests * fix ci * fix gcc werror
- Loading branch information
Showing
39 changed files
with
3,456 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef NMTOOLS_ARRAY_ARRAY_HSTACK_HPP | ||
#define NMTOOLS_ARRAY_ARRAY_HSTACK_HPP | ||
|
||
#include "nmtools/array/view/hstack.hpp" | ||
#include "nmtools/array/eval.hpp" | ||
|
||
namespace nmtools::array | ||
{ | ||
template <typename output_t=none_t, typename context_t=none_t, typename resolver_t=eval_result_t<>, | ||
typename lhs_array_t, typename rhs_array_t> | ||
constexpr auto hstack(const lhs_array_t& lhs, const rhs_array_t& rhs, | ||
context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value<resolver_t> resolver=meta::as_value_v<resolver_t>) | ||
{ | ||
auto result = view::hstack(lhs,rhs); | ||
return eval(result | ||
, nmtools::forward<context_t>(context) | ||
, nmtools::forward<output_t>(output) | ||
, resolver | ||
); | ||
} // hstack | ||
} // namespace nmtools::array | ||
|
||
#endif // NMTOOLS_ARRAY_ARRAY_HSTACK_HPP |
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,23 @@ | ||
#ifndef NMTOOLS_ARRAY_ARRAY_STACK_HPP | ||
#define NMTOOLS_ARRAY_ARRAY_STACK_HPP | ||
|
||
#include "nmtools/array/view/stack.hpp" | ||
#include "nmtools/array/eval.hpp" | ||
|
||
namespace nmtools::array | ||
{ | ||
template <typename output_t=none_t, typename context_t=none_t, typename resolver_t=eval_result_t<>, | ||
typename lhs_array_t, typename rhs_array_t, typename axis_t=meta::ct<0>> | ||
constexpr auto stack(const lhs_array_t& lhs, const rhs_array_t& rhs, axis_t axis=axis_t{} | ||
, context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value<resolver_t> resolver=meta::as_value_v<resolver_t>) | ||
{ | ||
auto result = view::stack(lhs,rhs,axis); | ||
return eval(result | ||
, nmtools::forward<context_t>(context) | ||
, nmtools::forward<output_t>(output) | ||
, resolver | ||
); | ||
} // stack | ||
} // namespace nmtools::array | ||
|
||
#endif // NMTOOLS_ARRAY_ARRAY_STACK_HPP |
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,23 @@ | ||
#ifndef NMTOOLS_ARRAY_ARRAY_VSTACK_HPP | ||
#define NMTOOLS_ARRAY_ARRAY_VSTACK_HPP | ||
|
||
#include "nmtools/array/view/vstack.hpp" | ||
#include "nmtools/array/eval.hpp" | ||
|
||
namespace nmtools::array | ||
{ | ||
template <typename output_t=none_t, typename context_t=none_t, typename resolver_t=eval_result_t<>, | ||
typename lhs_array_t, typename rhs_array_t> | ||
constexpr auto vstack(const lhs_array_t& lhs, const rhs_array_t& rhs, | ||
context_t&& context=context_t{}, output_t&& output=output_t{},meta::as_value<resolver_t> resolver=meta::as_value_v<resolver_t>) | ||
{ | ||
auto result = view::vstack(lhs,rhs); | ||
return eval(result | ||
, nmtools::forward<context_t>(context) | ||
, nmtools::forward<output_t>(output) | ||
, resolver | ||
); | ||
} // vstack | ||
} // namespace nmtools::array | ||
|
||
#endif // NMTOOLS_ARRAY_ARRAY_VSTACK_HPP |
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,25 @@ | ||
#ifndef NMTOOLS_ARRAY_FUNCTIONAL_HSTACK_HPP | ||
#define NMTOOLS_ARRAY_FUNCTIONAL_HSTACK_HPP | ||
|
||
#include "nmtools/array/functional/functor.hpp" | ||
#include "nmtools/array/functional/indexing.hpp" | ||
#include "nmtools/array/view/hstack.hpp" | ||
|
||
namespace nmtools::functional | ||
{ | ||
namespace fun | ||
{ | ||
struct hstack_t | ||
{ | ||
template <typename...args_t> | ||
constexpr auto operator()(const args_t&...args) const | ||
{ | ||
return view::hstack(args...); | ||
} | ||
}; | ||
} | ||
|
||
constexpr inline auto hstack = functor_t{binary_fmap_t<fun::hstack_t>{}}; | ||
} // namespace nmtools::functional | ||
|
||
#endif // NMTOOLS_ARRAY_FUNCTIONAL_HSTACK_HPP |
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,25 @@ | ||
#ifndef NMTOOLS_ARRAY_FUNCTIONAL_STACK_HPP | ||
#define NMTOOLS_ARRAY_FUNCTIONAL_STACK_HPP | ||
|
||
#include "nmtools/array/functional/functor.hpp" | ||
#include "nmtools/array/functional/indexing.hpp" | ||
#include "nmtools/array/view/stack.hpp" | ||
|
||
namespace nmtools::functional | ||
{ | ||
namespace fun | ||
{ | ||
struct stack_t | ||
{ | ||
template <typename...args_t> | ||
constexpr auto operator()(const args_t&...args) const | ||
{ | ||
return view::stack(args...); | ||
} | ||
}; | ||
} | ||
|
||
constexpr inline auto stack = functor_t{binary_fmap_t<fun::stack_t>{}}; | ||
} // namespace nmtools::functional | ||
|
||
#endif // NMTOOLS_ARRAY_FUNCTIONAL_STACK_HPP |
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,25 @@ | ||
#ifndef NMTOOLS_ARRAY_FUNCTIONAL_VSTACK_HPP | ||
#define NMTOOLS_ARRAY_FUNCTIONAL_VSTACK_HPP | ||
|
||
#include "nmtools/array/functional/functor.hpp" | ||
#include "nmtools/array/functional/indexing.hpp" | ||
#include "nmtools/array/view/vstack.hpp" | ||
|
||
namespace nmtools::functional | ||
{ | ||
namespace fun | ||
{ | ||
struct vstack_t | ||
{ | ||
template <typename...args_t> | ||
constexpr auto operator()(const args_t&...args) const | ||
{ | ||
return view::vstack(args...); | ||
} | ||
}; | ||
} | ||
|
||
constexpr inline auto vstack = functor_t{binary_fmap_t<fun::vstack_t>{}}; | ||
} // namespace nmtools::functional | ||
|
||
#endif // NMTOOLS_ARRAY_FUNCTIONAL_VSTACK_HPP |
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
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
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
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,79 @@ | ||
#ifndef NMTOOLS_ARRAY_INDEX_HSTACK_HPP | ||
#define NMTOOLS_ARRAY_INDEX_HSTACK_HPP | ||
|
||
#include "nmtools/meta.hpp" | ||
#include "nmtools/array/shape.hpp" | ||
|
||
namespace nmtools::index | ||
{ | ||
struct hstack_axis_t {}; | ||
|
||
template <typename lhs_shape_t, typename rhs_shape_t> | ||
constexpr auto hstack_axis([[maybe_unused]] const lhs_shape_t& lhs_shape, const rhs_shape_t&) | ||
{ | ||
using result_t = meta::resolve_optype_t<hstack_axis_t,lhs_shape_t,rhs_shape_t>; | ||
|
||
auto result = result_t {}; | ||
|
||
if constexpr (!meta::is_constant_index_v<result_t>) { | ||
auto lhs_dim = len(lhs_shape); | ||
result = ((lhs_dim == 1) ? 0 : 1); | ||
} | ||
|
||
return result; | ||
} | ||
} // namespace nmtools::index | ||
|
||
namespace nmtools::meta | ||
{ | ||
namespace error | ||
{ | ||
template <typename...> | ||
struct HSTACK_AXIS_UNSUPPORTED : detail::fail_t {}; | ||
} | ||
|
||
template <typename lhs_shape_t, typename rhs_shape_t> | ||
struct resolve_optype<void,index::hstack_axis_t,lhs_shape_t,rhs_shape_t> | ||
{ | ||
static constexpr auto vtype = [](){ | ||
constexpr auto lhs_dim = len_v<lhs_shape_t>; | ||
constexpr auto rhs_dim = len_v<rhs_shape_t>; | ||
if constexpr ((lhs_dim > 0) && (lhs_dim == rhs_dim)) { | ||
using type = ct<((lhs_dim == 1) ? 0 : 1)>; | ||
return as_value_v<type>; | ||
} else if constexpr (is_index_array_v<lhs_shape_t> | ||
&& is_index_array_v<rhs_shape_t> | ||
) { | ||
using type = nm_size_t; | ||
return as_value_v<type>; | ||
} else { | ||
using type = error::HSTACK_AXIS_UNSUPPORTED<lhs_shape_t,rhs_shape_t>; | ||
return as_value_v<type>; | ||
} | ||
}(); | ||
using type = type_t<decltype(vtype)>; | ||
}; | ||
} // namespace nmtools::meta | ||
|
||
#endif // NMTOOLS_ARRAY_INDEX_HSTACK_HPP | ||
|
||
#ifndef NMTOOLS_ARRAY_VIEW_HSTACK_HPP | ||
#define NMTOOLS_ARRAY_VIEW_HSTACK_HPP | ||
|
||
#include "nmtools/meta.hpp" | ||
#include "nmtools/array/view/concatenate.hpp" | ||
|
||
namespace nmtools::view | ||
{ | ||
template <typename lhs_t, typename rhs_t> | ||
constexpr auto hstack(const lhs_t& lhs, const rhs_t& rhs) | ||
{ | ||
auto axis = index::hstack_axis( | ||
shape<true>(lhs) | ||
, shape<true>(rhs) | ||
); | ||
return concatenate(lhs,rhs,axis); | ||
} | ||
} // namespace nmtools::view | ||
|
||
#endif // NMTOOLS_ARRAY_VIEW_HSTACK_HPP |
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
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
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,20 @@ | ||
#ifndef NMTOOLS_ARRAY_VIEW_STACK_HPP | ||
#define NMTOOLS_ARRAY_VIEW_STACK_HPP | ||
|
||
#include "nmtools/array/view/concatenate.hpp" | ||
#include "nmtools/array/view/expand_dims.hpp" | ||
|
||
namespace nmtools::view | ||
{ | ||
template <typename lhs_t, typename rhs_t, typename axis_t=meta::ct<0>> | ||
constexpr auto stack(const lhs_t& lhs, const rhs_t& rhs, axis_t axis=axis_t{}) | ||
{ | ||
return concatenate( | ||
expand_dims(lhs,axis) | ||
, expand_dims(rhs,axis) | ||
, axis | ||
); | ||
} | ||
} // namespace nmtools::view | ||
|
||
#endif // NMTOOLS_ARRAY_VIEW_STACK_HPP |
Oops, something went wrong.