16 #ifndef dealii_table_h
17 #define dealii_table_h
35 template <
int N,
typename T>
37 template <
int N,
typename T>
75 namespace TableBaseAccessors
84 template <
int N,
typename T,
bool Constness>
93 template <
int N,
typename T>
111 template <
int N,
typename T>
163 template <
int N,
typename T,
bool C,
unsigned int P>
206 <<
"Index " <<
N - P + 1 <<
"has a value of " << arg1
207 <<
" but needs to be in the range [" << arg2 <<
"," << arg3
223 template <
int N1,
typename T1>
224 friend class ::Table;
225 template <
int N1,
typename T1,
bool C1,
unsigned int P1>
227 #ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
228 friend class ::Table<N, T>;
244 template <
int N,
typename T,
bool C>
330 template <
int N1,
typename T1>
331 friend class ::Table;
332 template <
int N1,
typename T1,
bool C1,
unsigned int P1>
334 #ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
335 friend class ::Table<2, T>;
411 template <
int N,
typename T>
439 template <
typename InputIterator>
441 InputIterator entries,
442 const bool C_style_indexing =
true);
453 template <
typename T2>
484 template <
typename T2>
518 const bool omit_default_initialization =
false);
524 size(
const unsigned int i)
const;
582 template <
typename InputIterator>
584 fill(InputIterator entries,
const bool C_style_indexing =
true);
634 template <
class Archive>
636 serialize(Archive &ar,
const unsigned int version);
680 template <
int,
typename>
698 template <
int N,
typename T>
715 template <
typename T>
771 template <
typename InputIterator>
773 InputIterator entries,
774 const bool C_style_indexing =
true);
847 template <
typename TableType,
bool Constness, Storage storage_order>
854 template <
typename TableType,
bool Constness, Storage storage_order>
873 template <
typename TableType,
bool Constness, Storage storage_order>
881 conditional<Constness, const TableType *, TableType *>::type;
963 Iterator<TableType, Constness, storage_order>,
971 template <
typename TableType, Storage storage_order>
998 template <
typename TableType, Storage storage_order>
1065 template <
typename TableType,
bool Constness, Storage storage_order>
1068 Accessor<TableType, Constness, storage_order>>
1080 conditional<Constness, const TableType *, TableType *>::type;
1108 const std::ptrdiff_t linear_index);
1127 template <
typename T>
1161 using iterator = MatrixTableIterators::
1212 template <
typename InputIterator>
1215 InputIterator entries,
1216 const bool C_style_indexing =
true);
1226 const bool omit_default_initialization =
false);
1355 AccessorBase<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1360 Accessor<Table<2, T>, false, MatrixTableIterators::Storage::row_major>;
1375 template <typename T>
1434 template <
typename InputIterator>
1438 InputIterator entries,
1439 const bool C_style_indexing =
true);
1507 template <
typename T>
1601 template <
typename T>
1698 template <
typename T>
1796 template <
typename T>
1897 template <
typename T,
bool Constness>
1903 template <
typename T,
bool Constness>
1909 template <
typename T,
bool Constness>
1930 template <
typename T>
1989 const bool omit_default_initialization =
false);
2087 MatrixTableIterators::Storage::column_major>;
2094 MatrixTableIterators::Storage::column_major>;
2103 template <int N, typename T>
2111 template <
int N,
typename T>
2112 template <
typename InputIterator>
2114 InputIterator entries,
2115 const bool C_style_indexing)
2118 fill(entries, C_style_indexing);
2123 template <
int N,
typename T>
2133 template <
int N,
typename T>
2134 template <
typename T2>
2144 template <
int N,
typename T>
2147 , values(std::move(src.
values))
2155 template <
int N,
typename T>
2156 template <
class Archive>
2162 ar &values &table_size;
2169 namespace TableBaseAccessors
2171 template <
int N,
typename T,
bool C,
unsigned int P>
2173 const iterator data)
2180 template <
int N,
typename T,
bool C,
unsigned int P>
2188 template <
int N,
typename T,
bool C,
unsigned int P>
2189 inline Accessor<
N,
T,
C, P - 1> Accessor<N, T, C, P>::
2204 size_type subobject_size = table.size()[
N - 1];
2205 for (
int p = P - 1; p > 1; --p)
2206 subobject_size *= table.size()[
N - p];
2207 const iterator new_data = data + i * subobject_size;
2214 template <
int N,
typename T,
bool C>
2216 const iterator data)
2223 template <
int N,
typename T,
bool C>
2231 template <
int N,
typename T,
bool C>
2232 inline typename Accessor<N, T, C, 1>::reference Accessor<N, T, C, 1>::
2241 template <
int N,
typename T,
bool C>
2243 Accessor<N, T, C, 1>::size()
const
2245 return table.size()[
N - 1];
2250 template <
int N,
typename T,
bool C>
2251 inline typename Accessor<N, T, C, 1>::iterator
2259 template <
int N,
typename T,
bool C>
2260 inline typename Accessor<N, T, C, 1>::iterator
2263 return data + table.size()[
N - 1];
2270 template <
int N,
typename T>
2283 template <
int N,
typename T>
2284 template <
typename T2>
2291 m.
values.begin() + n_elements(),
2299 template <
int N,
typename T>
2304 values = std::move(m.
values);
2313 template <
int N,
typename T>
2317 return (values == T2.
values);
2322 template <
int N,
typename T>
2327 if (n_elements() != 0)
2333 template <
int N,
typename T>
2337 if (n_elements() != 0)
2343 template <
int N,
typename T>
2346 const bool omit_default_initialization)
2348 table_size = new_sizes;
2350 const size_type new_size = n_elements();
2371 if (!omit_default_initialization)
2374 values.resize(new_size);
2377 values.resize_fast(new_size);
2382 values.resize_fast(new_size);
2387 template <
int N,
typename T>
2396 template <
int N,
typename T>
2401 return table_size[i];
2406 template <
int N,
typename T>
2411 for (
unsigned int n = 0; n <
N; ++n)
2418 template <
int N,
typename T>
2422 return (n_elements() == 0);
2429 namespace TableImplementation
2431 template <
typename InputIterator,
typename T>
2441 template <
typename InputIterator,
typename T>
2452 template <
typename InputIterator,
typename T>
2464 template <
typename InputIterator,
typename T,
int N>
2474 template <
int N,
typename T>
2475 template <
typename InputIterator>
2481 if (C_style_indexing)
2487 internal::TableImplementation::fill_Fortran_style(entries, *
this);
2492 template <
int N,
typename T>
2502 template <
int N,
typename T>
2511 template <
int N,
typename T>
2525 return size_type(indices[0]) * table_size[1] + indices[1];
2527 return ((
size_type(indices[0]) * table_size[1] + indices[1]) *
2532 unsigned int s = indices[0];
2533 for (
unsigned int n = 1; n <
N; ++n)
2534 s = s * table_size[n] + indices[n];
2542 template <
int N,
typename T>
2546 for (
unsigned int n = 0; n <
N; ++n)
2553 template <
int N,
typename T>
2557 for (
unsigned int n = 0; n <
N; ++n)
2564 template <
int N,
typename T>
2568 return values[position(indices)];
2573 template <
int N,
typename T>
2578 return values[position(indices)];
2583 template <
typename T>
2590 template <
typename T>
2591 template <
typename InputIterator>
2593 InputIterator entries,
2594 const bool C_style_indexing)
2600 template <
typename T>
2610 template <
typename T>
2620 template <
typename T>
2630 template <
typename T>
2640 template <
typename T>
2649 template <
typename T>
2661 template <
typename T>
2668 template <
typename T>
2669 template <
typename InputIterator>
2672 InputIterator entries,
2673 const bool C_style_indexing)
2679 template <
typename T>
2683 const bool omit_default_initialization)
2686 omit_default_initialization);
2691 template <
typename T>
2692 inline ::internal::TableBaseAccessors::Accessor<2, T, true, 1>
2696 return ::internal::TableBaseAccessors::Accessor<2, T, true, 1>(
2702 template <
typename T>
2703 inline ::internal::TableBaseAccessors::Accessor<2, T, false, 1>
2707 return ::internal::TableBaseAccessors::Accessor<2, T, false, 1>(
2713 template <
typename T>
2724 template <
typename T>
2735 template <
typename T>
2744 template <
typename T>
2753 template <
typename T>
2762 template <
typename T>
2771 template <
typename T>
2780 template <
typename T>
2789 template <
typename T>
2798 template <
typename T>
2807 template <
typename T>
2816 template <
typename T>
2832 template <
typename TableType, Storage storage_order>
2833 inline std::ptrdiff_t
2834 get_row_index(
const std::ptrdiff_t linear_index,
2835 const TableType *
const container)
2837 switch (storage_order)
2840 return linear_index / container->n_cols();
2842 return linear_index % container->n_rows();
2851 template <
typename TableType, Storage storage_order>
2852 inline std::ptrdiff_t
2853 get_column_index(
const std::ptrdiff_t linear_index,
2854 const TableType *
const container)
2856 switch (storage_order)
2859 return linear_index % container->n_cols();
2861 return linear_index / container->n_rows();
2871 template <
typename TableType,
bool Constness, Storage storage_order>
2873 : container(nullptr)
2874 , linear_index(std::numeric_limits<decltype(linear_index)>::
max())
2879 template <
typename TableType,
bool Constness, Storage storage_order>
2881 const container_pointer_type table)
2883 , linear_index(container->values.size())
2888 template <
typename TableType,
bool Constness, Storage storage_order>
2890 const AccessorBase<TableType, false, storage_order> &a)
2891 : container(a.container)
2892 , linear_index(a.linear_index)
2897 template <
typename TableType,
bool Constness, Storage storage_order>
2899 const container_pointer_type table,
2900 const std::ptrdiff_t index)
2902 , linear_index(index)
2904 Assert(0 <= linear_index &&
2905 std::size_t(linear_index) < container->values.size() + 1,
2906 ExcMessage(
"The current iterator points outside of the table and is "
2907 "not the end iterator."));
2912 template <
typename TableType,
bool Constness, Storage storage_order>
2913 inline const typename AccessorBase<TableType, Constness, storage_order>::
2917 assert_valid_linear_index();
2918 return this->container->values[linear_index];
2923 template <
typename TableType,
bool Constness, Storage storage_order>
2924 inline AccessorBase<TableType, Constness, storage_order>::
2927 assert_valid_linear_index();
2928 return this->container->values[linear_index];
2933 template <
typename TableType,
bool Constness, Storage storage_order>
2935 AccessorBase<TableType, Constness, storage_order>::row()
const
2937 assert_valid_linear_index();
2938 return static_cast<std::size_t
>(
2939 internal::get_row_index<TableType, storage_order>(linear_index,
2945 template <
typename TableType,
bool Constness, Storage storage_order>
2947 AccessorBase<TableType, Constness, storage_order>::column()
const
2949 assert_valid_linear_index();
2950 return static_cast<std::size_t
>(
2951 internal::get_column_index<TableType, storage_order>(linear_index,
2957 template <
typename TableType,
bool Constness, Storage storage_order>
2959 AccessorBase<TableType, Constness, storage_order>::assert_valid_linear_index()
2962 # ifdef DEBUG // avoid unused variable warnings by guarding everything
2963 Assert(container !=
nullptr,
2964 ExcMessage(
"This accessor has been default-constructed and does not "
2965 "have a corresponding table."));
2966 Assert(!container->empty(),
2967 ExcMessage(
"An empty table has no rows or columns."));
2968 Assert(0 <= linear_index &&
2969 std::size_t(linear_index) < container->values.size(),
2970 ExcMessage(
"The current iterator points outside of the table."));
2971 const std::ptrdiff_t row_n =
2972 internal::get_row_index<TableType, storage_order>(linear_index,
2974 const std::ptrdiff_t column_n =
2975 internal::get_column_index<TableType, storage_order>(linear_index,
2977 Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(),
2978 ExcMessage(
"The current iterator points outside the table."));
2979 Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(),
2980 ExcMessage(
"The current iterator points outside the table."));
2986 template <
typename TableType, Storage storage_order>
2987 inline const Accessor<TableType, false, storage_order> &
2988 Accessor<TableType, false, storage_order>::operator=(
2989 const typename Accessor<TableType, false, storage_order>::value_type &t)
2992 this->assert_valid_linear_index();
2993 this->container->values[this->linear_index] = t;
2999 template <
typename TableType, Storage storage_order>
3000 inline const Accessor<TableType, false, storage_order> &
3001 Accessor<TableType, false, storage_order>::operator=(
3002 typename Accessor<TableType, false, storage_order>::value_type &&t)
const
3004 this->assert_valid_linear_index();
3005 this->container->values[this->linear_index] = t;
3011 template <
typename TableType, Storage storage_order>
3012 inline typename Accessor<TableType, false, storage_order>::value_type &
3015 this->assert_valid_linear_index();
3016 return this->container->values[this->linear_index];
3021 template <
typename TableType, Storage storage_order>
3022 inline Accessor<TableType, false, storage_order>::operator
value_type &()
3024 this->assert_valid_linear_index();
3025 return this->container->values[this->linear_index];
3030 template <
typename TableType,
bool Constness, Storage storage_order>
3032 const Accessor<TableType, Constness, storage_order> &a)
3034 Accessor<TableType, Constness, storage_order>>(a)
3039 template <
typename TableType,
bool Constness, Storage storage_order>
3041 const container_pointer_type table)
3043 Accessor<TableType, Constness, storage_order>>(
3044 Accessor<TableType, Constness, storage_order>(table))
3049 template <
typename TableType,
bool Constness, Storage storage_order>
3051 const Iterator<TableType, false, storage_order> &i)
3053 Accessor<TableType, Constness, storage_order>>(*i)
3058 template <
typename TableType,
bool Constness, Storage storage_order>
3060 const container_pointer_type table,
3065 table->n_cols() * row_n + col_n :
3066 table->n_rows() * col_n + row_n)
3071 template <
typename TableType,
bool Constness, Storage storage_order>
3073 const container_pointer_type table,
3074 const std::ptrdiff_t linear_index)
3076 Accessor<TableType, Constness, storage_order>>(
3077 Accessor<TableType, Constness, storage_order>(table, linear_index))
3084 template <
typename T>
3092 template <
typename T>
3096 const bool omit_default_initialization)
3099 omit_default_initialization);
3104 template <
typename T>
3110 return this->values[
size_type(j) * this->table_size[1] + i];
3115 template <
typename T>
3121 return this->values[
size_type(j) * this->table_size[1] + i];
3126 template <
typename T>
3130 return this->values[
size_type(j) * this->table_size[1] + i];
3135 template <
typename T>
3139 return this->values[
size_type(j) * this->table_size[1] + i];
3144 template <
typename T>
3148 return this->table_size[1];
3153 template <
typename T>
3157 return this->table_size[0];
3162 template <
typename T>
3171 template <
typename T>
3180 template <
typename T>
3189 template <
typename T>
3199 template <
typename T>
3208 template <
typename T>
3209 template <
typename InputIterator>
3213 InputIterator entries,
3214 const bool C_style_indexing)
3222 template <
typename T>
3223 inline ::internal::TableBaseAccessors::Accessor<3, T, true, 2>
3230 *
this, this->
values.begin() + i * subobject_size));
3235 template <
typename T>
3236 inline ::internal::TableBaseAccessors::Accessor<3, T, false, 2>
3243 *
this, this->
values.begin() + i * subobject_size));
3248 template <
typename T>
3263 template <
typename T>
3277 template <
typename T>
3286 template <
typename T>
3295 template <
typename T>
3305 template <
typename T>
3306 inline ::internal::TableBaseAccessors::Accessor<4, T, true, 3>
3313 *
this, this->
values.begin() + i * subobject_size));
3318 template <
typename T>
3319 inline ::internal::TableBaseAccessors::Accessor<4, T, false, 3>
3324 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3];
3326 *
this, this->
values.begin() + i * subobject_size));
3331 template <
typename T>
3343 ->values[((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3345 this->table_size[3] +
3351 template <
typename T>
3363 ->values[((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3365 this->table_size[3] +
3371 template <
typename T>
3380 template <
typename T>
3389 template <
typename T>
3400 template <
typename T>
3401 inline ::internal::TableBaseAccessors::Accessor<5, T, true, 4>
3406 this->table_size[2] * this->table_size[3] *
3407 this->table_size[4];
3409 *
this, this->
values.begin() + i * subobject_size));
3414 template <
typename T>
3415 inline ::internal::TableBaseAccessors::Accessor<5, T, false, 4>
3420 this->table_size[2] * this->table_size[3] *
3421 this->table_size[4];
3423 *
this, this->
values.begin() + i * subobject_size));
3428 template <
typename T>
3442 ->values[(((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3444 this->table_size[3] +
3446 this->table_size[4] +
3452 template <
typename T>
3466 ->values[(((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3468 this->table_size[3] +
3470 this->table_size[4] +
3476 template <
typename T>
3485 template <
typename T>
3494 template <
typename T>
3504 table_indices[0] = size1;
3505 table_indices[1] = size2;
3506 table_indices[2] = size3;
3507 table_indices[3] = size4;
3508 table_indices[4] = size5;
3509 table_indices[5] = size6;
3516 template <
typename T>
3517 inline ::internal::TableBaseAccessors::Accessor<6, T, true, 5>
3522 this->table_size[2] * this->table_size[3] *
3523 this->table_size[4] * this->table_size[5];
3525 *
this, this->
values.begin() + i * subobject_size));
3530 template <
typename T>
3531 inline ::internal::TableBaseAccessors::Accessor<6, T, false, 5>
3536 this->table_size[2] * this->table_size[3] *
3537 this->table_size[4] * this->table_size[5];
3539 *
this, this->
values.begin() + i * subobject_size));
3544 template <
typename T>
3560 ->values[((((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3562 this->table_size[3] +
3564 this->table_size[4] +
3566 this->table_size[5] +
3572 template <
typename T>
3588 ->values[((((
size_type(i) * this->table_size[1] + j) * this->table_size[2] +
3590 this->table_size[3] +
3592 this->table_size[4] +
3594 this->table_size[5] +
3600 template <
typename T>
3609 template <
typename T>
3618 template <
typename T>
3629 table_indices[0] = size1;
3630 table_indices[1] = size2;
3631 table_indices[2] = size3;
3632 table_indices[3] = size4;
3633 table_indices[4] = size5;
3634 table_indices[5] = size6;
3635 table_indices[6] = size7;
3642 template <
typename T>
3643 inline ::internal::TableBaseAccessors::Accessor<7, T, true, 6>
3648 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3649 this->table_size[4] * this->table_size[5] * this->table_size[6];
3651 *
this, this->
values.begin() + i * subobject_size));
3656 template <
typename T>
3657 inline ::internal::TableBaseAccessors::Accessor<7, T, false, 6>
3662 size_type(this->table_size[1]) * this->table_size[2] * this->table_size[3] *
3663 this->table_size[4] * this->table_size[5] * this->table_size[6];
3665 *
this, this->
values.begin() + i * subobject_size));
3670 template <
typename T>
3688 [(((((
size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3689 this->table_size[3] +
3691 this->table_size[4] +
3693 this->table_size[5] +
3695 this->table_size[6] +
3701 template <
typename T>
3719 [(((((
size_type(i) * this->table_size[1] + j) * this->table_size[2] + k) *
3720 this->table_size[3] +
3722 this->table_size[4] +
3724 this->table_size[5] +
3726 this->table_size[6] +
3732 template <
typename T>
3741 template <
typename T>
3760 template <
int N,
typename T>