Skip to content

Instantly share code, notes, and snippets.

@amitsingh19975
Created June 7, 2019 08:00
Show Gist options
  • Save amitsingh19975/06f3dc5a53079ef3f009040524707edd to your computer and use it in GitHub Desktop.
Save amitsingh19975/06f3dc5a53079ef3f009040524707edd to your computer and use it in GitHub Desktop.
#include <boost/numeric/ublas/functional.hpp>
#include <boost/numeric/ublas/tensor/extents.hpp>
#include <boost/numeric/ublas/tensor/static_extents.hpp>
#include <boost/numeric/ublas/tensor/strides.hpp>
#include <boost/numeric/ublas/tensor/static_strides.hpp>
#include <boost/core/demangle.hpp>
#include <complex>
#include <iostream>
#include <type_traits>
namespace boost::numeric::ublas{
template<typename T, typename E = shape<dynamic_rank>, typename F = first_order, typename A = std::vector<T>>
struct tensor{
using base_type = A;
using extent_type = E;
using stride_type = stride_t<E,F>;
tensor(){
data_ = base_type(extents_.size());
}
/* .... */
// private:
base_type data_;
extent_type extents_;
stride_type strides_;
};
}
using namespace std;
using namespace boost::numeric::ublas;
template<typename T>
char const* get_type(T&& t){
return typeid(t).name();
}
int main(int argc, char const *argv[]) {
tensor<int> t1;
cout<<boost::core::demangle(get_type(t1.extents_))<<'\n'; // basic_extents<T>
cout<<boost::core::demangle(get_type(t1.strides_))<<'\n'; // basic_strides<T,first_order>
tensor<int,shape<4,1,2,3,4>> t2;
cout<<boost::core::demangle(get_type(t2.extents_))<<'\n'; // static_extents<T, 4,1,2,3,4>
cout<<boost::core::demangle(get_type(t2.strides_))<<'\n'; // static_strides<static_extents<T, 4,1,2,3,4>,first_order>
tensor<int,shape<4>> t3;
cout<<boost::core::demangle(get_type(t3.extents_))<<'\n'; // static_extents<T, 4>
cout<<boost::core::demangle(get_type(t3.strides_))<<'\n'; // static_strides<static_extents<T, 4>,first_order>
tensor<int,shape<4,dynamic_extent,2,dynamic_extent,4>> t4;
cout<<boost::core::demangle(get_type(t4.extents_))<<'\n'; // static_extents<T, 4, -1, 2, -1, 4>
cout<<boost::core::demangle(get_type(t4.strides_))<<'\n'; // static_strides<static_extents<T, 4, -1, 2, -1, 4>,first_order>
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment