namespace ewalena  0.2.15
ewalena is not an acronym
include/ewalena/lac/super_matrix.h
Go to the documentation of this file.
00001 // -------------------------------------------------------------------
00002 // @author Toby D. Young
00003 // @version $Id: super_matrix.h 1000 2012-12-04 13:21:14Z oneliefleft $
00004 //
00005 // Copyright 2012 namespace ewalena authors. All rights reserved.
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions
00009 // are met:
00010 //
00011 // 1. Redistributions of source code must retain the above copyright
00012 //    notice, this list of conditions and the following disclaimer.
00013 //
00014 // 2. Redistributions in binary form must reproduce the above
00015 //    copyright notice, this list of conditions and the following
00016 //    disclaimer in the documentation and/or other materials provided
00017 //    with the distribution.
00018 //
00019 // THIS SOFTWARE IS PROVIDED BY THE NAMEPSACE EWALENA AUTHORS ``AS
00020 // IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023 // NAMESPACE EWALENA AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00024 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00026 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00028 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00030 // OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // The views and conclusions contained in the software and
00033 // documentation are those of the authors and should not be
00034 // interpreted as representing official policies, either expressed or
00035 // implied, of the namespace ewalena authors.
00036 // -------------------------------------------------------------------
00037 
00038 #include <cassert>
00039 #include <cstring>
00040 #include <stdlib.h>
00041 #include <iostream>
00042 
00043 #ifndef __ewalena_super_matrix_h
00044 #define __ewalena_super_matrix_h
00045 
00046 #ifdef EWALENA_HAVE_CONFIG_H
00047 #include <ewalena/base/config.h>
00048 #endif
00049 
00050 namespace ewalena
00051 {
00052   
00058   template <typename ValueType = double>
00059     class SuperMatrix
00060     {
00061       
00062       
00063     public:
00064     
00068     SuperMatrix ();
00069     
00073     ~SuperMatrix ();
00074     
00081     explicit SuperMatrix (const unsigned int p, 
00082                           const unsigned int q,
00083                           const unsigned int r,
00084                           const unsigned int s,
00085                           const bool         zero = true);
00086     
00087     
00091     unsigned int n_rows () const;
00092     
00096     unsigned int n_cols () const;
00097     
00098     
00103     void reinit (const unsigned int p,
00104                  const unsigned int q,
00105                  const unsigned int r,
00106                  const unsigned int s,
00107                  const bool         zero = true);
00108     
00113     ValueType& operator () (const unsigned int i, 
00114                             const unsigned int j,
00115                             const unsigned int k,
00116                             const unsigned int l);
00117     
00122     const ValueType& operator () (const unsigned int i, 
00123                                   const unsigned int j,
00124                                   const unsigned int k,
00125                                   const unsigned int l) const;
00126     
00131     void reinit ();
00132     
00136     friend std::ostream& operator << (std::ostream            &output, 
00137                                       const SuperMatrix<ValueType> &M) 
00138     { 
00139       for (unsigned int i=0; i<M.n_rows ()*M.n_cols (); ++i)  
00140         output << M.data[i] << " ";  
00141       
00142       return output;  
00143     }
00144     
00145     protected:
00146     
00151     inline
00152     const 
00153     ValueType* operator* () const
00154     {
00155       return (*this).data;
00156     }
00157     
00162     inline
00163     ValueType* operator* () 
00164     {
00165       return (*this).data;
00166     }
00167     
00168     private:
00169     
00174     unsigned int __n_rows;
00175     
00180     unsigned int __n_cols;
00181     
00182     unsigned int I, J, K, L;
00183     
00188     ValueType* data;
00189     
00190     }; /* SuperMatrix */
00191   
00192   /*-------------- Inline and Other Functions -----------------------*/
00193   
00194   template <typename ValueType>
00195     inline
00196     unsigned int
00197     SuperMatrix<ValueType>::n_rows () const
00198     {
00199       return this->__n_rows;
00200     }
00201   
00202   template <typename ValueType>
00203     inline
00204     unsigned int
00205     SuperMatrix<ValueType>::n_cols () const
00206     {
00207       return this->__n_cols;
00208     }
00209 
00210   template <typename ValueType>
00211     inline 
00212     const ValueType& 
00213     SuperMatrix<ValueType>::operator () (const unsigned int i, 
00214                                          const unsigned int j,
00215                                          const unsigned int k,
00216                                          const unsigned int l) const
00217     {
00218       assert (i<I);
00219       assert (j<J);
00220       assert (k<K);
00221       assert (l<L);
00222 
00223       unsigned int index = __n_cols*I*l + J*k + (__n_cols*i+j);
00224 
00225       return data[index];
00226     }
00227   
00228   template <typename ValueType>
00229     inline 
00230     ValueType& 
00231     SuperMatrix<ValueType>::operator () (const unsigned int i, 
00232                                          const unsigned int j,
00233                                          const unsigned int k,
00234                                          const unsigned int l) 
00235     {
00236       assert (i<I);
00237       assert (j<J);
00238       assert (k<K);
00239       assert (l<L);
00240 
00241       unsigned int index = __n_cols*I*l + J*k + (__n_cols*i+j);
00242 
00243       return data[index];
00244     }
00245 
00246   /*-------------- Template and Other Functions ---------------------*/
00247 
00248 } /* namespace ewalena */
00249   
00250 #endif /* __ewalena_super_matrix_h */
00251   
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines