Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShMatrix.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SH_SHMATRIX_HPP
00025 #define SH_SHMATRIX_HPP
00026 
00027 #include "ShMeta.hpp"
00028 #include "ShVariable.hpp"
00029 #include "ShAttrib.hpp"
00030 #include "ShRefCount.hpp"
00031 
00032 namespace SH {
00033 
00034 template<int Rows, int Cols, ShBindingType Binding, typename T>
00035 class ShMatrix;
00036 
00037 template<int Rows, int Cols, typename T>
00038 class ShMatrixRows;
00039 
00046 template<int Rows, int Cols, ShBindingType Binding, typename T>
00047 class ShMatrix: public virtual ShMeta {
00048 public:
00049   typedef T storage_type;
00050   typedef typename ShHostType<T>::type host_type; 
00051   typedef typename ShMemType<T>::type mem_type;
00052   static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00053   static const ShBindingType binding_type = Binding;
00054   static const int typesize = Rows * Cols;
00055 
00056   typedef ShMatrix<Rows, Cols, SH_INPUT, T> InputType;
00057   typedef ShMatrix<Rows, Cols, SH_OUTPUT, T> OutputType;
00058   typedef ShMatrix<Rows, Cols, SH_INOUT, T> InOutType;
00059   typedef ShMatrix<Rows, Cols, SH_TEMP, T> TempType;
00060   typedef ShMatrix<Rows, Cols, SH_CONST, T> ConstType;
00061 
00069   ShMatrix();
00070 
00075   ShMatrix(const ShMatrix<Rows, Cols, Binding, T>& other);
00076 
00077 
00082   template<ShBindingType Binding2>
00083   ShMatrix(const ShMatrix<Rows, Cols, Binding2, T>& other);
00084   
00085   ~ShMatrix();
00086 
00092   ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding, T>& other);
00093 
00099   template<ShBindingType Binding2>
00100   ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00101 
00106   ShMatrix& operator=(const T& scalar);
00107 
00112   ShMatrix& operator=(const ShGeneric<1, T>& scalar);
00113 
00118   ShAttrib<Cols, Binding, T>& operator[](int i);
00119 
00124   const ShAttrib<Cols, Binding, T>& operator[](int i) const;
00125 
00131   template<ShBindingType Binding2>
00132   ShMatrix& operator+=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00133 
00139   template<ShBindingType Binding2>
00140   ShMatrix& operator-=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00141 
00142 
00149   template<ShBindingType Binding2>
00150   ShMatrix& operator/=(const ShMatrix<Rows, Cols, Binding2, T>& other);    
00151 
00157   template<ShBindingType Binding2>
00158   ShMatrix& operator*=(const ShMatrix<Rows, Cols, Binding2, T>& other);    
00159    
00164   ShMatrix& operator-();
00165 
00170   ShMatrix<Rows - 1, Cols -1, SH_TEMP, T> subMatrix(int,int) const;
00171 
00172   void setTranslation(const ShGeneric<Rows-1, T>& trans);
00173   
00174   void setScaling(const ShGeneric<Rows-1, T>& scale);
00175 
00176 
00182   ShMatrix& operator*=(const ShGeneric<1, T>& a);
00183     
00188   ShMatrix& operator/=(const ShGeneric<1, T>& a);
00189 
00195   ShMatrixRows<Rows, Cols, T> operator()() const; 
00196   ShMatrixRows<1, Cols, T> operator()(int) const;
00197   ShMatrixRows<2, Cols, T> operator()(int, int) const;
00198   ShMatrixRows<3, Cols, T> operator()(int, int, int) const;
00199   ShMatrixRows<4, Cols, T> operator()(int, int, int, int) const;
00201   
00207 
00209   void range(host_type low, host_type high);
00210 
00212   
00213   virtual std::string name() const;
00214   virtual void name(const std::string& n);
00215   virtual bool has_name() const;
00216   
00217   virtual bool internal() const;
00218   virtual void internal(bool);
00219 
00220   virtual std::string title() const;
00221   virtual void title(const std::string& t);
00222 
00223   virtual std::string description() const;
00224   virtual void description(const std::string& d);
00225 
00226   virtual std::string meta(const std::string& key) const;
00227   virtual void meta(const std::string& key, const std::string& value);
00228 
00229   int size() const { return Rows * Cols; }
00230   
00231   virtual void getValues(host_type dest[]) const;
00232 
00233 private:
00238   ShAttrib<Cols, Binding, T> m_data[Rows];
00239   
00240 };
00247 template<int R, int C, ShBindingType B, typename Ty>
00248 std::ostream& operator<<(std::ostream& out,
00249                          const ShMatrix<R, C, B, Ty>& m);
00250 
00257 template<int Rows, int Cols, typename T>
00258 class ShMatrixRows {
00259 public:
00260   template<ShBindingType Binding>
00261   ShMatrixRows(const ShMatrix<Rows, Cols, Binding, T>& source);
00262   
00263   template<int OR, ShBindingType Binding>
00264   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00265                int idx0);
00266   template<int OR, ShBindingType Binding>
00267   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00268                int idx0, int idx1);
00269   template<int OR, ShBindingType Binding>
00270   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00271                int idx0, int idx1, int idx2);
00272   template<int OR, ShBindingType Binding>
00273   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00274                int idx0, int idx1, int idx2, int idx3);
00275 
00276   ShMatrixRows(const ShMatrixRows<Rows, Cols, T>& other);
00277   
00278   ShMatrixRows& operator=(const ShMatrixRows<Rows, Cols, T>& other);
00279 
00284   ShMatrix<Rows, Cols, SH_TEMP, T> operator()() const; 
00285   ShMatrix<Rows, 1, SH_TEMP, T> operator()(int) const;
00286   ShMatrix<Rows, 2, SH_TEMP, T> operator()(int, int) const;
00287   ShMatrix<Rows, 3, SH_TEMP, T> operator()(int, int, int) const;
00288   ShMatrix<Rows, 4, SH_TEMP, T> operator()(int, int, int, int) const;
00290 private:
00291   ShAttrib<Cols, SH_TEMP, T> m_data[Rows];
00292 };
00293 
00294 
00295 typedef ShMatrix<1, 1, SH_INPUT, float> ShInputMatrix1x1f;
00296 typedef ShMatrix<1, 1, SH_OUTPUT, float> ShOutputMatrix1x1f;
00297 typedef ShMatrix<1, 1, SH_INOUT, float> ShInOutMatrix1x1f;
00298 typedef ShMatrix<1, 1, SH_TEMP, float> ShMatrix1x1f;
00299 typedef ShMatrix<1, 2, SH_INPUT, float> ShInputMatrix1x2f;
00300 typedef ShMatrix<1, 2, SH_OUTPUT, float> ShOutputMatrix1x2f;
00301 typedef ShMatrix<1, 2, SH_INOUT, float> ShInOutMatrix1x2f;
00302 typedef ShMatrix<1, 2, SH_TEMP, float> ShMatrix1x2f;
00303 typedef ShMatrix<1, 3, SH_INPUT, float> ShInputMatrix1x3f;
00304 typedef ShMatrix<1, 3, SH_OUTPUT, float> ShOutputMatrix1x3f;
00305 typedef ShMatrix<1, 3, SH_INOUT, float> ShInOutMatrix1x3f;
00306 typedef ShMatrix<1, 3, SH_TEMP, float> ShMatrix1x3f;
00307 typedef ShMatrix<1, 4, SH_INPUT, float> ShInputMatrix1x4f;
00308 typedef ShMatrix<1, 4, SH_OUTPUT, float> ShOutputMatrix1x4f;
00309 typedef ShMatrix<1, 4, SH_INOUT, float> ShInOutMatrix1x4f;
00310 typedef ShMatrix<1, 4, SH_TEMP, float> ShMatrix1x4f;
00311 
00312 typedef ShMatrix<2, 1, SH_INPUT, float> ShInputMatrix2x1f;
00313 typedef ShMatrix<2, 1, SH_OUTPUT, float> ShOutputMatrix2x1f;
00314 typedef ShMatrix<2, 1, SH_INOUT, float> ShInOutMatrix2x1f;
00315 typedef ShMatrix<2, 1, SH_TEMP, float> ShMatrix2x1f;
00316 typedef ShMatrix<2, 2, SH_INPUT, float> ShInputMatrix2x2f;
00317 typedef ShMatrix<2, 2, SH_OUTPUT, float> ShOutputMatrix2x2f;
00318 typedef ShMatrix<2, 2, SH_INOUT, float> ShInOutMatrix2x2f;
00319 typedef ShMatrix<2, 2, SH_TEMP, float> ShMatrix2x2f;
00320 typedef ShMatrix<2, 3, SH_INPUT, float> ShInputMatrix2x3f;
00321 typedef ShMatrix<2, 3, SH_OUTPUT, float> ShOutputMatrix2x3f;
00322 typedef ShMatrix<2, 3, SH_INOUT, float> ShInOutMatrix2x3f;
00323 typedef ShMatrix<2, 3, SH_TEMP, float> ShMatrix2x3f;
00324 typedef ShMatrix<2, 4, SH_INPUT, float> ShInputMatrix2x4f;
00325 typedef ShMatrix<2, 4, SH_OUTPUT, float> ShOutputMatrix2x4f;
00326 typedef ShMatrix<2, 4, SH_INOUT, float> ShInOutMatrix2x4f;
00327 typedef ShMatrix<2, 4, SH_TEMP, float> ShMatrix2x4f;
00328 
00329 typedef ShMatrix<3, 1, SH_INPUT, float> ShInputMatrix3x1f;
00330 typedef ShMatrix<3, 1, SH_OUTPUT, float> ShOutputMatrix3x1f;
00331 typedef ShMatrix<3, 1, SH_INOUT, float> ShInOutMatrix3x1f;
00332 typedef ShMatrix<3, 1, SH_TEMP, float> ShMatrix3x1f;
00333 typedef ShMatrix<3, 2, SH_INPUT, float> ShInputMatrix3x2f;
00334 typedef ShMatrix<3, 2, SH_OUTPUT, float> ShOutputMatrix3x2f;
00335 typedef ShMatrix<3, 2, SH_INOUT, float> ShInOutMatrix3x2f;
00336 typedef ShMatrix<3, 2, SH_TEMP, float> ShMatrix3x2f;
00337 typedef ShMatrix<3, 3, SH_INPUT, float> ShInputMatrix3x3f;
00338 typedef ShMatrix<3, 3, SH_OUTPUT, float> ShOutputMatrix3x3f;
00339 typedef ShMatrix<3, 3, SH_INOUT, float> ShInOutMatrix3x3f;
00340 typedef ShMatrix<3, 3, SH_TEMP, float> ShMatrix3x3f;
00341 typedef ShMatrix<3, 4, SH_INPUT, float> ShInputMatrix3x4f;
00342 typedef ShMatrix<3, 4, SH_OUTPUT, float> ShOutputMatrix3x4f;
00343 typedef ShMatrix<3, 4, SH_INOUT, float> ShInOutMatrix3x4f;
00344 typedef ShMatrix<3, 4, SH_TEMP, float> ShMatrix3x4f;
00345 
00346 typedef ShMatrix<4, 1, SH_INPUT, float> ShInputMatrix4x1f;
00347 typedef ShMatrix<4, 1, SH_OUTPUT, float> ShOutputMatrix4x1f;
00348 typedef ShMatrix<4, 1, SH_INOUT, float> ShInOutMatrix4x1f;
00349 typedef ShMatrix<4, 1, SH_TEMP, float> ShMatrix4x1f;
00350 typedef ShMatrix<4, 2, SH_INPUT, float> ShInputMatrix4x2f;
00351 typedef ShMatrix<4, 2, SH_OUTPUT, float> ShOutputMatrix4x2f;
00352 typedef ShMatrix<4, 2, SH_INOUT, float> ShInOutMatrix4x2f;
00353 typedef ShMatrix<4, 2, SH_TEMP, float> ShMatrix4x2f;
00354 typedef ShMatrix<4, 3, SH_INPUT, float> ShInputMatrix4x3f;
00355 typedef ShMatrix<4, 3, SH_OUTPUT, float> ShOutputMatrix4x3f;
00356 typedef ShMatrix<4, 3, SH_INOUT, float> ShInOutMatrix4x3f;
00357 typedef ShMatrix<4, 3, SH_TEMP, float> ShMatrix4x3f;
00358 typedef ShMatrix<4, 4, SH_INPUT, float> ShInputMatrix4x4f;
00359 typedef ShMatrix<4, 4, SH_OUTPUT, float> ShOutputMatrix4x4f;
00360 typedef ShMatrix<4, 4, SH_INOUT, float> ShInOutMatrix4x4f;
00361 typedef ShMatrix<4, 4, SH_TEMP, float> ShMatrix4x4f;
00362 
00363 }
00364 
00365 #include "ShMatrixImpl.hpp"
00366 
00367 #endif
00368 

Generated on Wed Jun 15 18:12:40 2005 for Sh by  doxygen 1.4.3-20050530