Classes var_lens_less_dimen and con_lens_less_dimen cause a matrix to appear to have fewer dimensions, without affecting the ranges of the remaining subscripts. These lenses have an internal state rather like the state of a Standard Library iterator. An X_lens_less_dimen's state is called a marker.
As an example, with a matrix whose form is ( 1 =< 3, 2 =< 6, 5 =< 8, 4 =< 7 ), an X_lens_less_dimen constructor would need a parameter similar to this:
vec_si const w {1, null_int, 7, null_int};where the number of components is equal to the dimensionality of the matrix being lensed. How this is interpreted:
There are eight functions to manage markers:
vec_si const & marker_get () const; sign_int marker_get (sign_int const pos) const; sign_int marker_bot (sign_int const pos) const; sign_int marker_top (sign_int const pos) const; void marker_set (vec_si const & v); void marker_set (sign_int const pos, sign_int const val); void marker_add (sign_int const pos, sign_int const val); void marker_sub (sign_int const pos, sign_int const val);Available for all X_lens_less_dimen:
Function alone_non_var which is used below will be fully described later. However, a brief explanation is that it performs the same operation on every element of a matrix. Then this program:
#include "SOME_DIRECTORY/mat_gen_dim.h" using namespace mat_gen_dim; struct triple { void operator () (double & a) { a *= 3.0; } }; int main () { form const frm_a {blt{1,3},blt{2,6},blt{5,8},blt{4,7}}; cout << "\nfrm_a: " << frm_a; var_matrix<double> mat_a {sub_matrix_linear (frm_a, 0.0)}; cout << "\nmat_a before: " << mat_a; vec_si const w {2, null_int, 6, null_int}; var_lens_less_dimen<double> ald_b {mat_a, w}; cout << "\nald_b with marker at (2, null, 6, null): " << ald_b; ald_b.marker_set (0, 1); ald_b.marker_set (2, 7); cout << "\nald_b with marker moved to (1, null, 7, null): " << ald_b; alone_non_var<triple,double> (ald_b); cout << "\nald_b after tripling: " << ald_b; cout << "\nmat_a after tripling: " << mat_a; return 0; }yields this output:
frm_a: ( 1 =< 3, 2 =< 6, 5 =< 8, 4 =< 7 ) mat_a before: ( 1 2 5 4 ) = 0.1254 ( 1 2 5 5 ) = 0.1255 ( 1 2 5 6 ) = 0.1256 ( 1 2 6 4 ) = 0.1264 ( 1 2 6 5 ) = 0.1265 ( 1 2 6 6 ) = 0.1266 ( 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6 4 ) = 0.2464 ( 2 4 6 5 ) = 0.2465 ( 2 4 6 6 ) = 0.2466 ( 2 4 7 4 ) = 0.2474 ( 2 4 7 5 ) = 0.2475 ( 2 4 7 6 ) = 0.2476 ( 2 5 5 4 ) = 0.2554 ( 2 5 5 5 ) = 0.2555 ( 2 5 5 6 ) = 0.2556 ( 2 5 6 4 ) = 0.2564 ( 2 5 6 5 ) = 0.2565 ( 2 5 6 6 ) = 0.2566 ( 2 5 7 4 ) = 0.2574 ( 2 5 7 5 ) = 0.2575 ( 2 5 7 6 ) = 0.2576 ald_b with marker at (2, null, 6, null): ( 2 4 ) = 0.2264 ( 2 5 ) = 0.2265 ( 2 6 ) = 0.2266 ( 3 4 ) = 0.2364 ( 3 5 ) = 0.2365 ( 3 6 ) = 0.2366 ( 4 4 ) = 0.2464 ( 4 5 ) = 0.2465 ( 4 6 ) = 0.2466 ( 5 4 ) = 0.2564 ( 5 5 ) = 0.2565 ( 5 6 ) = 0.2566 ald_b with marker moved to (1, null, 7, null): ( 2 4 ) = 0.1274 ( 2 5 ) = 0.1275 ( 2 6 ) = 0.1276 ( 3 4 ) = 0.1374 ( 3 5 ) = 0.1375 ( 3 6 ) = 0.1376 ( 4 4 ) = 0.1474 ( 4 5 ) = 0.1475 ( 4 6 ) = 0.1476 ( 5 4 ) = 0.1574 ( 5 5 ) = 0.1575 ( 5 6 ) = 0.1576 ald_b after tripling: ( 2 4 ) = 0.3822 ( 2 5 ) = 0.3825 ( 2 6 ) = 0.3828 ( 3 4 ) = 0.4122 ( 3 5 ) = 0.4125 ( 3 6 ) = 0.4128 ( 4 4 ) = 0.4422 ( 4 5 ) = 0.4425 ( 4 6 ) = 0.4428 ( 5 4 ) = 0.4722 ( 5 5 ) = 0.4725 ( 5 6 ) = 0.4728 mat_a after tripling: ( 1 2 5 4 ) = 0.1254 ( 1 2 5 5 ) = 0.1255 ( 1 2 5 6 ) = 0.1256 ( 1 2 6 4 ) = 0.1264 ( 1 2 6 5 ) = 0.1265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