lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] overview of C++ expression template libraries


From: Greg Chicares
Subject: Re: [lmi] overview of C++ expression template libraries
Date: Thu, 18 Feb 2021 01:27:25 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 2/17/21 11:36 AM, Vadim Zeitlin wrote:
[...]
> On Thu, 11 Sep 2008 20:16:08 +0000 Greg Chicares <gchicares@sbcglobal.net> 
> wrote:
> 
> GC> On 2007-01-08 14:23Z, Vadim Zeitlin wrote:
> GC> > 
> GC> >  I don't see anything against PETE except that it doesn't seem clear
> GC> > whether it's actively maintained.
> GC> 
> GC> There's no recent maintenance activity AFAICT.
> 
>  This is still the case today and, I think, it's safe to say there will
> never be any. Yet, lmi still uses PETE and you've been extending its use
> recently -- which is the motivation for this post, of course, as I wonder
> if it could make sense to have another look at the ET libraries using
> modern C++ in case we can find something "better" than PETE.

Maybe, though I doubt it.

I did take an extremely quick glance at 'armadillo' and 'eigen' a few
days ago. My impression was that they're large and complex, which is
reasonable enough given how ambitious they are, and that therefore
perhaps we should rather "bear those ills we have than fly to others
that we know not of".

My ambitions are tiny by comparison, but mostly orthogonal to theirs.
I don't want tensors and all that. I just want to be able to write
simple operations on scalars and arrays in a simple, natural, and
(most of all) terse way, e.g.:

  scalar A, B;
  vector U, V, W;
  W = max(0.0, 1.0 + A * U / (B * V - 3.5));

I can glance at a terse expression (in my professional domain) and
see what it does, and (probably) say whether it's right. But endless
lines of std::transform would puzzle anyone's will, and lambdas with
ranged-for aren't much more transparent. Really, the least awful way
to do this without a library like PETE is to write in C as though it
were FORTRAN without matrices:

  for(int i = 0; i < length; ++i)
    {W[i] = max(0.0, 1.0 + A * U[i] / (B * V[i] - 3.5));}

Of course, there's std::valarray, which can handle this part:
  1.0 + A * U / (B * V - 3.5)
but can't do this, AFAICT:
  W = max(0.0, W)
because std::valarray::apply() applies only unary functions,
but max() is binary.

>  "Better" needs to be defined, of course, but I'm quite sure that we should
> be able to find something even easier to manage (regenerating PETE files is
> probably not too bad, although I've never done it myself, but there is just
> no reason to ever do any generation at all since C++ got variadic
> templates) and much faster (if only because PETE doesn't attempt to do any
> vectorization whatsoever, let alone use GPU for it, as some of the
> libraries now do).

I come to expression templates seeking expressiveness, though wanting
to avoid any serious speed penalty--yet not primarily seeking speed.
But better speed is nice to have, provided expressiveness is maximized.

>  It's probably not very urgent to replace it, but personally I think it
> might be worthwhile to do at least a "due diligence" verification and check
> that we can't easily a lot in performance by just switching to another
> library. Please let me know if you agree and think it would be worthwhile.

Um...sure, if you want to look into it. I do worry about trading PETE's
known limitations for the unknown problems of another library.

I'd be quickly convinced by a library that would let me replace this:

    std::reverse(chg_sa.begin(), chg_sa.end());
    std::partial_sum(chg_sa.begin(), chg_sa.end(), chg_sa.begin());
    std::reverse(chg_sa.begin(), chg_sa.end());

with the pellucid equivalent in Iverson notation:

    chg_sa←⌽+\⌽chg_sa

but I know that's a lot to ask.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]