メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

ArrayN.cc

解説を見る。
00001 // Template array classes
00002 /*
00003 
00004 Copyright (C) 2000 John W. Eaton
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 2, or (at your option) any
00011 later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, write to the Free
00020 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 
00022 */
00023 
00024 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00025 #pragma implementation
00026 #endif
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <cassert>
00033 
00034 #include <iostream>
00035 
00036 #include "Array-util.h"
00037 #include "ArrayN.h"
00038 #include "ArrayN-idx.h"
00039 #include "idx-vector.h"
00040 #include "lo-error.h"
00041 
00042 // N-dimensional array class.
00043 
00044 template <class T>
00045 std::ostream&
00046 operator << (std::ostream& os, const ArrayN<T>& a)
00047 {
00048   dim_vector a_dims = a.dims ();
00049 
00050   int n_dims = a_dims.length ();
00051 
00052   os << n_dims << "-dimensional array";
00053 
00054   if (n_dims)
00055     os << " (" << a_dims.str () << ")";
00056 
00057   os <<"\n\n";
00058 
00059   if (n_dims)
00060     {
00061       os << "data:";
00062 
00063       Array<int> ra_idx (n_dims, 0);
00064 
00065       // Number of times the first 2d-array is to be displayed.
00066 
00067       int m = 1;
00068       for (int i = 2; i < n_dims; i++)
00069         m *= a_dims(i);
00070 
00071       if (m == 1)
00072         {
00073           int rows = 0;
00074           int cols = 0;
00075 
00076           switch (n_dims)
00077             {
00078             case 2:
00079               rows = a_dims(0);
00080               cols = a_dims(1);
00081 
00082               for (int j = 0; j < rows; j++)
00083                 {
00084                   ra_idx(0) = j;
00085                   for (int k = 0; k < cols; k++)
00086                     {
00087                       ra_idx(1) = k;
00088                       os << " " << a.elem(ra_idx);
00089                     }
00090                   os << "\n";
00091                 }
00092               break;
00093 
00094             default:
00095               rows = a_dims(0);
00096 
00097               for (int k = 0; k < rows; k++)
00098                 {
00099                   ra_idx(0) = k;
00100                   os << " " << a.elem(ra_idx);
00101                 }
00102               break;
00103             }
00104 
00105           os << "\n";
00106         }
00107       else
00108         {
00109           int rows = a_dims(0);
00110           int cols = a_dims(1);
00111 
00112           for (int i = 0; i < m; i++)
00113             {
00114               os << "\n(:,:,";
00115 
00116               for (int j = 2; j < n_dims - 1; j++)
00117                 os << ra_idx(j) + 1 << ",";
00118 
00119               os << ra_idx(n_dims - 1) + 1 << ") = \n";
00120 
00121               for (int j = 0; j < rows; j++)
00122                 {
00123                   ra_idx(0) = j;
00124 
00125                   for (int k = 0; k < cols; k++)
00126                     {
00127                       ra_idx(1) = k;
00128                       os << " " << a.elem(ra_idx);
00129                     }
00130 
00131                   os << "\n";
00132                 }
00133 
00134               os << "\n";
00135 
00136               if (i != m - 1)
00137                 increment_index (ra_idx, a_dims, 2);
00138             }
00139         }
00140     }
00141 
00142   return os;
00143 }
00144 
00145 /*
00146 ;;; Local Variables: ***
00147 ;;; mode: C++ ***
00148 ;;; End: ***
00149 */

Wed Dec 29 11:50:55 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送