Skip to content
Merged
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 btas/generic/permute.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace btas {
++itrY;
}
};
if (r_is_permutable)
if constexpr (r_is_permutable)
do_perm(X, Y, permute(r, p));
else {
do_perm(X, Y, permute(btas::Range(r.lobound(), r.upbound(), r.stride()), p));
Expand Down
20 changes: 20 additions & 0 deletions btas/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <functional>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>

namespace btas {
Expand Down Expand Up @@ -144,6 +145,25 @@ namespace btas {
}
}

/// construct from \c range object, fill each element from \c gen called on
/// the element's multi-index. \c gen must be callable with the range's
/// iteration value (its multi-index) and return a value convertible to
/// \c value_type.
template <typename Range, typename F,
typename = std::enable_if_t<
btas::is_boxrange<Range>::value &&
std::is_invocable_r_v<
value_type, F,
decltype(*std::begin(std::declval<const range_type&>()))>>>
Tensor(const Range& range, F&& gen)
Comment thread
evaleev marked this conversation as resolved.
: range_(range.lobound(), range.upbound()) {
array_adaptor<storage_type>::resize(storage_, range_.area());
auto out_it = begin();
for (auto&& idx : range_) {
*out_it++ = std::invoke(std::forward<F>(gen), idx);
}
Comment thread
evaleev marked this conversation as resolved.
}

/// construct from \c range and \c storage
template <typename Range, typename Storage>
Tensor(const Range& range, const Storage& storage,
Expand Down
Loading
Loading