473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Applying a linear transform to a std::vector<T>

Hi there,

I am dealing with the following problem:

I need to convert a std::vector<T(where T can be any interget
type: char, short, ushort) by applying a linear transform (a,b),
following;

output[i] = a*input[i] + b (a & b are floating point type)

Since memory space is important, I am trying to divide the problem
in subcases. Basically

1. If a or b is float then the output vector need to be declared as
vector<float(input vector is at most 16bits integer type)

2. Is a & b are integer I need to compute the min/max of the input
scalar type, apply the transform and check the output interval to find
which C type is the best match.

Since this look like boilerplate code, I was wondering if there was
anything I could reuse (other than just numeric_limits to find the min
max). Even just the interval calculation is tricky, although in my
case I can just cast eveyrthing to double since I am dealing with at
most 32bits calculation.

thanks for comments,
-Mathieu
Jun 27 '08 #1
1 1780
On Fri, 25 Apr 2008 15:52:01 +0200, mathieu <ma***************@gmail.com
wrote:
Hi there,

I am dealing with the following problem:

I need to convert a std::vector<T(where T can be any interget
type: char, short, ushort) by applying a linear transform (a,b),
following;

output[i] = a*input[i] + b (a & b are floating point type)

Since memory space is important, I am trying to divide the problem
in subcases. Basically

1. If a or b is float then the output vector need to be declared as
vector<float(input vector is at most 16bits integer type)

2. Is a & b are integer I need to compute the min/max of the input
scalar type, apply the transform and check the output interval to find
which C type is the best match.

Since this look like boilerplate code, I was wondering if there was
anything I could reuse (other than just numeric_limits to find the min
max). Even just the interval calculation is tricky, although in my
case I can just cast eveyrthing to double since I am dealing with at
most 32bits calculation.

thanks for comments,
-Mathieu

May be you should use std::valarray.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Stefan Höhne | last post by:
Hi, as I recon, std::vector::clear()'s semantics changed from MS VC++ 6.0 to MS' DOT.NET - compiler. In the 6.0 version the capacity() of the vector did not change with the call to...
3
by: Chris | last post by:
Hi, I'm playing/developing a simple p2p file sharing client for an existing protocol. A 2 second description of the protocol is Message Length = int, 4 bytes Message Code = int, 4 bytes...
4
by: John | last post by:
I have a function declaration that gives an error while compiling. Can anyone help me figure this one out? inline void create(const std::vector< myclass >& plist, std::vector< myclass...
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
8
by: Lionel B | last post by:
On my platform I find that the std::vector<boolspecialisation incurs a significant performance hit in some circumstances (when compared, say, to std::vector<intprogrammed analagously). Is it...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
1
by: sergio311 | last post by:
Hi all, I'm new of c++ and i'm writing a class that create a matrix of data (of T type, it's a template class). The member variable m_data must stores the matrix's data and i prefer use heap so,...
8
by: jacek.dziedzic | last post by:
Hi! I need to be able to track memory usage in a medium-sized application I'm developing. The only significant (memory-wise) non- local objects are of two types -- std::vector<and of a custom...
3
by: Rune Allnor | last post by:
Hi folks. I have a function that takes an element in a vector as argument. The naive interface goes as float computeSomething(const std::vector<float>& v, size_t i) { size_t j = i-1; size_t...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.