source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/tinymat2.cc @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 4.1 KB
Line 
1/***************************************************************************
2 * blitz/tinyvec.cc  Declaration of TinyVector methods
3 *
4 * $Id$
5 *
6 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
7 *
8 * This file is a part of Blitz.
9 *
10 * Blitz is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation, either version 3
13 * of the License, or (at your option) any later version.
14 *
15 * Blitz is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
22 *
23 * Suggestions:          blitz-devel@lists.sourceforge.net
24 * Bugs:                 blitz-support@lists.sourceforge.net   
25 *
26 * For more information, please see the Blitz++ Home Page:
27 *    https://sourceforge.net/projects/blitz/
28 *
29 ***************************************************************************/
30
31#ifndef BZ_TINYMAT2_CC
32#define BZ_TINYMAT2_CC
33
34#include <blitz/tmevaluate.h>
35#include <blitz/tinymat2io.cc>
36#include <blitz/array/domain.h>
37
38BZ_NAMESPACE(blitz)
39
40template<typename P_numtype, int N_rows, int N_columns>
41inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(T_numtype initValue) 
42{
43  for (sizeType i=0; i < numElements(); ++i)
44    data_[i] = initValue;
45}
46
47template<typename P_numtype, int N_rows, int N_columns>
48inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const T_matrix& x) 
49{
50  for (sizeType i=0; i < numElements(); ++i)
51    data_[i] = x.data_[i];
52}
53
54template<typename P_numtype, int N_rows, int N_columns>
55template<typename P_numtype2>
56inline
57TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const TinyMatrix<P_numtype2, N_rows, N_columns>& x)
58{
59  for (sizeType i=0; i < numElements(); ++i)
60    data_[i] = static_cast<P_numtype>(x.data_[i]);
61}
62
63/*
64 * Assignment-type operators
65 */
66
67template<typename P_numtype, int N_rows, int N_columns>
68TinyMatrix<P_numtype, N_rows, N_columns>&
69TinyMatrix<P_numtype, N_rows, N_columns>::initialize(T_numtype x)
70{
71    (*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
72    return *this;
73}
74
75template<typename P_numtype, int N_rows, int N_columns>
76template<typename T_expr>
77inline
78TinyMatrix<P_numtype, N_rows, N_columns>&
79TinyMatrix<P_numtype, N_rows, N_columns>::operator=(const ETBase<T_expr>& expr)
80{
81  _tm_evaluate(_bz_typename asExpr<T_expr>::T_expr(expr.unwrap()), 
82               _bz_update<T_numtype, _bz_typename asExpr<T_expr>::T_expr::T_result>());
83    return *this;
84}
85
86#define BZ_TM2_UPDATE(op,name)                                          \
87  template<typename P_numtype, int N_rows, int N_columns>               \
88  template<typename T>                                                  \
89  inline TinyMatrix<P_numtype, N_rows, N_columns>&                      \
90  TinyMatrix<P_numtype, N_rows, N_columns>::operator op(const T& expr)  \
91  {                                                                     \
92    _tm_evaluate(_bz_typename asExpr<T>::T_expr(expr),                  \
93                 name<T_numtype, _bz_typename asExpr<T>::T_expr::T_result>()); \
94  return *this;                                                         \
95  }
96
97BZ_TM2_UPDATE(+=, _bz_plus_update)
98BZ_TM2_UPDATE(-=, _bz_minus_update)
99BZ_TM2_UPDATE(*=, _bz_multiply_update)
100BZ_TM2_UPDATE(/=, _bz_divide_update)
101BZ_TM2_UPDATE(%=, _bz_mod_update)
102BZ_TM2_UPDATE(^=, _bz_xor_update)
103BZ_TM2_UPDATE(&=, _bz_bitand_update)
104BZ_TM2_UPDATE(|=, _bz_bitor_update)
105BZ_TM2_UPDATE(<<=, _bz_shiftl_update)
106BZ_TM2_UPDATE(>>=, _bz_shiftr_update)
107
108/*
109 * Other member functions
110 */
111
112
113template<typename P_numtype, int N_rows, int N_columns>
114inline RectDomain<2> 
115TinyMatrix<P_numtype, N_rows, N_columns>::domain()
116{
117  return RectDomain<2>(lbound(), ubound()); 
118}
119
120
121template<typename P_numtype, int N_rows, int N_columns>
122template<int N0, int N1>
123inline _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyMatrix<P_numtype, N_rows, N_columns> >::T_expr, N0, N1> >
124TinyMatrix<P_numtype, N_rows, N_columns>::operator()(IndexPlaceholder<N0>, IndexPlaceholder<N1>) const
125{
126  return _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_matrix>::T_expr, 
127                                         N0, N1> >(noConst());
128} 
129
130
131BZ_NAMESPACE_END
132
133#endif // BZ_TINYVEC_CC
Note: See TracBrowser for help on using the repository browser.