00001
00002 #ifndef vnl_matrix_fixed_ref_h_
00003 #define vnl_matrix_fixed_ref_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 #include <vcl_cassert.h>
00144 #include <vcl_iosfwd.h>
00145 #include <vcl_cstring.h>
00146 #include <vnl/vnl_matrix_fixed.h>
00147 #include <vnl/vnl_vector_fixed.h>
00148 #include <vnl/vnl_vector_fixed_ref.h>
00149 #include <vnl/vnl_c_vector.h>
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 template <class T, unsigned num_rows, unsigned num_cols>
00169 class vnl_matrix_fixed_ref_const
00170 {
00171 protected:
00172 const T* data_;
00173 public:
00174 vnl_matrix_fixed_ref_const(const vnl_matrix_fixed<T,num_rows,num_cols>& rhs)
00175 : data_(rhs.data_block())
00176 {
00177 }
00178 explicit vnl_matrix_fixed_ref_const(const T * dataptr)
00179 : data_(dataptr)
00180 {
00181 }
00182 vnl_matrix_fixed_ref_const(const vnl_matrix_fixed_ref_const<T,num_rows,num_cols> & rhs)
00183 : data_(rhs.data_)
00184 {
00185 }
00186
00187 vnl_vector_fixed<T,num_rows> get_row(unsigned row_index) const
00188 {
00189 vnl_vector<T> v(num_cols);
00190 for (unsigned int j = 0; j < num_cols; j++)
00191 v[j] = (*this)(row_index,j);
00192 return v;
00193 }
00194
00195
00196 vnl_vector_fixed<T,num_cols> get_column(unsigned column_index) const
00197 {
00198 vnl_vector<T> v(num_rows);
00199 for (unsigned int j = 0; j < num_rows; j++)
00200 v[j] = (*this)(j,column_index);
00201 return v;
00202 }
00203
00204
00205 vnl_vector<T> get_diagonal() const;
00206
00207 const T * data_block() const { return data_; }
00208
00209
00210 typedef T const *const_iterator;
00211
00212 const_iterator begin() const { return data_; }
00213
00214 const_iterator end() const { return begin() + this->size(); }
00215
00216
00217 typedef const T element_type;
00218
00219 typedef const T *iterator;
00220
00221 T const & operator() (unsigned r, unsigned c) const
00222 {
00223 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
00224 assert(r<num_rows);
00225 assert(c<num_cols);
00226 #endif
00227 return *(data_ + num_cols * r + c);
00228 }
00229
00230
00231
00232 T const * operator[] (unsigned r) const { return data_ + num_cols * r; }
00233
00234
00235 unsigned rows() const { return num_rows; }
00236
00237
00238
00239 unsigned columns() const { return num_cols; }
00240
00241
00242
00243 unsigned cols() const { return num_cols; }
00244
00245
00246
00247 unsigned size() const { return num_rows*num_cols; }
00248
00249
00250 void print(vcl_ostream& os) const;
00251
00252 void copy_out(T *) const;
00253
00254
00255
00256
00257 vnl_matrix_fixed<T,num_rows,num_cols> apply(T (*f)(T)) const;
00258
00259
00260 vnl_matrix_fixed<T,num_rows,num_cols> apply(T (*f)(T const&)) const;
00261
00262
00263 vnl_matrix_fixed<T,num_cols,num_rows> transpose () const;
00264
00265
00266 vnl_matrix_fixed<T,num_cols,num_rows> conjugate_transpose () const;
00267
00268
00269
00270 vnl_matrix<T> extract (unsigned rowz, unsigned colz,
00271 unsigned top=0, unsigned left=0) const;
00272
00273
00274 vnl_matrix<T> get_n_rows (unsigned rowstart, unsigned n) const;
00275
00276
00277 vnl_matrix<T> get_n_columns(unsigned colstart, unsigned n) const;
00278
00279
00280 typedef typename vnl_c_vector<T>::abs_t abs_t;
00281
00282
00283 abs_t array_one_norm() const { return vnl_c_vector<T>::one_norm(begin(), size()); }
00284
00285
00286 abs_t array_two_norm() const { return vnl_c_vector<T>::two_norm(begin(), size()); }
00287
00288
00289 abs_t array_inf_norm() const { return vnl_c_vector<T>::inf_norm(begin(), size()); }
00290
00291
00292 abs_t absolute_value_sum() const { return array_one_norm(); }
00293
00294
00295 abs_t absolute_value_max() const { return array_inf_norm(); }
00296
00297
00298 abs_t operator_one_norm() const;
00299
00300
00301 abs_t operator_inf_norm() const;
00302
00303
00304 abs_t frobenius_norm() const { return vnl_c_vector<T>::two_norm(begin(), size()); }
00305
00306
00307 abs_t fro_norm() const { return frobenius_norm(); }
00308
00309
00310 abs_t rms() const { return vnl_c_vector<T>::rms_norm(begin(), size()); }
00311
00312
00313 T min_value() const { return vnl_c_vector<T>::min_value(begin(), size()); }
00314
00315
00316 T max_value() const { return vnl_c_vector<T>::max_value(begin(), size()); }
00317
00318
00319 unsigned arg_min() const { return vnl_c_vector<T>::arg_min(begin(), size()); }
00320
00321
00322 unsigned arg_max() const { return vnl_c_vector<T>::arg_max(begin(), size()); }
00323
00324
00325 T mean() const { return vnl_c_vector<T>::mean(begin(), size()); }
00326
00327
00328
00329
00330 bool empty() const { return num_rows==0 && num_cols==0; }
00331
00332
00333 bool is_identity() const;
00334
00335
00336 bool is_identity(double tol) const;
00337
00338
00339 bool is_zero() const;
00340
00341
00342 bool is_zero(double tol) const;
00343
00344
00345 bool is_finite() const;
00346
00347
00348 bool has_nans() const;
00349
00350
00351
00352 void assert_size(unsigned rowz, unsigned colz) const
00353 {
00354 #ifndef NDEBUG
00355 assert_size_internal(rowz, colz);
00356 #endif
00357 }
00358
00359
00360 void assert_finite() const
00361 {
00362 #ifndef NDEBUG
00363 assert_finite_internal();
00364 #endif
00365 }
00366
00367 static void add( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::add(a,b,r); }
00368 static void add( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::add(a,b,r); }
00369 static void sub( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
00370 static void sub( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
00371 static void sub( T a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::sub(a,b,r); }
00372 static void mul( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::mul(a,b,r); }
00373 static void mul( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::mul(a,b,r); }
00374 static void div( const T* a, const T* b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::div(a,b,r); }
00375 static void div( const T* a, T b, T* r ) { vnl_matrix_fixed<T,num_rows,num_cols>::div(a,b,r); }
00376
00377 static bool equal( const T* a, const T* b ) { return vnl_matrix_fixed<T,num_rows,num_cols>::equal(a,b); }
00378
00379 private:
00380 const vnl_matrix_fixed_ref_const<T,num_rows,num_cols> & operator=(const vnl_matrix_fixed_ref_const<T,num_rows,num_cols>& ) const
00381 {
00382 assert(!"Assignment is illegal for a vnl_matrix_fixed_ref_const");
00383 return *this;
00384 }
00385
00386 void assert_finite_internal() const;
00387
00388 void assert_size_internal(unsigned, unsigned) const;
00389 };
00390
00391
00392 template <class T, unsigned num_rows, unsigned num_cols>
00393 class vnl_matrix_fixed_ref : public vnl_matrix_fixed_ref_const<T,num_rows,num_cols>
00394 {
00395 typedef vnl_matrix_fixed_ref_const<T,num_rows,num_cols> base;
00396
00397 public:
00398
00399
00400 T * data_block() const {
00401 return const_cast<T*>(this->data_);
00402 }
00403 vnl_matrix_fixed_ref(vnl_matrix_fixed<T,num_rows,num_cols>& rhs)
00404 : base(rhs.data_block())
00405 {
00406 }
00407 explicit vnl_matrix_fixed_ref(T * dataptr)
00408 : base(dataptr)
00409 {
00410 }
00411
00412
00413 vnl_matrix_fixed_ref const & operator=(const vnl_matrix_fixed_ref_const<T,num_rows,num_cols>& rhs) const
00414 {
00415 vcl_memcpy(data_block(), rhs.data_block(), num_rows*num_cols*sizeof(T));
00416 return *this;
00417 }
00418
00419
00420
00421
00422 void put (unsigned r, unsigned c, T const& v) { (*this)(r,c) = v; }
00423
00424
00425 T get (unsigned r, unsigned c) const { return (*this)(r,c); }
00426
00427
00428
00429 T * operator[] (unsigned r) const { return data_block() + num_cols * r; }
00430
00431
00432
00433 T & operator() (unsigned r, unsigned c) const
00434 {
00435 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
00436 assert(r<num_rows);
00437 assert(c<num_cols);
00438 #endif
00439 return *(this->data_block() + num_cols * r + c);
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 vnl_matrix_fixed_ref const& fill (T) const;
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 vnl_matrix_fixed_ref const& fill_diagonal (T) const;
00471
00472
00473
00474
00475
00476 vnl_matrix_fixed_ref const& set_diagonal(vnl_vector<T> const&) const;
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 vnl_matrix_fixed_ref const& copy_in(T const *) const;
00492
00493
00494
00495 vnl_matrix_fixed_ref const& set(T const *d) const { return copy_in(d); }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 vnl_matrix_fixed_ref const& inplace_transpose() const;
00508
00509
00510
00511
00512
00513
00514 vnl_matrix_fixed_ref const& operator+= (T s) const
00515 {
00516 base::add( data_block(), s, data_block() ); return *this;
00517 }
00518
00519
00520 vnl_matrix_fixed_ref const& operator-= (T s) const
00521 {
00522 base::sub( data_block(), s, data_block() ); return *this;
00523 }
00524
00525
00526 vnl_matrix_fixed_ref const& operator*= (T s) const
00527 {
00528 base::mul( data_block(), s, data_block() ); return *this;
00529 }
00530
00531
00532 vnl_matrix_fixed_ref const& operator/= (T s) const
00533 {
00534 base::div( data_block(), s, data_block() ); return *this;
00535 }
00536
00537
00538 vnl_matrix_fixed_ref const & operator+= (vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const& m) const
00539 {
00540 base::add( data_block(), m.data_block(), data_block() ); return *this;
00541 }
00542
00543
00544 vnl_matrix_fixed_ref const& operator+= (vnl_matrix<T> const& m) const
00545 {
00546 assert( m.rows() == num_rows && m.cols() == num_cols );
00547 base::add( data_block(), m.data_block(), data_block() ); return *this;
00548 }
00549
00550
00551 vnl_matrix_fixed_ref const& operator-= (vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const& m) const
00552 {
00553 base::sub( data_block(), m.data_block(), data_block() ); return *this;
00554 }
00555
00556
00557 vnl_matrix_fixed_ref const& operator-= (vnl_matrix<T> const& m) const
00558 {
00559 assert( m.rows() == num_rows && m.cols() == num_cols );
00560 base::sub( data_block(), m.data_block(), data_block() ); return *this;
00561 }
00562
00563
00564 vnl_matrix_fixed<T,num_rows,num_cols> operator- () const
00565 {
00566 vnl_matrix_fixed<T,num_rows,num_cols> r;
00567 base::sub( T(0), data_block(), r.data_block() );
00568 return r;
00569 }
00570
00571
00572 vnl_matrix_fixed_ref const& operator*= (vnl_matrix_fixed_ref_const<T,num_cols,num_cols> const& s) const
00573 {
00574 vnl_matrix_fixed<T, num_rows, num_cols> out;
00575 for (unsigned i = 0; i < num_rows; ++i)
00576 for (unsigned j = 0; j < num_cols; ++j)
00577 {
00578 T accum = this->operator()(i,0) * s(0,j);
00579 for (unsigned k = 1; k < num_cols; ++k)
00580 accum += this->operator()(i,k) * s(k,j);
00581 out(i,j) = accum;
00582 }
00583 *this = out;
00584 return *this;
00585 }
00586
00587 #ifdef VCL_VC_6
00588 template<unsigned o>
00589 vnl_matrix_fixed<T,num_rows,o> operator*( vnl_matrix_fixed_fake_base<o,num_cols,T> const& mat ) const
00590 {
00591 vnl_matrix_fixed<T,num_cols,o> const& b = static_cast<vnl_matrix_fixed<T,num_cols,o> const&>(mat);
00592 return vnl_matrix_fixed_mat_mat_mult<T,num_rows,num_cols,o>( *this, b );
00593 }
00594 vnl_vector_fixed<T, num_rows> operator*( vnl_vector_fixed_ref_const<T, num_cols> const& b) const
00595 {
00596 return vnl_matrix_fixed_mat_vec_mult<T,num_rows,num_cols>(*this,b);
00597 }
00598 #endif
00599
00600
00601 vnl_matrix_fixed_ref const & update (vnl_matrix<T> const&, unsigned top=0, unsigned left=0) const;
00602
00603
00604 vnl_matrix_fixed_ref const& set_column(unsigned i, T const * v) const;
00605
00606
00607 vnl_matrix_fixed_ref const& set_column(unsigned i, T value ) const;
00608
00609
00610 vnl_matrix_fixed_ref const& set_column(unsigned j, vnl_vector<T> const& v) const;
00611
00612
00613 vnl_matrix_fixed_ref const& set_column(unsigned j, vnl_vector_fixed<T, num_rows> const& v) const;
00614
00615
00616 vnl_matrix_fixed_ref const& set_columns(unsigned starting_column, vnl_matrix<T> const& M) const;
00617
00618
00619 vnl_matrix_fixed_ref const& set_row (unsigned i, T const * v) const;
00620
00621
00622 vnl_matrix_fixed_ref const& set_row (unsigned i, T value ) const;
00623
00624
00625 vnl_matrix_fixed_ref const& set_row (unsigned i, vnl_vector<T> const& v) const;
00626
00627
00628 vnl_matrix_fixed_ref const& set_row (unsigned i, vnl_vector_fixed<T, num_cols> const& v) const;
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644 vnl_matrix_fixed_ref const& set_identity() const;
00645
00646
00647
00648
00649
00650
00651
00652 vnl_matrix_fixed_ref const& flipud() const;
00653
00654
00655
00656
00657
00658
00659
00660 vnl_matrix_fixed_ref const& fliplr() const;
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 vnl_matrix_fixed_ref const& normalize_rows() const;
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 vnl_matrix_fixed_ref const& normalize_columns() const;
00689
00690
00691
00692
00693
00694
00695
00696 vnl_matrix_fixed_ref const& scale_row (unsigned row, T value) const;
00697
00698
00699
00700
00701
00702
00703
00704 vnl_matrix_fixed_ref const& scale_column(unsigned col, T value) const;
00705
00706
00707
00708
00709 bool read_ascii(vcl_istream& s) const;
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 vnl_matrix_ref<T> as_ref() { return vnl_matrix_ref<T>( num_rows, num_cols, data_block() ); }
00725
00726
00727
00728
00729
00730
00731 const vnl_matrix_ref<T> as_ref() const { return vnl_matrix_ref<T>( num_rows, num_cols, const_cast<T*>(data_block()) ); }
00732
00733
00734
00735
00736
00737 operator const vnl_matrix_ref<T>() const { return vnl_matrix_ref<T>( num_rows, num_cols, const_cast<T*>(data_block()) ); }
00738
00739
00740 const vnl_matrix<T> as_matrix() const { return vnl_matrix<T>(const_cast<T*>(data_block()),num_rows,num_cols); }
00741
00742
00743
00744 typedef T element_type;
00745
00746
00747 typedef T *iterator;
00748
00749 iterator begin() const { return data_block(); }
00750
00751 iterator end() const { return begin() + this->size(); }
00752
00753
00754
00755 bool operator_eq (vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const & rhs) const
00756 {
00757 return vnl_matrix_fixed_ref<T,num_rows,num_cols>::equal( this->data_block(), rhs.data_block() );
00758 }
00759
00760
00761 bool operator==(vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const &that) const { return this->operator_eq(that); }
00762
00763
00764 bool operator!=(vnl_matrix_fixed_ref_const<T,num_rows,num_cols> const &that) const { return !this->operator_eq(that); }
00765
00766
00767 };
00768
00769 #undef VNL_MATRIX_FIXED_VCL60_WORKAROUND
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 template<class T, unsigned m, unsigned n>
00781 inline
00782 vnl_matrix_fixed<T,m,n> operator+( const vnl_matrix_fixed_ref_const<T,m,n>& mat1, const vnl_matrix_fixed_ref_const<T,m,n>& mat2 )
00783 {
00784 vnl_matrix_fixed<T,m,n> r;
00785 vnl_matrix_fixed<T,m,n>::add( mat1.data_block(), mat2.data_block(), r.data_block() );
00786 return r;
00787 }
00788
00789 template<class T, unsigned m, unsigned n>
00790 inline
00791 vnl_matrix_fixed<T,m,n> operator+( const vnl_matrix_fixed_ref_const<T,m,n>& mat, T s )
00792 {
00793 vnl_matrix_fixed<T,m,n> r;
00794 vnl_matrix_fixed<T,m,n>::add( mat.data_block(), s, r.data_block() );
00795 return r;
00796 }
00797
00798 template<class T, unsigned m, unsigned n>
00799 inline
00800 vnl_matrix_fixed<T,m,n> operator+( T s, const vnl_matrix_fixed_ref_const<T,m,n>& mat )
00801 {
00802 vnl_matrix_fixed<T,m,n> r;
00803 vnl_matrix_fixed<T,m,n>::add( mat.data_block(), s, r.data_block() );
00804 return r;
00805 }
00806
00807 template<class T, unsigned m, unsigned n>
00808 inline
00809 vnl_matrix_fixed<T,m,n> operator-( const vnl_matrix_fixed_ref_const<T,m,n>& mat1, const vnl_matrix_fixed_ref_const<T,m,n>& mat2 )
00810 {
00811 vnl_matrix_fixed<T,m,n> r;
00812 vnl_matrix_fixed<T,m,n>::sub( mat1.data_block(), mat2.data_block(), r.data_block() );
00813 return r;
00814 }
00815
00816 template<class T, unsigned m, unsigned n>
00817 inline
00818 vnl_matrix_fixed<T,m,n> operator-( const vnl_matrix_fixed_ref_const<T,m,n>& mat, T s )
00819 {
00820 vnl_matrix_fixed<T,m,n> r;
00821 vnl_matrix_fixed<T,m,n>::sub( mat.data_block(), s, r.data_block() );
00822 return r;
00823 }
00824
00825 template<class T, unsigned m, unsigned n>
00826 inline
00827 vnl_matrix_fixed<T,m,n> operator-( T s, const vnl_matrix_fixed_ref_const<T,m,n>& mat )
00828 {
00829 vnl_matrix_fixed<T,m,n> r;
00830 vnl_matrix_fixed<T,m,n>::sub( s, mat.data_block(), r.data_block() );
00831 return r;
00832 }
00833
00834 template<class T, unsigned m, unsigned n>
00835 inline
00836 vnl_matrix_fixed<T,m,n> operator*( const vnl_matrix_fixed_ref_const<T,m,n>& mat, T s )
00837 {
00838 vnl_matrix_fixed<T,m,n> r;
00839 vnl_matrix_fixed<T,m,n>::mul( mat.data_block(), s, r.data_block() );
00840 return r;
00841 }
00842
00843 template<class T, unsigned m, unsigned n>
00844 inline
00845 vnl_matrix_fixed<T,m,n> operator*( T s, const vnl_matrix_fixed_ref_const<T,m,n>& mat )
00846 {
00847 vnl_matrix_fixed<T,m,n> r;
00848 vnl_matrix_fixed<T,m,n>::mul( mat.data_block(), s, r.data_block() );
00849 return r;
00850 }
00851
00852 template<class T, unsigned m, unsigned n>
00853 inline
00854 vnl_matrix_fixed<T,m,n> operator/( const vnl_matrix_fixed_ref_const<T,m,n>& mat, T s )
00855 {
00856 vnl_matrix_fixed<T,m,n> r;
00857 vnl_matrix_fixed<T,m,n>::div( mat.data_block(), s, r.data_block() );
00858 return r;
00859 }
00860
00861
00862 template<class T, unsigned m, unsigned n>
00863 inline
00864 vnl_matrix_fixed<T,m,n> element_product( const vnl_matrix_fixed_ref_const<T,m,n>& mat1,
00865 const vnl_matrix_fixed_ref_const<T,m,n>& mat2 )
00866 {
00867 vnl_matrix_fixed<T,m,n> r;
00868 vnl_matrix_fixed<T,m,n>::mul( mat1.data_block(), mat2.data_block(), r.data_block() );
00869 return r;
00870 }
00871
00872
00873 template<class T, unsigned m, unsigned n>
00874 inline
00875 vnl_matrix_fixed<T,m,n> element_quotient( const vnl_matrix_fixed_ref_const<T,m,n>& mat1,
00876 const vnl_matrix_fixed_ref_const<T,m,n>& mat2)
00877 {
00878 vnl_matrix_fixed<T,m,n> r;
00879 vnl_matrix_fixed<T,m,n>::div( mat1.data_block(), mat2.data_block(), r.data_block() );
00880 return r;
00881 }
00882
00883
00884
00885
00886
00887 template <class T, unsigned M, unsigned N>
00888 inline
00889 vnl_vector_fixed<T, M>
00890 vnl_matrix_fixed_mat_vec_mult(const vnl_matrix_fixed_ref_const<T, M, N>& a,
00891 const vnl_vector_fixed_ref_const<T, N>& b)
00892 {
00893 vnl_vector_fixed<T, M> out;
00894 for (unsigned i = 0; i < M; ++i)
00895 {
00896 T accum = a(i,0) * b(0);
00897 for (unsigned k = 1; k < N; ++k)
00898 accum += a(i,k) * b(k);
00899 out(i) = accum;
00900 }
00901 return out;
00902 }
00903
00904
00905 template <class T, unsigned M, unsigned N, unsigned O>
00906 inline
00907 vnl_matrix_fixed<T, M, O>
00908 vnl_matrix_fixed_mat_mat_mult(const vnl_matrix_fixed_ref_const<T, M, N>& a,
00909 const vnl_matrix_fixed_ref_const<T, N, O>& b)
00910 {
00911 vnl_matrix_fixed<T, M, O> out;
00912 for (unsigned i = 0; i < M; ++i)
00913 for (unsigned j = 0; j < O; ++j)
00914 {
00915 T accum = a(i,0) * b(0,j);
00916 for (unsigned k = 1; k < N; ++k)
00917 accum += a(i,k) * b(k,j);
00918 out(i,j) = accum;
00919 }
00920 return out;
00921 }
00922
00923 #ifndef VCL_VC_6
00924
00925
00926
00927
00928
00929 template <class T, unsigned M, unsigned N>
00930 inline
00931 vnl_vector_fixed<T, M> operator*(const vnl_matrix_fixed_ref_const<T, M, N>& a, const vnl_vector_fixed_ref_const<T, N>& b)
00932 {
00933 return vnl_matrix_fixed_mat_vec_mult(a,b);
00934 }
00935
00936
00937
00938 template <class T, unsigned M, unsigned N, unsigned O>
00939 inline
00940 vnl_matrix_fixed<T, M, O> operator*(const vnl_matrix_fixed_ref_const<T, M, N>& a, const vnl_matrix_fixed_ref_const<T, N, O>& b)
00941 {
00942 return vnl_matrix_fixed_mat_mat_mult(a,b);
00943 }
00944 #endif // ! VCL_VC_6
00945
00946
00947
00948
00949
00950
00951 template<class T, unsigned m, unsigned n>
00952 inline vnl_matrix<T> operator+( const vnl_matrix_fixed_ref_const<T,m,n>& a, const vnl_matrix<T>& b )
00953 {
00954 return a.as_ref() + b;
00955 }
00956
00957 template<class T, unsigned m, unsigned n>
00958 inline vnl_matrix<T> operator+( const vnl_matrix<T>& a, const vnl_matrix_fixed_ref_const<T,m,n>& b )
00959 {
00960 return a + b.as_ref();
00961 }
00962
00963 template<class T, unsigned m, unsigned n>
00964 inline vnl_matrix<T> operator-( const vnl_matrix_fixed_ref_const<T,m,n>& a, const vnl_matrix<T>& b )
00965 {
00966 return a.as_ref() - b;
00967 }
00968
00969 template<class T, unsigned m, unsigned n>
00970 inline vnl_matrix<T> operator-( const vnl_matrix<T>& a, const vnl_matrix_fixed_ref_const<T,m,n>& b )
00971 {
00972 return a - b.as_ref();
00973 }
00974
00975 template<class T, unsigned m, unsigned n>
00976 inline vnl_matrix<T> operator*( const vnl_matrix_fixed_ref_const<T,m,n>& a, const vnl_matrix<T>& b )
00977 {
00978 return a.as_ref() * b;
00979 }
00980
00981 template<class T, unsigned m, unsigned n>
00982 inline vnl_matrix<T> operator*( const vnl_matrix<T>& a, const vnl_matrix_fixed_ref_const<T,m,n>& b )
00983 {
00984 return a * b.as_ref();
00985 }
00986
00987 template<class T, unsigned m, unsigned n>
00988 inline vnl_vector<T> operator*( const vnl_matrix_fixed_ref_const<T,m,n>& a, const vnl_vector<T>& b )
00989 {
00990 return a.as_ref() * b;
00991 }
00992
00993 template<class T, unsigned n>
00994 inline vnl_vector<T> operator*( const vnl_matrix<T>& a, const vnl_vector_fixed_ref_const<T,n>& b )
00995 {
00996 return a * b.as_ref();
00997 }
00998
00999
01000
01001
01002 template<class T, unsigned m, unsigned n>
01003 inline
01004 vcl_ostream& operator<< (vcl_ostream& os, vnl_matrix_fixed_ref_const<T,m,n> const& mat)
01005 {
01006 mat.print(os);
01007 return os;
01008 }
01009
01010 template<class T, unsigned m, unsigned n>
01011 inline
01012 vcl_istream& operator>> (vcl_istream& is, vnl_matrix_fixed_ref<T,m,n> const& mat)
01013 {
01014 mat.read_ascii(is);
01015 return is;
01016 }
01017
01018
01019 #endif // vnl_matrix_fixed_ref_h_