Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3668

Re: Understanding ValArray slices

From jacob navia <jacob@spamsink.net>
Newsgroups comp.lang.c++
Subject Re: Understanding ValArray slices
Date 2011-04-14 14:48 +0200
Organization lccwin
Message-ID <io6qf5$ncl$1@speranza.aioe.org> (permalink)
References <io55g6$66o$1@speranza.aioe.org> <90mk5cFeeiU8@mid.individual.net> <io57nd$b6s$1@speranza.aioe.org> <0cfb9f27-e357-4df0-8524-c6f5da967d44@k3g2000prl.googlegroups.com>

Show all headers | View raw


Le 14/04/11 10:59, gwowen a écrit :
> On Apr 13, 11:22 pm, jacob navia<ja...@spamsink.net>  wrote:
>
>> Thanks, I see now how this works. The problem is that
>> it would be more efficient to pass directly the
>> stride specs instead of allocating the indices array. I will
>> see how I implement this.
>
> I think Ian and you are talking at slight cross-purposes.
>
> slices do not themselves, need to store an array of indices, but
> rather just the start,end and stride passed at construction time. All
> the heavy lifting can be done in the overloaded
> valarray::operator[slice], and no intermediate array-of-indices need
> creating.
>
> In inefficient semi-pseudo code
>
> valarray<T>  valarray::operator[] (slice ...) {
>    valarray<T>  retval(size.size());
>    size_t retidx = 0;
>    for(size_t idx = slice.start(); idx<  slice.end(); idx +=
> slice.stride()){
>      retval[retidx] = *this[idx];
>      retidx += 1;
>    }
> }
>
> Of course, one could implement them as generating an array of indices
> at construction time, but I doubt that implementations do this. The
> fact that operator[] is defined as operating on slice, rather than
> const slice&  suggests that in the intended implementation slices are
> easily copyable.

OK, this means that in my implementation

MultiplyWith(ValArray *, ValArray*)

would multiply two arrays of the same length

MutiplyWithScalar(ValArray *array,ElementType m)

would multiply an array by a single number and

MultiplyWithSlice(ValArray *array, size_t start, size_t size, size_t 
increment, ValArray *multiplicand)

would multiply using the described slice. The multiplicand should have 
exactly "size" elements (i.e. as much elements as the slice describes)

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-13 23:44 +0200
  Re: Understanding ValArray slices Ian Collins <ian-news@hotmail.com> - 2011-04-14 09:50 +1200
    Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 00:22 +0200
      Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 01:59 -0700
        Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 14:48 +0200
          Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 09:53 -0700
            Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 22:50 +0200
              Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-14 22:51 +0200
              Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-14 22:47 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-15 22:19 +0200
                Re: Understanding ValArray slices Ian Collins <ian-news@hotmail.com> - 2011-04-16 08:21 +1200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 14:13 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-15 23:24 +0200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 23:05 -0700
                Re: Understanding ValArray slices jacob navia <jacob@spamsink.net> - 2011-04-16 12:00 +0200
                Re: Understanding ValArray slices gwowen <gwowen@gmail.com> - 2011-04-15 14:23 -0700

csiph-web