2 // Copyright (c) 2002-2003
3 // Toon Knapen, Kresimir Fresl, Joerg Walter
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef _BOOST_UBLAS_RAW_
12 #define _BOOST_UBLAS_RAW_
14 namespace boost { namespace numeric { namespace ublas { namespace raw {
16 // We need data_const() mostly due to MSVC 6.0.
17 // But how shall we write portable code otherwise?
19 template < typename V >
21 int size( const V &v ) ;
23 template < typename V >
25 int size( const vector_reference<V> &v ) ;
27 template < typename M >
29 int size1( const M &m ) ;
30 template < typename M >
32 int size2( const M &m ) ;
34 template < typename M >
36 int size1( const matrix_reference<M> &m ) ;
37 template < typename M >
39 int size2( const matrix_reference<M> &m ) ;
41 template < typename M >
43 int leading_dimension( const M &m, row_major_tag ) ;
44 template < typename M >
46 int leading_dimension( const M &m, column_major_tag ) ;
47 template < typename M >
49 int leading_dimension( const M &m ) ;
51 template < typename M >
53 int leading_dimension( const matrix_reference<M> &m ) ;
55 template < typename V >
57 int stride( const V &v ) ;
59 template < typename V >
61 int stride( const vector_range<V> &v ) ;
62 template < typename V >
64 int stride( const vector_slice<V> &v ) ;
66 template < typename M >
68 int stride( const matrix_row<M> &v ) ;
69 template < typename M >
71 int stride( const matrix_column<M> &v ) ;
73 template < typename M >
75 int stride1( const M &m ) ;
76 template < typename M >
78 int stride2( const M &m ) ;
80 template < typename M >
82 int stride1( const matrix_reference<M> &m ) ;
83 template < typename M >
85 int stride2( const matrix_reference<M> &m ) ;
87 template < typename T, std::size_t M, std::size_t N >
89 int stride1( const c_matrix<T, M, N> &m ) ;
90 template < typename T, std::size_t M, std::size_t N >
92 int stride2( const c_matrix<T, M, N> &m ) ;
94 template < typename M >
96 int stride1( const matrix_range<M> &m ) ;
97 template < typename M >
99 int stride1( const matrix_slice<M> &m ) ;
100 template < typename M >
102 int stride2( const matrix_range<M> &m ) ;
103 template < typename M >
105 int stride2( const matrix_slice<M> &m ) ;
107 template < typename MV >
109 typename MV::array_type::array_type::const_pointer data( const MV &mv ) ;
110 template < typename MV >
112 typename MV::array_type::array_type::const_pointer data_const( const MV &mv ) ;
113 template < typename MV >
115 typename MV::array_type::pointer data( MV &mv ) ;
117 template < typename V >
119 typename V::array_type::array_type::const_pointer data( const vector_reference<V> &v ) ;
120 template < typename V >
122 typename V::array_type::array_type::const_pointer data_const( const vector_reference<V> &v ) ;
123 template < typename V >
125 typename V::array_type::pointer data( vector_reference<V> &v ) ;
127 template < typename T, std::size_t N >
129 typename c_vector<T, N>::array_type::array_type::const_pointer data( const c_vector<T, N> &v ) ;
130 template < typename T, std::size_t N >
132 typename c_vector<T, N>::array_type::array_type::const_pointer data_const( const c_vector<T, N> &v ) ;
133 template < typename T, std::size_t N >
135 typename c_vector<T, N>::pointer data( c_vector<T, N> &v ) ;
137 template < typename V >
139 typename V::array_type::array_type::const_pointer data( const vector_range<V> &v ) ;
140 template < typename V >
142 typename V::array_type::array_type::const_pointer data( const vector_slice<V> &v ) ;
143 template < typename V >
145 typename V::array_type::array_type::const_pointer data_const( const vector_range<V> &v ) ;
146 template < typename V >
148 typename V::array_type::array_type::const_pointer data_const( const vector_slice<V> &v ) ;
149 template < typename V >
151 typename V::array_type::pointer data( vector_range<V> &v ) ;
152 template < typename V >
154 typename V::array_type::pointer data( vector_slice<V> &v ) ;
156 template < typename M >
158 typename M::array_type::array_type::const_pointer data( const matrix_reference<M> &m ) ;
159 template < typename M >
161 typename M::array_type::array_type::const_pointer data_const( const matrix_reference<M> &m ) ;
162 template < typename M >
164 typename M::array_type::pointer data( matrix_reference<M> &m ) ;
166 template < typename T, std::size_t M, std::size_t N >
168 typename c_matrix<T, M, N>::array_type::array_type::const_pointer data( const c_matrix<T, M, N> &m ) ;
169 template < typename T, std::size_t M, std::size_t N >
171 typename c_matrix<T, M, N>::array_type::array_type::const_pointer data_const( const c_matrix<T, M, N> &m ) ;
172 template < typename T, std::size_t M, std::size_t N >
174 typename c_matrix<T, M, N>::pointer data( c_matrix<T, M, N> &m ) ;
176 template < typename M >
178 typename M::array_type::array_type::const_pointer data( const matrix_row<M> &v ) ;
179 template < typename M >
181 typename M::array_type::array_type::const_pointer data( const matrix_column<M> &v ) ;
182 template < typename M >
184 typename M::array_type::array_type::const_pointer data_const( const matrix_row<M> &v ) ;
185 template < typename M >
187 typename M::array_type::array_type::const_pointer data_const( const matrix_column<M> &v ) ;
188 template < typename M >
190 typename M::array_type::pointer data( matrix_row<M> &v ) ;
191 template < typename M >
193 typename M::array_type::pointer data( matrix_column<M> &v ) ;
195 template < typename M >
197 typename M::array_type::array_type::const_pointer data( const matrix_range<M> &m ) ;
198 template < typename M >
200 typename M::array_type::array_type::const_pointer data( const matrix_slice<M> &m ) ;
201 template < typename M >
203 typename M::array_type::array_type::const_pointer data_const( const matrix_range<M> &m ) ;
204 template < typename M >
206 typename M::array_type::array_type::const_pointer data_const( const matrix_slice<M> &m ) ;
207 template < typename M >
209 typename M::array_type::pointer data( matrix_range<M> &m ) ;
210 template < typename M >
212 typename M::array_type::pointer data( matrix_slice<M> &m ) ;
214 template < typename MV >
216 typename MV::array_type::array_type::const_pointer base( const MV &mv ) ;
218 template < typename MV >
220 typename MV::array_type::array_type::const_pointer base_const( const MV &mv ) ;
221 template < typename MV >
223 typename MV::array_type::pointer base( MV &mv ) ;
225 template < typename V >
227 typename V::array_type::array_type::const_pointer base( const vector_reference<V> &v ) ;
228 template < typename V >
230 typename V::array_type::array_type::const_pointer base_const( const vector_reference<V> &v ) ;
231 template < typename V >
233 typename V::array_type::pointer base( vector_reference<V> &v ) ;
235 template < typename T, std::size_t N >
237 typename c_vector<T, N>::array_type::array_type::const_pointer base( const c_vector<T, N> &v ) ;
238 template < typename T, std::size_t N >
240 typename c_vector<T, N>::array_type::array_type::const_pointer base_const( const c_vector<T, N> &v ) ;
241 template < typename T, std::size_t N >
243 typename c_vector<T, N>::pointer base( c_vector<T, N> &v ) ;
245 template < typename V >
247 typename V::array_type::array_type::const_pointer base( const vector_range<V> &v ) ;
248 template < typename V >
250 typename V::array_type::array_type::const_pointer base( const vector_slice<V> &v ) ;
251 template < typename V >
253 typename V::array_type::array_type::const_pointer base_const( const vector_range<V> &v ) ;
254 template < typename V >
256 typename V::array_type::array_type::const_pointer base_const( const vector_slice<V> &v ) ;
257 template < typename V >
259 typename V::array_type::pointer base( vector_range<V> &v ) ;
260 template < typename V >
262 typename V::array_type::pointer base( vector_slice<V> &v ) ;
264 template < typename M >
266 typename M::array_type::array_type::const_pointer base( const matrix_reference<M> &m ) ;
267 template < typename M >
269 typename M::array_type::array_type::const_pointer base_const( const matrix_reference<M> &m ) ;
270 template < typename M >
272 typename M::array_type::pointer base( matrix_reference<M> &m ) ;
274 template < typename T, std::size_t M, std::size_t N >
276 typename c_matrix<T, M, N>::array_type::array_type::const_pointer base( const c_matrix<T, M, N> &m ) ;
277 template < typename T, std::size_t M, std::size_t N >
279 typename c_matrix<T, M, N>::array_type::array_type::const_pointer base_const( const c_matrix<T, M, N> &m ) ;
280 template < typename T, std::size_t M, std::size_t N >
282 typename c_matrix<T, M, N>::pointer base( c_matrix<T, M, N> &m ) ;
284 template < typename M >
286 typename M::array_type::array_type::const_pointer base( const matrix_row<M> &v ) ;
287 template < typename M >
289 typename M::array_type::array_type::const_pointer base( const matrix_column<M> &v ) ;
290 template < typename M >
292 typename M::array_type::array_type::const_pointer base_const( const matrix_row<M> &v ) ;
293 template < typename M >
295 typename M::array_type::array_type::const_pointer base_const( const matrix_column<M> &v ) ;
296 template < typename M >
298 typename M::array_type::pointer base( matrix_row<M> &v ) ;
299 template < typename M >
301 typename M::array_type::pointer base( matrix_column<M> &v ) ;
303 template < typename M >
305 typename M::array_type::array_type::const_pointer base( const matrix_range<M> &m ) ;
306 template < typename M >
308 typename M::array_type::array_type::const_pointer base( const matrix_slice<M> &m ) ;
309 template < typename M >
311 typename M::array_type::array_type::const_pointer base_const( const matrix_range<M> &m ) ;
312 template < typename M >
314 typename M::array_type::array_type::const_pointer base_const( const matrix_slice<M> &m ) ;
315 template < typename M >
317 typename M::array_type::pointer base( matrix_range<M> &m ) ;
318 template < typename M >
320 typename M::array_type::pointer base( matrix_slice<M> &m ) ;
322 template < typename MV >
324 typename MV::size_type start( const MV &mv ) ;
326 template < typename V >
328 typename V::size_type start( const vector_range<V> &v ) ;
329 template < typename V >
331 typename V::size_type start( const vector_slice<V> &v ) ;
333 template < typename M >
335 typename M::size_type start( const matrix_row<M> &v ) ;
336 template < typename M >
338 typename M::size_type start( const matrix_column<M> &v ) ;
340 template < typename M >
342 typename M::size_type start( const matrix_range<M> &m ) ;
343 template < typename M >
345 typename M::size_type start( const matrix_slice<M> &m ) ;
349 template < typename V >
351 int size( const V &v ) {
355 template < typename V >
357 int size( const vector_reference<V> &v ) {
361 template < typename M >
363 int size1( const M &m ) {
366 template < typename M >
368 int size2( const M &m ) {
372 template < typename M >
374 int size1( const matrix_reference<M> &m ) {
375 return size1( m.expression() ) ;
377 template < typename M >
379 int size2( const matrix_reference<M> &m ) {
380 return size2( m.expression() ) ;
383 template < typename M >
385 int leading_dimension( const M &m, row_major_tag ) {
388 template < typename M >
390 int leading_dimension( const M &m, column_major_tag ) {
393 template < typename M >
395 int leading_dimension( const M &m ) {
396 return leading_dimension( m, typename M::orientation_category() ) ;
399 template < typename M >
401 int leading_dimension( const matrix_reference<M> &m ) {
402 return leading_dimension( m.expression() ) ;
405 template < typename V >
407 int stride( const V &v ) {
411 template < typename V >
413 int stride( const vector_range<V> &v ) {
414 return stride( v.data() ) ;
416 template < typename V >
418 int stride( const vector_slice<V> &v ) {
419 return v.stride() * stride( v.data() ) ;
422 template < typename M >
424 int stride( const matrix_row<M> &v ) {
425 return stride2( v.data() ) ;
427 template < typename M >
429 int stride( const matrix_column<M> &v ) {
430 return stride1( v.data() ) ;
433 template < typename M >
435 int stride1( const M &m ) {
436 typedef typename M::functor_type functor_type;
437 return functor_type::one1( m.size1(), m.size2() ) ;
439 template < typename M >
441 int stride2( const M &m ) {
442 typedef typename M::functor_type functor_type;
443 return functor_type::one2( m.size1(), m.size2() ) ;
446 template < typename M >
448 int stride1( const matrix_reference<M> &m ) {
449 return stride1( m.expression() ) ;
451 template < typename M >
453 int stride2( const matrix_reference<M> &m ) {
454 return stride2( m.expression() ) ;
457 template < typename T, std::size_t M, std::size_t N >
459 int stride1( const c_matrix<T, M, N> &m ) {
462 template < typename T, std::size_t M, std::size_t N >
464 int stride2( const c_matrix<T, M, N> &m ) {
468 template < typename M >
470 int stride1( const matrix_range<M> &m ) {
471 return stride1( m.data() ) ;
473 template < typename M >
475 int stride1( const matrix_slice<M> &m ) {
476 return m.stride1() * stride1( m.data() ) ;
478 template < typename M >
480 int stride2( const matrix_range<M> &m ) {
481 return stride2( m.data() ) ;
483 template < typename M >
485 int stride2( const matrix_slice<M> &m ) {
486 return m.stride2() * stride2( m.data() ) ;
489 template < typename MV >
491 typename MV::array_type::array_type::array_type::const_pointer data( const MV &mv ) {
492 return &mv.data().begin()[0] ;
494 template < typename MV >
496 typename MV::array_type::array_type::const_pointer data_const( const MV &mv ) {
497 return &mv.data().begin()[0] ;
499 template < typename MV >
501 typename MV::array_type::pointer data( MV &mv ) {
502 return &mv.data().begin()[0] ;
506 template < typename V >
508 typename V::array_type::array_type::const_pointer data( const vector_reference<V> &v ) {
509 return data( v.expression () ) ;
511 template < typename V >
513 typename V::array_type::array_type::const_pointer data_const( const vector_reference<V> &v ) {
514 return data_const( v.expression () ) ;
516 template < typename V >
518 typename V::array_type::pointer data( vector_reference<V> &v ) {
519 return data( v.expression () ) ;
522 template < typename T, std::size_t N >
524 typename c_vector<T, N>::array_type::array_type::const_pointer data( const c_vector<T, N> &v ) {
527 template < typename T, std::size_t N >
529 typename c_vector<T, N>::array_type::array_type::const_pointer data_const( const c_vector<T, N> &v ) {
532 template < typename T, std::size_t N >
534 typename c_vector<T, N>::pointer data( c_vector<T, N> &v ) {
538 template < typename V >
540 typename V::array_type::array_type::const_pointer data( const vector_range<V> &v ) {
541 return data( v.data() ) + v.start() * stride (v.data() ) ;
543 template < typename V >
545 typename V::array_type::array_type::const_pointer data( const vector_slice<V> &v ) {
546 return data( v.data() ) + v.start() * stride (v.data() ) ;
548 template < typename V >
550 typename V::array_type::array_type::const_pointer data_const( const vector_range<V> &v ) {
551 return data_const( v.data() ) + v.start() * stride (v.data() ) ;
553 template < typename V >
555 typename V::array_type::const_pointer data_const( const vector_slice<V> &v ) {
556 return data_const( v.data() ) + v.start() * stride (v.data() ) ;
558 template < typename V >
560 typename V::array_type::pointer data( vector_range<V> &v ) {
561 return data( v.data() ) + v.start() * stride (v.data() ) ;
563 template < typename V >
565 typename V::array_type::pointer data( vector_slice<V> &v ) {
566 return data( v.data() ) + v.start() * stride (v.data() ) ;
569 template < typename M >
571 typename M::array_type::const_pointer data( const matrix_reference<M> &m ) {
572 return data( m.expression () ) ;
574 template < typename M >
576 typename M::array_type::const_pointer data_const( const matrix_reference<M> &m ) {
577 return data_const( m.expression () ) ;
579 template < typename M >
581 typename M::array_type::pointer data( matrix_reference<M> &m ) {
582 return data( m.expression () ) ;
585 template < typename T, std::size_t M, std::size_t N >
587 typename c_matrix<T, M, N>::array_type::const_pointer data( const c_matrix<T, M, N> &m ) {
590 template < typename T, std::size_t M, std::size_t N >
592 typename c_matrix<T, M, N>::array_type::const_pointer data_const( const c_matrix<T, M, N> &m ) {
595 template < typename T, std::size_t M, std::size_t N >
597 typename c_matrix<T, M, N>::pointer data( c_matrix<T, M, N> &m ) {
601 template < typename M >
603 typename M::array_type::const_pointer data( const matrix_row<M> &v ) {
604 return data( v.data() ) + v.index() * stride1( v.data() ) ;
606 template < typename M >
608 typename M::array_type::const_pointer data( const matrix_column<M> &v ) {
609 return data( v.data() ) + v.index() * stride2( v.data() ) ;
611 template < typename M >
613 typename M::array_type::const_pointer data_const( const matrix_row<M> &v ) {
614 return data_const( v.data() ) + v.index() * stride1( v.data() ) ;
616 template < typename M >
618 typename M::array_type::const_pointer data_const( const matrix_column<M> &v ) {
619 return data_const( v.data() ) + v.index() * stride2( v.data() ) ;
621 template < typename M >
623 typename M::array_type::pointer data( matrix_row<M> &v ) {
624 return data( v.data() ) + v.index() * stride1( v.data() ) ;
626 template < typename M >
628 typename M::array_type::pointer data( matrix_column<M> &v ) {
629 return data( v.data() ) + v.index() * stride2( v.data() ) ;
632 template < typename M >
634 typename M::array_type::const_pointer data( const matrix_range<M> &m ) {
635 return data( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
637 template < typename M >
639 typename M::array_type::const_pointer data( const matrix_slice<M> &m ) {
640 return data( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
642 template < typename M >
644 typename M::array_type::const_pointer data_const( const matrix_range<M> &m ) {
645 return data_const( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
647 template < typename M >
649 typename M::array_type::const_pointer data_const( const matrix_slice<M> &m ) {
650 return data_const( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
652 template < typename M >
654 typename M::array_type::pointer data( matrix_range<M> &m ) {
655 return data( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
657 template < typename M >
659 typename M::array_type::pointer data( matrix_slice<M> &m ) {
660 return data( m.data() ) + m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
664 template < typename MV >
666 typename MV::array_type::const_pointer base( const MV &mv ) {
667 return &mv.data().begin()[0] ;
669 template < typename MV >
671 typename MV::array_type::const_pointer base_const( const MV &mv ) {
672 return &mv.data().begin()[0] ;
674 template < typename MV >
676 typename MV::array_type::pointer base( MV &mv ) {
677 return &mv.data().begin()[0] ;
680 template < typename V >
682 typename V::array_type::const_pointer base( const vector_reference<V> &v ) {
683 return base( v.expression () ) ;
685 template < typename V >
687 typename V::array_type::const_pointer base_const( const vector_reference<V> &v ) {
688 return base_const( v.expression () ) ;
690 template < typename V >
692 typename V::array_type::pointer base( vector_reference<V> &v ) {
693 return base( v.expression () ) ;
696 template < typename T, std::size_t N >
698 typename c_vector<T, N>::array_type::const_pointer base( const c_vector<T, N> &v ) {
701 template < typename T, std::size_t N >
703 typename c_vector<T, N>::array_type::const_pointer base_const( const c_vector<T, N> &v ) {
706 template < typename T, std::size_t N >
708 typename c_vector<T, N>::pointer base( c_vector<T, N> &v ) {
712 template < typename V >
714 typename V::array_type::const_pointer base( const vector_range<V> &v ) {
715 return base( v.data() ) ;
717 template < typename V >
719 typename V::array_type::const_pointer base( const vector_slice<V> &v ) {
720 return base( v.data() ) ;
722 template < typename V >
724 typename V::array_type::const_pointer base_const( const vector_range<V> &v ) {
725 return base_const( v.data() ) ;
727 template < typename V >
729 typename V::array_type::const_pointer base_const( const vector_slice<V> &v ) {
730 return base_const( v.data() ) ;
732 template < typename V >
734 typename V::array_type::pointer base( vector_range<V> &v ) {
735 return base( v.data() ) ;
737 template < typename V >
739 typename V::array_type::pointer base( vector_slice<V> &v ) {
740 return base( v.data() ) ;
743 template < typename M >
745 typename M::array_type::const_pointer base( const matrix_reference<M> &m ) {
746 return base( m.expression () ) ;
748 template < typename M >
750 typename M::array_type::const_pointer base_const( const matrix_reference<M> &m ) {
751 return base_const( m.expression () ) ;
753 template < typename M >
755 typename M::array_type::pointer base( matrix_reference<M> &m ) {
756 return base( m.expression () ) ;
759 template < typename T, std::size_t M, std::size_t N >
761 typename c_matrix<T, M, N>::array_type::const_pointer base( const c_matrix<T, M, N> &m ) {
764 template < typename T, std::size_t M, std::size_t N >
766 typename c_matrix<T, M, N>::array_type::const_pointer base_const( const c_matrix<T, M, N> &m ) {
769 template < typename T, std::size_t M, std::size_t N >
771 typename c_matrix<T, M, N>::pointer base( c_matrix<T, M, N> &m ) {
775 template < typename M >
777 typename M::array_type::const_pointer base( const matrix_row<M> &v ) {
778 return base( v.data() ) ;
780 template < typename M >
782 typename M::array_type::const_pointer base( const matrix_column<M> &v ) {
783 return base( v.data() ) ;
785 template < typename M >
787 typename M::array_type::const_pointer base_const( const matrix_row<M> &v ) {
788 return base_const( v.data() ) ;
790 template < typename M >
792 typename M::array_type::const_pointer base_const( const matrix_column<M> &v ) {
793 return base_const( v.data() ) ;
795 template < typename M >
797 typename M::array_type::pointer base( matrix_row<M> &v ) {
798 return base( v.data() ) ;
800 template < typename M >
802 typename M::array_type::pointer base( matrix_column<M> &v ) {
803 return base( v.data() ) ;
806 template < typename M >
808 typename M::array_type::const_pointer base( const matrix_range<M> &m ) {
809 return base( m.data() ) ;
811 template < typename M >
813 typename M::array_type::const_pointer base( const matrix_slice<M> &m ) {
814 return base( m.data() ) ;
816 template < typename M >
818 typename M::array_type::const_pointer base_const( const matrix_range<M> &m ) {
819 return base_const( m.data() ) ;
821 template < typename M >
823 typename M::array_type::const_pointer base_const( const matrix_slice<M> &m ) {
824 return base_const( m.data() ) ;
826 template < typename M >
828 typename M::array_type::pointer base( matrix_range<M> &m ) {
829 return base( m.data() ) ;
831 template < typename M >
833 typename M::array_type::pointer base( matrix_slice<M> &m ) {
834 return base( m.data() ) ;
837 template < typename MV >
839 typename MV::size_type start( const MV &mv ) {
843 template < typename V >
845 typename V::size_type start( const vector_range<V> &v ) {
846 return v.start() * stride (v.data() ) ;
848 template < typename V >
850 typename V::size_type start( const vector_slice<V> &v ) {
851 return v.start() * stride (v.data() ) ;
854 template < typename M >
856 typename M::size_type start( const matrix_row<M> &v ) {
857 return v.index() * stride1( v.data() ) ;
859 template < typename M >
861 typename M::size_type start( const matrix_column<M> &v ) {
862 return v.index() * stride2( v.data() ) ;
865 template < typename M >
867 typename M::size_type start( const matrix_range<M> &m ) {
868 return m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;
870 template < typename M >
872 typename M::size_type start( const matrix_slice<M> &m ) {
873 return m.start1() * stride1( m.data () ) + m.start2() * stride2( m.data () ) ;