comparison liboctave/Array.cc @ 9732:b4fdfee405b5

remove ArrayN<T> + fix nonhom. diag-scalar ops
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 16 Oct 2009 13:12:31 +0200
parents 7b9cbaad68d6
children 01f897d8a130
comparison
equal deleted inserted replaced
9731:7b9cbaad68d6 9732:b4fdfee405b5
2935 2935
2936 #define INSTANTIATE_ARRAY(T, API) \ 2936 #define INSTANTIATE_ARRAY(T, API) \
2937 template <> void Array<T>::instantiation_guard () { } \ 2937 template <> void Array<T>::instantiation_guard () { } \
2938 template class API Array<T> 2938 template class API Array<T>
2939 2939
2940 // FIXME: is this used?
2941
2942 template <class T>
2943 std::ostream&
2944 operator << (std::ostream& os, const Array<T>& a)
2945 {
2946 dim_vector a_dims = a.dims ();
2947
2948 int n_dims = a_dims.length ();
2949
2950 os << n_dims << "-dimensional array";
2951
2952 if (n_dims)
2953 os << " (" << a_dims.str () << ")";
2954
2955 os <<"\n\n";
2956
2957 if (n_dims)
2958 {
2959 os << "data:";
2960
2961 Array<octave_idx_type> ra_idx (n_dims, 0);
2962
2963 // Number of times the first 2d-array is to be displayed.
2964
2965 octave_idx_type m = 1;
2966 for (int i = 2; i < n_dims; i++)
2967 m *= a_dims(i);
2968
2969 if (m == 1)
2970 {
2971 octave_idx_type rows = 0;
2972 octave_idx_type cols = 0;
2973
2974 switch (n_dims)
2975 {
2976 case 2:
2977 rows = a_dims(0);
2978 cols = a_dims(1);
2979
2980 for (octave_idx_type j = 0; j < rows; j++)
2981 {
2982 ra_idx(0) = j;
2983 for (octave_idx_type k = 0; k < cols; k++)
2984 {
2985 ra_idx(1) = k;
2986 os << " " << a.elem(ra_idx);
2987 }
2988 os << "\n";
2989 }
2990 break;
2991
2992 default:
2993 rows = a_dims(0);
2994
2995 for (octave_idx_type k = 0; k < rows; k++)
2996 {
2997 ra_idx(0) = k;
2998 os << " " << a.elem(ra_idx);
2999 }
3000 break;
3001 }
3002
3003 os << "\n";
3004 }
3005 else
3006 {
3007 octave_idx_type rows = a_dims(0);
3008 octave_idx_type cols = a_dims(1);
3009
3010 for (int i = 0; i < m; i++)
3011 {
3012 os << "\n(:,:,";
3013
3014 for (int j = 2; j < n_dims - 1; j++)
3015 os << ra_idx(j) + 1 << ",";
3016
3017 os << ra_idx(n_dims - 1) + 1 << ") = \n";
3018
3019 for (octave_idx_type j = 0; j < rows; j++)
3020 {
3021 ra_idx(0) = j;
3022
3023 for (octave_idx_type k = 0; k < cols; k++)
3024 {
3025 ra_idx(1) = k;
3026 os << " " << a.elem(ra_idx);
3027 }
3028
3029 os << "\n";
3030 }
3031
3032 os << "\n";
3033
3034 if (i != m - 1)
3035 increment_index (ra_idx, a_dims, 2);
3036 }
3037 }
3038 }
3039
3040 return os;
3041 }
3042
2940 /* 3043 /*
2941 ;;; Local Variables: *** 3044 ;;; Local Variables: ***
2942 ;;; mode: C++ *** 3045 ;;; mode: C++ ***
2943 ;;; End: *** 3046 ;;; End: ***
2944 */ 3047 */