Boost logo

Boost Users :

Subject: [Boost-users] [multi_array]bug in strides calculation with some storage orderings
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-12-30 12:02:49


If I understand correctly, the multi_array storage order determines
which strides are larger than others. In short:

  if( order[I]>order[I+1])
  then stride[I]>stride[I+1]

However, the output from the attached code shows that this is not
always true. In the attached code, the mono_tonic_print function
tests the conditions and prints out the results. The following
partial output:

  :count=3
    :permut_v={ 1, 2, 0}
    :permut_i={ 2, 0, 1}
    :ma.ordering(*)==permut_v=1
    :multi_array_strides:strides()={ 12, 1, 3}
      :monotonically increasing={ 0, 0}
      :is_mono_tonic=0
    :expected_strides:{ 4, 8, 1}
      :monotonically increasing={ 1, 1}
      :is_mono_tonic=1
  :count=4
    :permut_v={ 2, 0, 1}
    :permut_i={ 1, 2, 0}
    :ma.ordering(*)==permut_v=1
    :multi_array_strides:strides()={ 4, 8, 1}
      :monotonically increasing={ 0, 0}
      :is_mono_tonic=0
    :expected_strides:{ 12, 1, 3}
      :monotonically increasing={ 1, 1}
      :is_mono_tonic=1

shows that the multi_array code fails this monotonic constrait when
the order is one of:

    :permut_v={ 1, 2, 0}
    :permut_v={ 2, 0, 1}

The code also shows a possible solution. This possible solution uses
the inverse permutation instead of the original permutation to
calculate the strides, as shown in the expected_strides function.
There's also a macro, NO_INVERT_PERMUT, which, if defined, has
expected_strides reproduce the multi_array strides, which may help
narrow down the source of the error in multi_array's stride
calculation.

The output is also attached. If macro INDENT_OUTPUT is defined, the
code requires:

http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/iostreams/filter/indent.hpp
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/iostreams/utility/indent_scoped_ostreambuf.hpp
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/utility/trace_scope.hpp
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/utility/indent_scope.hpp

If you don't want to download those, then the output will not be
nicely indented as shown in the attached output.

HTH.

-regards,
Larry





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net