tensor.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. // Copyright (c) 2018-2019
  2. // Cem Bassoy
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // The authors gratefully acknowledge the support of
  9. // Fraunhofer and Google in producing this work
  10. // which started as a Google Summer of Code project.
  11. //
  12. /// \file tensor.hpp Definition for the tensor template class
  13. #ifndef BOOST_UBLAS_TENSOR_IMPL_HPP
  14. #define BOOST_UBLAS_TENSOR_IMPL_HPP
  15. #include <boost/config.hpp>
  16. #include <initializer_list>
  17. #include "algorithms.hpp"
  18. #include "expression.hpp"
  19. #include "expression_evaluation.hpp"
  20. #include "extents.hpp"
  21. #include "strides.hpp"
  22. #include "index.hpp"
  23. namespace boost { namespace numeric { namespace ublas {
  24. template<class T, class F, class A>
  25. class tensor;
  26. template<class T, class F, class A>
  27. class matrix;
  28. template<class T, class A>
  29. class vector;
  30. ///** \brief Base class for Tensor container models
  31. // *
  32. // * it does not model the Tensor concept but all derived types should.
  33. // * The class defines a common base type and some common interface for all
  34. // * statically derived Tensor classes
  35. // * We implement the casts to the statically derived type.
  36. // */
  37. //template<class C>
  38. //class tensor_container:
  39. // public detail::tensor_expression<C>
  40. //{
  41. //public:
  42. // static const unsigned complexity = 0;
  43. // typedef C container_type;
  44. // typedef tensor_tag type_category;
  45. // BOOST_UBLAS_INLINE
  46. // const container_type &operator () () const {
  47. // return *static_cast<const container_type *> (this);
  48. // }
  49. // BOOST_UBLAS_INLINE
  50. // container_type &operator () () {
  51. // return *static_cast<container_type *> (this);
  52. // }
  53. //};
  54. /** @brief A dense tensor of values of type \c T.
  55. *
  56. * For a \f$n\f$-dimensional tensor \f$v\f$ and \f$0\leq i < n\f$ every element \f$v_i\f$ is mapped
  57. * to the \f$i\f$-th element of the container. A storage type \c A can be specified which defaults to \c unbounded_array.
  58. * Elements are constructed by \c A, which need not initialise their value.
  59. *
  60. * @tparam T type of the objects stored in the tensor (like int, double, complex,...)
  61. * @tparam A The type of the storage array of the tensor. Default is \c unbounded_array<T>. \c <bounded_array<T> and \c std::vector<T> can also be used
  62. */
  63. template<class T, class F = first_order, class A = std::vector<T,std::allocator<T>> >
  64. class tensor:
  65. public detail::tensor_expression<tensor<T, F, A>,tensor<T, F, A>>
  66. {
  67. static_assert( std::is_same<F,first_order>::value ||
  68. std::is_same<F,last_order >::value, "boost::numeric::tensor template class only supports first- or last-order storage formats.");
  69. using self_type = tensor<T, F, A>;
  70. public:
  71. template<class derived_type>
  72. using tensor_expression_type = detail::tensor_expression<self_type,derived_type>;
  73. template<class derived_type>
  74. using matrix_expression_type = matrix_expression<derived_type>;
  75. template<class derived_type>
  76. using vector_expression_type = vector_expression<derived_type>;
  77. using super_type = tensor_expression_type<self_type>;
  78. // static_assert(std::is_same_v<tensor_expression_type<self_type>, detail::tensor_expression<tensor<T,F,A>,tensor<T,F,A>>>, "tensor_expression_type<self_type>");
  79. using array_type = A;
  80. using layout_type = F;
  81. using size_type = typename array_type::size_type;
  82. using difference_type = typename array_type::difference_type;
  83. using value_type = typename array_type::value_type;
  84. using reference = typename array_type::reference;
  85. using const_reference = typename array_type::const_reference;
  86. using pointer = typename array_type::pointer;
  87. using const_pointer = typename array_type::const_pointer;
  88. using iterator = typename array_type::iterator;
  89. using const_iterator = typename array_type::const_iterator;
  90. using reverse_iterator = typename array_type::reverse_iterator;
  91. using const_reverse_iterator = typename array_type::const_reverse_iterator;
  92. using tensor_temporary_type = self_type;
  93. using storage_category = dense_tag;
  94. using strides_type = basic_strides<std::size_t,layout_type>;
  95. using extents_type = shape;
  96. using matrix_type = matrix<value_type,layout_type,array_type>;
  97. using vector_type = vector<value_type,array_type>;
  98. /** @brief Constructs a tensor.
  99. *
  100. * @note the tensor is empty.
  101. * @note the tensor needs to reshaped for further use.
  102. *
  103. */
  104. BOOST_UBLAS_INLINE
  105. constexpr tensor ()
  106. : tensor_expression_type<self_type>() // container_type
  107. , extents_()
  108. , strides_()
  109. , data_()
  110. {
  111. }
  112. /** @brief Constructs a tensor with an initializer list
  113. *
  114. * By default, its elements are initialized to 0.
  115. *
  116. * @code tensor<float> A{4,2,3}; @endcode
  117. *
  118. * @param l initializer list for setting the dimension extents of the tensor
  119. */
  120. explicit BOOST_UBLAS_INLINE
  121. tensor (std::initializer_list<size_type> l)
  122. : tensor_expression_type<self_type>()
  123. , extents_ (std::move(l))
  124. , strides_ (extents_)
  125. , data_ (extents_.product())
  126. {
  127. }
  128. /** @brief Constructs a tensor with a \c shape
  129. *
  130. * By default, its elements are initialized to 0.
  131. *
  132. * @code tensor<float> A{extents{4,2,3}}; @endcode
  133. *
  134. * @param s initial tensor dimension extents
  135. */
  136. explicit BOOST_UBLAS_INLINE
  137. tensor (extents_type const& s)
  138. : tensor_expression_type<self_type>() //tensor_container<self_type>()
  139. , extents_ (s)
  140. , strides_ (extents_)
  141. , data_ (extents_.product())
  142. {}
  143. /** @brief Constructs a tensor with a \c shape and initiates it with one-dimensional data
  144. *
  145. * @code tensor<float> A{extents{4,2,3}, array }; @endcode
  146. *
  147. *
  148. * @param s initial tensor dimension extents
  149. * @param a container of \c array_type that is copied according to the storage layout
  150. */
  151. BOOST_UBLAS_INLINE
  152. tensor (extents_type const& s, const array_type &a)
  153. : tensor_expression_type<self_type>() //tensor_container<self_type>()
  154. , extents_ (s)
  155. , strides_ (extents_)
  156. , data_ (a)
  157. {
  158. if(this->extents_.product() != this->data_.size())
  159. throw std::runtime_error("Error in boost::numeric::ublas::tensor: size of provided data and specified extents do not match.");
  160. }
  161. /** @brief Constructs a tensor using a shape tuple and initiates it with a value.
  162. *
  163. * @code tensor<float> A{extents{4,2,3}, 1 }; @endcode
  164. *
  165. * @param e initial tensor dimension extents
  166. * @param i initial value of all elements of type \c value_type
  167. */
  168. BOOST_UBLAS_INLINE
  169. tensor (extents_type const& e, const value_type &i)
  170. : tensor_expression_type<self_type>() //tensor_container<self_type> ()
  171. , extents_ (e)
  172. , strides_ (extents_)
  173. , data_ (extents_.product(), i)
  174. {}
  175. /** @brief Constructs a tensor from another tensor
  176. *
  177. * @param v tensor to be copied.
  178. */
  179. BOOST_UBLAS_INLINE
  180. tensor (const tensor &v)
  181. : tensor_expression_type<self_type>()
  182. , extents_ (v.extents_)
  183. , strides_ (v.strides_)
  184. , data_ (v.data_ )
  185. {}
  186. /** @brief Constructs a tensor from another tensor
  187. *
  188. * @param v tensor to be moved.
  189. */
  190. BOOST_UBLAS_INLINE
  191. tensor (tensor &&v)
  192. : tensor_expression_type<self_type>() //tensor_container<self_type> ()
  193. , extents_ (std::move(v.extents_))
  194. , strides_ (std::move(v.strides_))
  195. , data_ (std::move(v.data_ ))
  196. {}
  197. /** @brief Constructs a tensor with a matrix
  198. *
  199. * \note Initially the tensor will be two-dimensional.
  200. *
  201. * @param v matrix to be copied.
  202. */
  203. BOOST_UBLAS_INLINE
  204. tensor (const matrix_type &v)
  205. : tensor_expression_type<self_type>()
  206. , extents_ ()
  207. , strides_ ()
  208. , data_ (v.data())
  209. {
  210. if(!data_.empty()){
  211. extents_ = extents_type{v.size1(),v.size2()};
  212. strides_ = strides_type(extents_);
  213. }
  214. }
  215. /** @brief Constructs a tensor with a matrix
  216. *
  217. * \note Initially the tensor will be two-dimensional.
  218. *
  219. * @param v matrix to be moved.
  220. */
  221. BOOST_UBLAS_INLINE
  222. tensor (matrix_type &&v)
  223. : tensor_expression_type<self_type>()
  224. , extents_ {}
  225. , strides_ {}
  226. , data_ {}
  227. {
  228. if(v.size1()*v.size2() != 0){
  229. extents_ = extents_type{v.size1(),v.size2()};
  230. strides_ = strides_type(extents_);
  231. data_ = std::move(v.data());
  232. }
  233. }
  234. /** @brief Constructs a tensor using a \c vector
  235. *
  236. * @note It is assumed that vector is column vector
  237. * @note Initially the tensor will be one-dimensional.
  238. *
  239. * @param v vector to be copied.
  240. */
  241. BOOST_UBLAS_INLINE
  242. tensor (const vector_type &v)
  243. : tensor_expression_type<self_type>()
  244. , extents_ ()
  245. , strides_ ()
  246. , data_ (v.data())
  247. {
  248. if(!data_.empty()){
  249. extents_ = extents_type{data_.size(),1};
  250. strides_ = strides_type(extents_);
  251. }
  252. }
  253. /** @brief Constructs a tensor using a \c vector
  254. *
  255. * @param v vector to be moved.
  256. */
  257. BOOST_UBLAS_INLINE
  258. tensor (vector_type &&v)
  259. : tensor_expression_type<self_type>()
  260. , extents_ {}
  261. , strides_ {}
  262. , data_ {}
  263. {
  264. if(v.size() != 0){
  265. extents_ = extents_type{v.size(),1};
  266. strides_ = strides_type(extents_);
  267. data_ = std::move(v.data());
  268. }
  269. }
  270. /** @brief Constructs a tensor with another tensor with a different layout
  271. *
  272. * @param other tensor with a different layout to be copied.
  273. */
  274. BOOST_UBLAS_INLINE
  275. template<class other_layout>
  276. tensor (const tensor<value_type, other_layout> &other)
  277. : tensor_expression_type<self_type> ()
  278. , extents_ (other.extents())
  279. , strides_ (other.extents())
  280. , data_ (other.extents().product())
  281. {
  282. copy(this->rank(), this->extents().data(),
  283. this->data(), this->strides().data(),
  284. other.data(), other.strides().data());
  285. }
  286. /** @brief Constructs a tensor with an tensor expression
  287. *
  288. * @code tensor<float> A = B + 3 * C; @endcode
  289. *
  290. * @note type must be specified of tensor must be specified.
  291. * @note dimension extents are extracted from tensors within the expression.
  292. *
  293. * @param expr tensor expression
  294. */
  295. BOOST_UBLAS_INLINE
  296. template<class derived_type>
  297. tensor (const tensor_expression_type<derived_type> &expr)
  298. : tensor_expression_type<self_type> ()
  299. , extents_ ( detail::retrieve_extents(expr) )
  300. , strides_ ( extents_ )
  301. , data_ ( extents_.product() )
  302. {
  303. static_assert( detail::has_tensor_types<self_type, tensor_expression_type<derived_type>>::value,
  304. "Error in boost::numeric::ublas::tensor: expression does not contain a tensor. cannot retrieve shape.");
  305. detail::eval( *this, expr );
  306. }
  307. /** @brief Constructs a tensor with a matrix expression
  308. *
  309. * @code tensor<float> A = B + 3 * C; @endcode
  310. *
  311. * @note matrix expression is evaluated and pushed into a temporary matrix before assignment.
  312. * @note extents are automatically extracted from the temporary matrix
  313. *
  314. * @param expr matrix expression
  315. */
  316. BOOST_UBLAS_INLINE
  317. template<class derived_type>
  318. tensor (const matrix_expression_type<derived_type> &expr)
  319. : tensor( matrix_type ( expr ) )
  320. {
  321. }
  322. /** @brief Constructs a tensor with a vector expression
  323. *
  324. * @code tensor<float> A = b + 3 * b; @endcode
  325. *
  326. * @note matrix expression is evaluated and pushed into a temporary matrix before assignment.
  327. * @note extents are automatically extracted from the temporary matrix
  328. *
  329. * @param expr vector expression
  330. */
  331. BOOST_UBLAS_INLINE
  332. template<class derived_type>
  333. tensor (const vector_expression_type<derived_type> &expr)
  334. : tensor( vector_type ( expr ) )
  335. {
  336. }
  337. /** @brief Evaluates the tensor_expression and assigns the results to the tensor
  338. *
  339. * @code A = B + C * 2; @endcode
  340. *
  341. * @note rank and dimension extents of the tensors in the expressions must conform with this tensor.
  342. *
  343. * @param expr expression that is evaluated.
  344. */
  345. BOOST_UBLAS_INLINE
  346. template<class derived_type>
  347. tensor &operator = (const tensor_expression_type<derived_type> &expr)
  348. {
  349. detail::eval(*this, expr);
  350. return *this;
  351. }
  352. tensor& operator=(tensor other)
  353. {
  354. swap (*this, other);
  355. return *this;
  356. }
  357. tensor& operator=(const_reference v)
  358. {
  359. std::fill(this->begin(), this->end(), v);
  360. return *this;
  361. }
  362. /** @brief Returns true if the tensor is empty (\c size==0) */
  363. BOOST_UBLAS_INLINE
  364. bool empty () const {
  365. return this->data_.empty();
  366. }
  367. /** @brief Returns the size of the tensor */
  368. BOOST_UBLAS_INLINE
  369. size_type size () const {
  370. return this->data_.size ();
  371. }
  372. /** @brief Returns the size of the tensor */
  373. BOOST_UBLAS_INLINE
  374. size_type size (size_type r) const {
  375. return this->extents_.at(r);
  376. }
  377. /** @brief Returns the number of dimensions/modes of the tensor */
  378. BOOST_UBLAS_INLINE
  379. size_type rank () const {
  380. return this->extents_.size();
  381. }
  382. /** @brief Returns the number of dimensions/modes of the tensor */
  383. BOOST_UBLAS_INLINE
  384. size_type order () const {
  385. return this->extents_.size();
  386. }
  387. /** @brief Returns the strides of the tensor */
  388. BOOST_UBLAS_INLINE
  389. strides_type const& strides () const {
  390. return this->strides_;
  391. }
  392. /** @brief Returns the extents of the tensor */
  393. BOOST_UBLAS_INLINE
  394. extents_type const& extents () const {
  395. return this->extents_;
  396. }
  397. /** @brief Returns a \c const reference to the container. */
  398. BOOST_UBLAS_INLINE
  399. const_pointer data () const {
  400. return this->data_.data();
  401. }
  402. /** @brief Returns a \c const reference to the container. */
  403. BOOST_UBLAS_INLINE
  404. pointer data () {
  405. return this->data_.data();
  406. }
  407. /** @brief Element access using a single index.
  408. *
  409. * @code auto a = A[i]; @endcode
  410. *
  411. * @param i zero-based index where 0 <= i < this->size()
  412. */
  413. BOOST_UBLAS_INLINE
  414. const_reference operator [] (size_type i) const {
  415. return this->data_[i];
  416. }
  417. /** @brief Element access using a single index.
  418. *
  419. *
  420. * @code A[i] = a; @endcode
  421. *
  422. * @param i zero-based index where 0 <= i < this->size()
  423. */
  424. BOOST_UBLAS_INLINE
  425. reference operator [] (size_type i)
  426. {
  427. return this->data_[i];
  428. }
  429. /** @brief Element access using a multi-index or single-index.
  430. *
  431. *
  432. * @code auto a = A.at(i,j,k); @endcode or
  433. * @code auto a = A.at(i); @endcode
  434. *
  435. * @param i zero-based index where 0 <= i < this->size() if sizeof...(is) == 0, else 0<= i < this->size(0)
  436. * @param is zero-based indices where 0 <= is[r] < this->size(r) where 0 < r < this->rank()
  437. */
  438. template<class ... size_types>
  439. BOOST_UBLAS_INLINE
  440. const_reference at (size_type i, size_types ... is) const {
  441. if constexpr (sizeof...(is) == 0)
  442. return this->data_[i];
  443. else
  444. return this->data_[detail::access<0ul>(size_type(0),this->strides_,i,std::forward<size_types>(is)...)];
  445. }
  446. /** @brief Element access using a multi-index or single-index.
  447. *
  448. *
  449. * @code A.at(i,j,k) = a; @endcode or
  450. * @code A.at(i) = a; @endcode
  451. *
  452. * @param i zero-based index where 0 <= i < this->size() if sizeof...(is) == 0, else 0<= i < this->size(0)
  453. * @param is zero-based indices where 0 <= is[r] < this->size(r) where 0 < r < this->rank()
  454. */
  455. BOOST_UBLAS_INLINE
  456. template<class ... size_types>
  457. reference at (size_type i, size_types ... is) {
  458. if constexpr (sizeof...(is) == 0)
  459. return this->data_[i];
  460. else
  461. return this->data_[detail::access<0ul>(size_type(0),this->strides_,i,std::forward<size_types>(is)...)];
  462. }
  463. /** @brief Element access using a single index.
  464. *
  465. *
  466. * @code A(i) = a; @endcode
  467. *
  468. * @param i zero-based index where 0 <= i < this->size()
  469. */
  470. BOOST_UBLAS_INLINE
  471. const_reference operator()(size_type i) const {
  472. return this->data_[i];
  473. }
  474. /** @brief Element access using a single index.
  475. *
  476. * @code A(i) = a; @endcode
  477. *
  478. * @param i zero-based index where 0 <= i < this->size()
  479. */
  480. BOOST_UBLAS_INLINE
  481. reference operator()(size_type i){
  482. return this->data_[i];
  483. }
  484. /** @brief Generates a tensor index for tensor contraction
  485. *
  486. *
  487. * @code auto Ai = A(_i,_j,k); @endcode
  488. *
  489. * @param i placeholder
  490. * @param is zero-based indices where 0 <= is[r] < this->size(r) where 0 < r < this->rank()
  491. */
  492. BOOST_UBLAS_INLINE
  493. template<std::size_t I, class ... index_types>
  494. decltype(auto) operator() (index::index_type<I> p, index_types ... ps) const
  495. {
  496. constexpr auto N = sizeof...(ps)+1;
  497. if( N != this->rank() )
  498. throw std::runtime_error("Error in boost::numeric::ublas::operator(): size of provided index_types does not match with the rank.");
  499. return std::make_pair( std::cref(*this), std::make_tuple( p, std::forward<index_types>(ps)... ) );
  500. }
  501. /** @brief Reshapes the tensor
  502. *
  503. *
  504. * (1) @code A.reshape(extents{m,n,o}); @endcode or
  505. * (2) @code A.reshape(extents{m,n,o},4); @endcode
  506. *
  507. * If the size of this smaller than the specified extents than
  508. * default constructed (1) or specified (2) value is appended.
  509. *
  510. * @note rank of the tensor might also change.
  511. *
  512. * @param e extents with which the tensor is reshaped.
  513. * @param v value which is appended if the tensor is enlarged.
  514. */
  515. BOOST_UBLAS_INLINE
  516. void reshape (extents_type const& e, value_type v = value_type{})
  517. {
  518. this->extents_ = e;
  519. this->strides_ = strides_type(this->extents_);
  520. if(e.product() != this->size())
  521. this->data_.resize (this->extents_.product(), v);
  522. }
  523. friend void swap(tensor& lhs, tensor& rhs) {
  524. std::swap(lhs.data_ , rhs.data_ );
  525. std::swap(lhs.extents_, rhs.extents_);
  526. std::swap(lhs.strides_, rhs.strides_);
  527. }
  528. /// \brief return an iterator on the first element of the tensor
  529. BOOST_UBLAS_INLINE
  530. const_iterator begin () const {
  531. return data_.begin ();
  532. }
  533. /// \brief return an iterator on the first element of the tensor
  534. BOOST_UBLAS_INLINE
  535. const_iterator cbegin () const {
  536. return data_.cbegin ();
  537. }
  538. /// \brief return an iterator after the last element of the tensor
  539. BOOST_UBLAS_INLINE
  540. const_iterator end () const {
  541. return data_.end();
  542. }
  543. /// \brief return an iterator after the last element of the tensor
  544. BOOST_UBLAS_INLINE
  545. const_iterator cend () const {
  546. return data_.cend ();
  547. }
  548. /// \brief Return an iterator on the first element of the tensor
  549. BOOST_UBLAS_INLINE
  550. iterator begin () {
  551. return data_.begin();
  552. }
  553. /// \brief Return an iterator at the end of the tensor
  554. BOOST_UBLAS_INLINE
  555. iterator end () {
  556. return data_.end();
  557. }
  558. /// \brief Return a const reverse iterator before the first element of the reversed tensor (i.e. end() of normal tensor)
  559. BOOST_UBLAS_INLINE
  560. const_reverse_iterator rbegin () const {
  561. return data_.rbegin();
  562. }
  563. /// \brief Return a const reverse iterator before the first element of the reversed tensor (i.e. end() of normal tensor)
  564. BOOST_UBLAS_INLINE
  565. const_reverse_iterator crbegin () const {
  566. return data_.crbegin();
  567. }
  568. /// \brief Return a const reverse iterator on the end of the reverse tensor (i.e. first element of the normal tensor)
  569. BOOST_UBLAS_INLINE
  570. const_reverse_iterator rend () const {
  571. return data_.rend();
  572. }
  573. /// \brief Return a const reverse iterator on the end of the reverse tensor (i.e. first element of the normal tensor)
  574. BOOST_UBLAS_INLINE
  575. const_reverse_iterator crend () const {
  576. return data_.crend();
  577. }
  578. /// \brief Return a const reverse iterator before the first element of the reversed tensor (i.e. end() of normal tensor)
  579. BOOST_UBLAS_INLINE
  580. reverse_iterator rbegin () {
  581. return data_.rbegin();
  582. }
  583. /// \brief Return a const reverse iterator on the end of the reverse tensor (i.e. first element of the normal tensor)
  584. BOOST_UBLAS_INLINE
  585. reverse_iterator rend () {
  586. return data_.rend();
  587. }
  588. #if 0
  589. // -------------
  590. // Serialization
  591. // -------------
  592. /// Serialize a tensor into and archive as defined in Boost
  593. /// \param ar Archive object. Can be a flat file, an XML file or any other stream
  594. /// \param file_version Optional file version (not yet used)
  595. template<class Archive>
  596. void serialize(Archive & ar, const unsigned int /* file_version */){
  597. ar & serialization::make_nvp("data",data_);
  598. }
  599. #endif
  600. private:
  601. extents_type extents_;
  602. strides_type strides_;
  603. array_type data_;
  604. };
  605. }}} // namespaces
  606. #endif