chaining ouput iterator to input iterator

Hi,
I have a function that transforms a serie of numbers into another serie:
template

On Sat, Jul 7, 2012 at 6:55 PM, MM
Hi,
I have a function that transforms a serie of numbers into another serie:
template
void transform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
Maybe use boost::transform_iterator? - Jeff

I have a function that transforms a serie of numbers into another serie:
template
void transform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
In this particular case, you can use boost::transform_iterator rather than std::transform, as Jeff pointed out. However, this does not resolve the problem in general, which is how to treat the sequence of values a function writes to an output iterator as a range (or pair of iterators) input to another function (without accumulating the elements in a container, of course). This seems like a textbook use case for coroutines. I wonder whether a solution using Boost.Context would impose sufficiently little overhead to provide a general solution to this problem. Regards, Nate

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nathan Ridge Sent: 08 July 2012 06:18 To: Boost Mailing List Subject: Re: [Boost-users] chaining ouput iterator to input iterator
I have a function that transforms a serie of numbers into another serie:
template
void mytransform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
In this particular case, you can use boost::transform_iterator rather than std::transform, as Jeff pointed out.
However, this does not resolve the problem in general, which is how to treat the sequence of values a function writes to an output iterator as a range (or pair of iterators) input to another function (without accumulating the elements in a container, of course).
I'm not too sure how to call the transform_iterator in this case. I have these 2 functions that I need to provide separately because they are used separately. And I also need a 3rd function, called double stddev_of_transformed(InputIterator begin, InputIterator end) { return mytransform(begin, end, boost::transform_iterator( ... ) ); // ???? }
This seems like a textbook use case for coroutines. I wonder whether a solution using Boost.Context would impose sufficiently little overhead to provide a general solution to this problem.
I'll take a look at this too, thanks, MM

I have a function that transforms a serie of numbers into another serie:
template
void mytransform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
In this particular case, you can use boost::transform_iterator rather than std::transform, as Jeff pointed out.
However, this does not resolve the problem in general, which is how to treat the sequence of values a function writes to an output iterator as a range (or pair of iterators) input to another function (without accumulating the elements in a container, of course).
I'm not too sure how to call the transform_iterator in this case.
I have these 2 functions that I need to provide separately because they are used separately. And I also need a 3rd function, called
double stddev_of_transformed(InputIterator begin, InputIterator end) { return mytransform(begin, end, boost::transform_iterator( ... ) ); // ???? }
Sorry, I thought by transform() you meant std::transform(). If you have your own mytransform() function (and you can't replace it with a call to std::transform()), then boost::transform_iterator may not be applicable. In that case, your options are 1) accumulate the outputs in a container in between the two calls, or 2) use a Boost.Context-based solution as I mentioned before. Regards, Nate

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nathan Ridge Sent: 08 July 2012 15:33 To: Boost Mailing List Subject: Re: [Boost-users] chaining ouput iterator to input iterator
I have a function that transforms a serie of numbers into another serie:
template
void mytransform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
In this particular case, you can use boost::transform_iterator rather than std::transform, as Jeff pointed out.
However, this does not resolve the problem in general, which is how to treat the sequence of values a function writes to an output iterator as a range (or pair of iterators) input to another function (without accumulating the elements in a container, of course).
I'm not too sure how to call the transform_iterator in this case.
I have these 2 functions that I need to provide separately because they are used separately. And I also need a 3rd function, called
double stddev_of_transformed(InputIterator begin, InputIterator end) { return mytransform(begin, end, boost::transform_iterator( ... ) ); // ???? }
Sorry, I thought by transform() you meant std::transform(). If you have your own mytransform() function (and you can't replace it with a call to std::transform()), then boost::transform_iterator may not be applicable. In that case, your options are 1) accumulate the outputs in a container in between the two calls, or 2) use a Boost.Context-based solution as I mentioned before.
Regards, Nate
Boost.Coroutine? Is that in boost vault? MM

On Sun, Jul 8, 2012 at 5:33 PM, MM
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nathan Ridge Sent: 08 July 2012 15:33 To: Boost Mailing List Subject: Re: [Boost-users] chaining ouput iterator to input iterator
your options are ... 2) use a Boost.Context-based solution as I mentioned before.
Boost.Coroutine? Is that in boost vault?
Heh. There is a Boost.Coroutine in the Vault, but you're better advised to use the new Boost.Coroutine just coming up for review this week (I believe). IMO, either would be better than directly using Boost.Context. Context is a low-level library intended for use by application-level libraries such as Coroutine. It's just that any application-level library based on user-space context switching necessarily deals with the same platform-dependent issues; Oliver Kowalke has very usefully abstracted those out as Context. Now Oliver has presented us with a reimplementation of the original Boost.Coroutine prototype (in the Vault), based on his Context library. If you're willing, it would be very timely to add your opinion to the review about to be announced.

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nat Linden Sent: 09 July 2012 13:24 To: boost-users@lists.boost.org Subject: Re: [Boost-users] chaining ouput iterator to input iterator
On Sun, Jul 8, 2012 at 5:33 PM, MM
wrote: -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nathan Ridge Sent: 08 July 2012 15:33 To: Boost Mailing List Subject: Re: [Boost-users] chaining ouput iterator to input iterator
your options are ... 2) use a Boost.Context-based solution as I mentioned before.
Boost.Coroutine? Is that in boost vault?
Heh. There is a Boost.Coroutine in the Vault, but you're better advised to use the new Boost.Coroutine just coming up for review this week (I believe).
IMO, either would be better than directly using Boost.Context. Context is a low-level library intended for use by application-level libraries such as Coroutine. It's just that any application-level library based on user-space context switching necessarily deals with the same platform-dependent issues; Oliver Kowalke has very usefully abstracted those out as Context.
Now Oliver has presented us with a reimplementation of the original Boost.Coroutine prototype (in the Vault), based on his Context library. If you're willing, it would be very timely to add your opinion to the review about to be announced.
Presumably the doc is in the boost vault. I'll take a look Frankly, the coroutine seems very unnatural as I am accustomed to the separation of concerns, and the mechanism of of function call, and so on... I was also wondering if some lazy function from phoenix could help with this, or really a boost::transform_iterator could do it somehow MM

your options are ... 2) use a Boost.Context-based solution as I mentioned before.
Boost.Coroutine? Is that in boost vault?
[snip]
Frankly, the coroutine seems very unnatural as I am accustomed to the separation of concerns, and the mechanism of of function call, and so on...
I was also wondering if some lazy function from phoenix could help with this, or really a boost::transform_iterator could do it somehow
Is it possible for you to change the implementation of my_transform? If so, could you post its implementation (or an outline of it)? We may be able to suggest a way to express the same thing with boost::transform_iterator instead. Regards, Nate

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nathan Ridge Sent: 09 July 2012 19:20 To: Boost Mailing List Subject: Re: [Boost-users] chaining ouput iterator to input iterator
your options are ... 2) use a Boost.Context-based solution as I mentioned before.
Boost.Coroutine? Is that in boost vault?
[snip]
Frankly, the coroutine seems very unnatural as I am accustomed to the separation of concerns, and the mechanism of of function call, and so on...
I was also wondering if some lazy function from phoenix could help with this, or really a boost::transform_iterator could do it somehow
Is it possible for you to change the implementation of my_transform? If so, could you post its implementation (or an outline of it)? We may be able to suggest a way to express the same thing with boost::transform_iterator instead.
Regards, Nate
I wouldn't be able to change the signature...
template

your options are ... 2) use a Boost.Context-based solution as I mentioned before.
Boost.Coroutine? Is that in boost vault?
Heh. There is a Boost.Coroutine in the Vault, but you're better advised to use the new Boost.Coroutine just coming up for review this week (I believe).
IMO, either would be better than directly using Boost.Context. Context is a low-level library intended for use by application-level libraries such as Coroutine. It's just that any application-level library based on user-space context switching necessarily deals with the same platform-dependent issues; Oliver Kowalke has very usefully abstracted those out as Context.
Now Oliver has presented us with a reimplementation of the original Boost.Coroutine prototype (in the Vault), based on his Context library. If you're willing, it would be very timely to add your opinion to the review about to be announced.
You're right, I was thinking of an earlier version of Boost.Context that had a high-level interface with an object of type 'context' which could be suspended/resumed etc. It seems this interface is not included in the Boost.Context that's currently in trunk and instead the functionality was moved to Boost.Coroutine? I totally missed that... Regards, Nate
participants (4)
-
Jeffrey Lee Hellrung, Jr.
-
MM
-
Nat Linden
-
Nathan Ridge