Loading ...
Sorry, an error occurred while loading the content.

Re: [ublas-dev] Re: Suggested sparse case iteration algorithm

Expand Messages
  • Michael Stevens
    Hi gitarrenschlumpf, (not sure how to address you here!) ... I m glad this is efficient. In particular it is good there is a efficient solution which doesn t
    Message 1 of 6 , Feb 25, 2004
    • 0 Attachment
      Hi gitarrenschlumpf, (not sure how to address you here!)

      On Wednesday 25 February 2004 12:44, gitarrenschlumpf wrote:
      > Ok, this works great.

      I'm glad this is efficient. In particular it is good there is a efficient
      solution which doesn't change the uBLAS code too much.


      > The three-ifs-idea is good. You could tweak it
      > some more by removing the
      > difference_type compare = index1 - index2;
      > and comparing the indices directly instead, that is
      > if (index1 == index2)
      > and so on. I don't know why this is faster, but the compilers I
      > tested it with ( VC7.1/Intel8.0 ) refused to optimize the other case.
      Wow. I'm amazed by that, I kept it this way assuming it would be faster.
      Direct comparison seems better anyway as it avoids the range restriction
      imposed by conversion to difference_type.

      > My confidence in the abilities of compilers has diminished greatly
      > while looking at this problem.
      Compilers always seem to steadfastly refuse what seems obvious to me as a
      human!
      Actually I think the original code (which recomputes indexes) is fundementally
      not optimisable. I guess would be that possible side effects of the operators
      in the loop mean the compiler must recompute both indexes.

      Michael
      --
      ___________________________________
      Michael Stevens Systems Engineering

      34128 Kassel, Germany
      Phone/Fax: +49 561 5218038

      Navigation Systems, Estimation and
      Bayesian Filtering
      http://www.sf.net/Bayes++
      ___________________________________
    • Michael Stevens
      Hi again, ... Looks good. I was looking at exactly the same code myself as a candidate for optimisation. My suggestion is to move the same container comparison
      Message 2 of 6 , Feb 25, 2004
      • 0 Attachment
        Hi again,
        On Wednesday 25 February 2004 13:23, gitarrenschlumpf wrote:
        > And one more:
        > What about reverting the order of comparisons in the iterator ==
        > operators?
        >
        > Now it is:
        > vector_sparse.hpp line 1186
        >
        > BOOST_UBLAS_INLINE
        > bool operator == (const const_iterator &it) const {
        > return &(*this) () == &it () && it_ == it.it_;
        > }
        >
        > As far as I understand, this first checks if the two iterators to be
        > compared point to the same container. Then it compares the internal
        > pointer representation of the iterators.
        >
        > Reverting the order of comparisons makes the comparison faster:
        > return it_ == it.it_ && &(*this) () == &it ();
        >
        > Could this have any catastrophic side effects?

        Looks good. I was looking at exactly the same code myself as a candidate for
        optimisation.

        My suggestion is to move the same container comparison out of release builds
        completely so we would have.

        BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
        return it_ == it.it_;

        However the current code has this comment in it from Joerg
        // FIXME: won't work with vector of vectors.
        // BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic
        ());
        so I am not sure of the correct solution.

        I'm making the assumption that comparing iterators different containers is
        undefined. Therefore the only point of the container check is to catch
        program errors.

        Actually I think there is a fundamental issue we the way uBLAS iterators are
        required to store a containter reference. I will put that in a separate
        posting so I can change the subject line.

        Michael
        --
        ___________________________________
        Michael Stevens Systems Engineering

        Navigation Systems, Estimation and
        Bayesian Filtering
        http://www.sf.net/Bayes++
        ___________________________________
      Your message has been successfully submitted and would be delivered to recipients shortly.