-
Notifications
You must be signed in to change notification settings - Fork 152
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
Features/subtensor #126
Open
amitsingh19975
wants to merge
9
commits into
develop
Choose a base branch
from
features/subtensor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Features/subtensor #126
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f91fea9
rebase subtensor
94ae6a7
add subtensor test
1513a07
add access functions for tensor and subtensor.
64c661b
stride creation changed.
ae385d4
fix tesor-vector multiplication for subtensor.
0df6293
improve product function for tensor-times-vector.
949ffaa
remove difference between strides and slices.
bassoy 50e19e5
fix wrong mtv call from test multiplication.
bassoy 997df31
revert stride computation for vectors.
bassoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,55 +1,5 @@ | ||
HEADERS += \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/algorithms.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/expression.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/expression_evaluation.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/functions.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/index.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/index_functions.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/layout.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/multi_index.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/multi_index_utility.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/multiplication.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/operators_arithmetic.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/operators_comparison.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/ostream.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tags.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/concepts.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/type_traits.hpp | ||
|
||
|
||
HEADERS += \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/traits/basic_type_traits.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/traits/storage_traits.hpp | ||
|
||
HEADERS += \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_dynamic_size.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_static_size.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_static_functions.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_static.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_base.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/extents_functions.hpp | ||
|
||
|
||
HEADERS += \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/tensor_core.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/tensor_engine.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/tensor_static.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/tensor_static_rank.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/tensor_dynamic.hpp | ||
|
||
|
||
HEADERS += \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/inner_prod.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/init.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/outer_prod.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/trans.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/norm.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/imag.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/real.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/conj.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/tensor_times_vector.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/tensor_times_matrix.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/tensor_times_tensor.hpp \ | ||
$${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/reshape.hpp | ||
HEADERS += $${INCLUDE_DIR}/boost/numeric/ublas/tensor/*.hpp | ||
HEADERS += $${INCLUDE_DIR}/boost/numeric/ublas/tensor/traits/*.hpp | ||
HEADERS += $${INCLUDE_DIR}/boost/numeric/ublas/tensor/extents/*.hpp | ||
HEADERS += $${INCLUDE_DIR}/boost/numeric/ublas/tensor/tensor/*.hpp | ||
HEADERS += $${INCLUDE_DIR}/boost/numeric/ublas/tensor/function/*.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,197 @@ | ||
// | ||
// Copyright (c) 2020, Cem Bassoy, [email protected] | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See | ||
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
// The authors gratefully acknowledge the support of | ||
// Fraunhofer IOSB, Ettlingen, Germany | ||
// | ||
|
||
|
||
#ifndef BOOST_UBLAS_TENSOR_ACCESS_HPP | ||
#define BOOST_UBLAS_TENSOR_ACCESS_HPP | ||
|
||
|
||
#include <algorithm> | ||
#include <numeric> | ||
#include <functional> | ||
|
||
#include <boost/numeric/ublas/functional.hpp> | ||
|
||
|
||
namespace boost::numeric::ublas { | ||
|
||
using first_order = column_major; | ||
using last_order = row_major; | ||
|
||
} // namespace boost::numeric::ublas | ||
|
||
namespace boost::numeric::ublas::detail{ | ||
|
||
|
||
/** \brief Computes a single index from multi-index of a tensor or subtensor | ||
* | ||
* \param i iterator to a multi-index vector of length std::distance(begin,end) | ||
* \param ip iterator to a multi-index vector of length std::distance(begin,end) | ||
* \param w iterator to a stride vector of length std::distance(begin,end) or greater | ||
*/ | ||
template<typename InputIt1, typename InputIt2> | ||
constexpr inline auto compute_single_index(InputIt1 i, InputIt1 ip, InputIt2 w) | ||
{ | ||
return std::inner_product(i,ip,w,0ul,std::plus<>{},std::multiplies<>{}); | ||
} | ||
|
||
|
||
/** \brief Computes a single index from a multi-index of a tensor or subtensor | ||
* | ||
* \param i iterator to a multi-index vector of length std::distance(begin,end) | ||
* \param ip iterator to a multi-index vector of length std::distance(begin,end) | ||
* \param w iterator to a stride vector of length std::distance(begin,end) or greater | ||
*/ | ||
template<unsigned p, typename InputIt1, typename InputIt2> | ||
constexpr inline auto compute_single_index(InputIt1 i, InputIt1 /*ip*/, InputIt2 w) | ||
{ | ||
if constexpr(p==0u) return 0ul; | ||
else if constexpr(p >1u) return compute_single_index<p-1>(i,i,w)+i[p-1]*w[p-1]; | ||
else return i[p-1]*w[p-1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. different indentation for else return i[p-1]*w[p-1];
^ Reported as warning by clang-tidy. |
||
} | ||
|
||
/** @brief Computes a multi-index from single index of a tensor or subtensor | ||
* | ||
* j = compute_single_index (i, ip, w) | ||
* compute_multi_index (j, w, wp, k) with k == i | ||
* | ||
* @param w begin input iterator to a container with tensor or subtensor strides of length std::distance(begin,end) | ||
* @param wp end input iterator to a container with tensor or subtensor strides of length std::distance(begin,end) | ||
* @param i begin output iterator to a container with tensor or subtensor indices length std::distance(begin,end) or greater | ||
*/ | ||
template<typename InputIt1, typename OutputIt, typename LayoutType> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, LayoutType /*unused*/); | ||
//{ | ||
// if(w == wp) | ||
// return; | ||
|
||
// auto wr = std::make_reverse_iterator( w ); | ||
// auto wrp = std::make_reverse_iterator( wp ); | ||
// auto ir = std::make_reverse_iterator( i+std::distance(w,wp) ); | ||
|
||
// std::transform(wrp,wr,ir, [&j](auto v) { auto k=j/v; j-=v*k; return k; } ); | ||
//} | ||
|
||
|
||
template<typename InputIt1, typename OutputIt> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, first_order /*unused*/) | ||
{ | ||
if(w == wp) | ||
return; | ||
|
||
auto wr = std::make_reverse_iterator( w ); | ||
auto wrp = std::make_reverse_iterator( wp ); | ||
auto ir = std::make_reverse_iterator( i+std::distance(w,wp) ); | ||
|
||
std::transform(wrp,wr,ir, [&j](auto v) { auto k=j/v; j-=v*k; return k; } ); | ||
} | ||
|
||
template<typename InputIt1, typename OutputIt> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, last_order /*unused*/) | ||
{ | ||
if(w == wp) | ||
return; | ||
|
||
std::transform(w,wp,i, [&j](auto v) { auto k=j/v; j-=v*k; return k; } ); | ||
} | ||
|
||
|
||
|
||
|
||
//template<typename InputIt1, typename OutputIt> | ||
//constexpr inline void compute_multi_index_last(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i) | ||
//{ | ||
// if(w == wp) | ||
// return; | ||
//// for(unsigned r = 0ul; r < p; ++r) { | ||
//// i[r] = kq/w[r]; | ||
//// kq -= w[r]*i[r]; | ||
//// } | ||
// std::transform(w,wp,i, [&j](auto v) { auto k=j/v; j-=v*k; return k; } ); | ||
//} | ||
|
||
//template<typename InputIt1, typename OutputIt> | ||
//constexpr inline void compute_multi_index_first(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i) | ||
//{ | ||
// if(w == wp) | ||
// return; | ||
|
||
//// for(int r = p-1; r >= 0; --r) { | ||
//// i[r] = kq/w[r]; | ||
//// kq -= w[r]*i[r]; | ||
//// } | ||
|
||
// auto wr = std::make_reverse_iterator( w ); | ||
// auto wrp = std::make_reverse_iterator( wp ); | ||
// auto ir = std::make_reverse_iterator( i+std::distance(w,wp) ); | ||
|
||
// std::transform(wrp,wr,ir, [&j](auto v) { auto k=j/v; j-=v*k; return k; } ); | ||
//} | ||
|
||
|
||
/** @brief Computes a single index from a multi-index of a dense tensor or subtensor | ||
* | ||
* @param j single index that is transformed into a multi-index | ||
* @param w begin input iterator to a container with strides of length p | ||
* @param i begin input iterator to a container with indices of length p or greater | ||
*/ | ||
template<unsigned p, typename InputIt1, typename OutputIt, typename LayoutType> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 /*wp*/, OutputIt i, LayoutType); | ||
|
||
|
||
template<unsigned p, typename InputIt1, typename OutputIt> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 /*wp*/, OutputIt i, first_order o) | ||
{ | ||
if constexpr (p==0u) return; | ||
else if constexpr (p >1u) {i[p-1]=j/w[p-1]; compute_multi_index<p-1>(j-w[p-1]*i[p-1],w,w,i,o); } | ||
else {i[p-1]=j/w[p-1]; } | ||
} | ||
|
||
|
||
|
||
template<unsigned p, unsigned k = 0, typename InputIt1, typename OutputIt> | ||
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 /*wp*/, OutputIt i, last_order o) | ||
{ | ||
if constexpr (p == 0u ) { return; } | ||
else if constexpr (k+1 == p) {i[k]=j/w[k]; } | ||
else {i[k]=j/w[k]; compute_multi_index<p,k+1>(j-w[k]*i[k],w,w,i,o); } | ||
} | ||
|
||
|
||
|
||
//template<unsigned p, typename InputIt1, typename OutputIt, unsigned k = 0> | ||
//constexpr inline void compute_multi_index_last(std::size_t j, InputIt1 w, InputIt1 /*wp*/, OutputIt i) | ||
//{ | ||
// if constexpr (p == 0u ) return; | ||
// else if constexpr (k+1 == p) {i[k]=j/w[k]; } | ||
// else {i[k]=j/w[k]; compute_multi_index_last<p,k+1>(j-w[k]*i[k],w,w,i); } | ||
//} | ||
|
||
|
||
/** @brief Computes a single (relative memory) index of a dense tensor from a single index of one of its subtensor | ||
* | ||
* @param jv single index of a subtensor that is transformed into a single index of a dense tensor | ||
* @param w begin input iterator of a container with tensor strides of length std::distance(w,wp) | ||
* @param wp end input iterator of a container with tensor strides of length std::distance(w,wp) | ||
* @param v begin input iterator of a container with subtensor strides of length std::distance(w,wp) or greater | ||
*/ | ||
template<typename InputIt1, typename InputIt2> | ||
constexpr inline auto compute_single_index(std::size_t jv, InputIt1 w, InputIt1 wp, InputIt2 v) | ||
{ | ||
return std::inner_product(w,wp,v,0ul, | ||
std::plus<>{}, | ||
[&jv](auto ww, auto vv) { auto k=jv/vv; jv-=vv*k; return ww*k; } | ||
); | ||
} | ||
|
||
} // namespace boost::numeric::ublas::detail | ||
|
||
#endif |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
#include <type_traits> | ||
|
||
|
||
namespace boost::numeric::ublas{ | ||
|
||
template<typename T> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
different indentation for
if
and correspondingelse
[readability-misleading-indentation]Reported as warning by clang-tidy.