473,770 Members | 4,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(w here 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(in put 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 1827
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(w here 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(in put 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
7079
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 clear(), in DOT.NET the capacity() is reduced to 0.
3
2805
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 Data
4
2406
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 >::iterator left, std::vector< myclass >::iterator right); x.hpp:153: error: `class std::vector<myclass, D>, std::alloca
9
8897
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; Any ideas why is tihs happening? The code is as follows: template <class T> struct StdVectorStorage { std::vector<T>* _storage;
8
5372
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 possible to "spoof" std::vector into implementing a "true" vector of bool rather than the specialisation? Say I do: typedef bool boolreally; std::vector<booleallybvec;
6
5652
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. char temp; std::vector<unsigned charmmessage; while (!done){
1
2399
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, i need to allocate the std::vector<std::vector<T> > member variable with new operator. How can i?
8
3621
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 class simple_vector<that is a hand-rolled substitute for array<>. With the latter I have code that tracks all allocations and destructions, so I can account for all the memory. The question is about std::vector<-- how can I track memory usage
3
5656
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 k = i+1;
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.