| [658] | 1 | /*************************************************************************** | 
|---|
|  | 2 | * blitz/tinymat.h       Declaration of TinyMatrix<T, N, M> | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * $Id: tinymat.h,v 1.1.1.1 1999-11-26 16:37:04 ansari Exp $ | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
|  | 7 | * | 
|---|
|  | 8 | * This program is free software; you can redistribute it and/or | 
|---|
|  | 9 | * modify it under the terms of the GNU General Public License | 
|---|
|  | 10 | * as published by the Free Software Foundation; either version 2 | 
|---|
|  | 11 | * of the License, or (at your option) any later version. | 
|---|
|  | 12 | * | 
|---|
|  | 13 | * This program is distributed in the hope that it will be useful, | 
|---|
|  | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 16 | * GNU General Public License for more details. | 
|---|
|  | 17 | * | 
|---|
|  | 18 | * Suggestions:          blitz-suggest@cybervision.com | 
|---|
|  | 19 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
|  | 20 | * | 
|---|
|  | 21 | * For more information, please see the Blitz++ Home Page: | 
|---|
|  | 22 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
|  | 23 | * | 
|---|
|  | 24 | *************************************************************************** | 
|---|
|  | 25 | * $Log: not supported by cvs2svn $ | 
|---|
|  | 26 | * Revision 1.1.1.1  1999/04/09  17:59:01  ansari | 
|---|
|  | 27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99 | 
|---|
|  | 28 | * | 
|---|
|  | 29 | * Revision 1.2  1998/03/14 00:04:47  tveldhui | 
|---|
|  | 30 | * 0.2-alpha-05 | 
|---|
|  | 31 | * | 
|---|
|  | 32 | * Revision 1.1  1997/07/16 14:51:20  tveldhui | 
|---|
|  | 33 | * Update: Alpha release 0.2 (Arrays) | 
|---|
|  | 34 | * | 
|---|
|  | 35 | */ | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #ifndef BZ_TINYMAT_H | 
|---|
|  | 38 | #define BZ_TINYMAT_H | 
|---|
|  | 39 |  | 
|---|
|  | 40 | #ifndef BZ_BLITZ_H | 
|---|
|  | 41 | #include <blitz/blitz.h> | 
|---|
|  | 42 | #endif | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #ifndef BZ_TINYVEC_H | 
|---|
|  | 45 | #include <blitz/tinyvec.h> | 
|---|
|  | 46 | #endif | 
|---|
|  | 47 |  | 
|---|
|  | 48 | #ifndef BZ_LISTINIT_H | 
|---|
|  | 49 | #include <blitz/listinit.h> | 
|---|
|  | 50 | #endif | 
|---|
|  | 51 |  | 
|---|
|  | 52 | #include <blitz/tinymatexpr.h> | 
|---|
|  | 53 | #include <blitz/meta/matassign.h> | 
|---|
|  | 54 |  | 
|---|
|  | 55 | BZ_NAMESPACE(blitz) | 
|---|
|  | 56 |  | 
|---|
|  | 57 | // Forward declarations | 
|---|
|  | 58 | template<class T_expr> | 
|---|
|  | 59 | class _bz_tinyMatExpr; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | template<class T_numtype, int N_rows, int N_columns, int N_rowStride, | 
|---|
|  | 62 | int N_colStride> | 
|---|
|  | 63 | class _bz_tinyMatrixRef { | 
|---|
|  | 64 |  | 
|---|
|  | 65 | public: | 
|---|
|  | 66 | _bz_tinyMatrixRef(T_numtype* _bz_restrict const data) | 
|---|
|  | 67 | : data_(data) | 
|---|
|  | 68 | { } | 
|---|
|  | 69 |  | 
|---|
|  | 70 | T_numtype * _bz_restrict data() | 
|---|
|  | 71 | { return (T_numtype * _bz_restrict)data_; } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | T_numtype& _bz_restrict operator()(int i, int j) | 
|---|
|  | 74 | { return data_[i * N_rowStride + j * N_colStride]; } | 
|---|
|  | 75 |  | 
|---|
|  | 76 | T_numtype operator()(int i, int j) const | 
|---|
|  | 77 | { return data_[i * N_rowStride + j * N_colStride]; } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | protected: | 
|---|
|  | 80 | T_numtype * _bz_restrict const data_; | 
|---|
|  | 81 | }; | 
|---|
|  | 82 |  | 
|---|
|  | 83 | template<class P_numtype, int N_rows, int N_columns> | 
|---|
|  | 84 | class TinyMatrix { | 
|---|
|  | 85 |  | 
|---|
|  | 86 | public: | 
|---|
|  | 87 | typedef P_numtype T_numtype; | 
|---|
|  | 88 | typedef _bz_tinyMatrixRef<T_numtype, N_rows, N_columns, N_columns, 1> | 
|---|
|  | 89 | T_reference; | 
|---|
|  | 90 | typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix; | 
|---|
|  | 91 |  | 
|---|
|  | 92 | TinyMatrix() { } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | T_numtype* _bz_restrict data() | 
|---|
|  | 95 | { return data_; } | 
|---|
|  | 96 |  | 
|---|
|  | 97 | const T_numtype* _bz_restrict data() const | 
|---|
|  | 98 | { return data_; } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | T_numtype* _bz_restrict dataFirst() | 
|---|
|  | 101 | { return data_; } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | const T_numtype* _bz_restrict dataFirst() const | 
|---|
|  | 104 | { return data_; } | 
|---|
|  | 105 |  | 
|---|
|  | 106 | // NEEDS_WORK -- precondition checks | 
|---|
|  | 107 | T_numtype& _bz_restrict operator()(int i, int j) | 
|---|
|  | 108 | { return data_[i*N_columns + j]; } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | T_numtype operator()(int i, int j) const | 
|---|
|  | 111 | { return data_[i*N_columns + j]; } | 
|---|
|  | 112 |  | 
|---|
|  | 113 | T_reference getRef() | 
|---|
|  | 114 | { return T_reference((T_numtype*)data_); } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | const T_reference getRef() const | 
|---|
|  | 117 | { return T_reference((T_numtype*)data_); } | 
|---|
|  | 118 |  | 
|---|
|  | 119 | // Scalar operand | 
|---|
|  | 120 | ListInitializationSwitch<T_matrix> | 
|---|
|  | 121 | operator=(T_numtype x) | 
|---|
|  | 122 | { | 
|---|
|  | 123 | return ListInitializationSwitch<T_matrix>(*this, x); | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
|  | 126 | template<class T_expr> | 
|---|
|  | 127 | TinyMatrix<T_numtype, N_rows, N_columns>& | 
|---|
|  | 128 | operator=(_bz_tinyMatExpr<T_expr> expr) | 
|---|
|  | 129 | { | 
|---|
|  | 130 | _bz_meta_matAssign<N_rows, N_columns, 0>::f(*this, expr, | 
|---|
|  | 131 | _bz_update<T_numtype, _bz_typename T_expr::T_numtype>()); | 
|---|
|  | 132 | return *this; | 
|---|
|  | 133 | } | 
|---|
|  | 134 |  | 
|---|
|  | 135 | // NEEDS_WORK -- not implemented | 
|---|
|  | 136 | void initialize(T_numtype x) | 
|---|
|  | 137 | { BZ_NOT_IMPLEMENTED(); } | 
|---|
|  | 138 |  | 
|---|
|  | 139 | T_numtype* _bz_restrict getInitializationIterator() | 
|---|
|  | 140 | { return dataFirst(); } | 
|---|
|  | 141 |  | 
|---|
|  | 142 | protected: | 
|---|
|  | 143 | T_numtype data_[N_rows * N_columns]; | 
|---|
|  | 144 | }; | 
|---|
|  | 145 |  | 
|---|
|  | 146 | BZ_NAMESPACE_END | 
|---|
|  | 147 |  | 
|---|
|  | 148 | #include <blitz/meta/matvec.h>     // Matrix-vector product metaprogram | 
|---|
|  | 149 | #include <blitz/meta/matmat.h>     // Matrix-matrix products | 
|---|
|  | 150 |  | 
|---|
|  | 151 | #endif // BZ_TINYMAT_H | 
|---|
|  | 152 |  | 
|---|