I'll start off differently by showing what I know how to do:
valarray<float> va(100, 0.0f);
float* fp;
fp = &va[0];
some_c_function( fp, va.size() );
What I want to do though is quite the opposite:
float* fp;
valarray<float> va;
&va[0] = fp; // this doesn't work on many levels
What I am trying to show is that I want to construct a valarray, but
use some pointer (from shared memory for example) to initialize the
valarray. I want to overlay a valarray on a c-style array so I don't
suffer the penalty of copying all the data from the array like the
following constructor does:
float af1 [] = {0, 1, 2, 3};
valarray <float> vf1 (af1, 4);
Is this possible with just STL or do I need to dive in to some other
C++ numerics library? 3 2741
In article <11*********************@g47g2000cwa.googlegroups. com>,
"klucar" <kl****@gmail.com> wrote: I'll start off differently by showing what I know how to do:
valarray<float> va(100, 0.0f); float* fp; fp = &va[0]; some_c_function( fp, va.size() );
What I want to do though is quite the opposite:
float* fp; valarray<float> va;
&va[0] = fp; // this doesn't work on many levels
What I am trying to show is that I want to construct a valarray, but use some pointer (from shared memory for example) to initialize the valarray. I want to overlay a valarray on a c-style array so I don't suffer the penalty of copying all the data from the array like the following constructor does:
float af1 [] = {0, 1, 2, 3}; valarray <float> vf1 (af1, 4);
Is this possible with just STL or do I need to dive in to some other C++ numerics library?
int array[] = { 3, 6, 18, 3, 22 };
// initialize valarray by elements of an ordinary array
std::valarray<int> va3(array, sizeof (array)/sizeof (array[0]));
// initialize by the second to the fourth element
std::valarray<int> va4(array+1, 3);
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
In article <11*********************@g47g2000cwa.googlegroups. com>,
"klucar" <kl****@gmail.com> wrote: I'll start off differently by showing what I know how to do:
valarray<float> va(100, 0.0f); float* fp; fp = &va[0]; some_c_function( fp, va.size() );
What I want to do though is quite the opposite:
float* fp; valarray<float> va;
&va[0] = fp; // this doesn't work on many levels
What I am trying to show is that I want to construct a valarray, but use some pointer (from shared memory for example) to initialize the valarray. I want to overlay a valarray on a c-style array so I don't suffer the penalty of copying all the data from the array like the following constructor does:
float af1 [] = {0, 1, 2, 3}; valarray <float> vf1 (af1, 4);
Is this possible with just STL or do I need to dive in to some other C++ numerics library?
Sorry, my last post was premature. valarray holds its data by value just
like other containers.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
So is my only hope to get a pointer to a valarray object? It just
seems bad that C++ containers have to be in charge. I guess a memory
manager object would have to use valarrays to store data and then pass
out valarray pointers to C++ objects and C pointers to C functions
using &va[0]. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Brechbühler |
last post by:
The template std::valarray behaves pretty much like a mathematical
vector. Arithmetic operators apply elementwise. Now I'd like to extend
this to a user-defined type, e.g., complex.
...
|
by: Jim West |
last post by:
The GNU implementation of the valarray header (g++ version 3.3.2)
includes the comment:
// This complication is so to make valarray<valarray<T> > work
// even though it is not required by the...
|
by: Steven T. Hatton |
last post by:
Examine the following code before you compile and run it. What do you
expect to happen? Is what you expected consistent with the result of
running it?
#include <valarray>
#include <iostream>
...
|
by: Peter |
last post by:
Hi everybody,
I am unfortunately stuck with a probably very simple problem. I made a
class called Particle with a valarray (STL) as a class member.
The code for the class goes like this:
...
|
by: ES Kim |
last post by:
comp.std.c++ would be a better place for this question.
Forgive me, but I can't post anything on moderated newsgroups
for some reason.
valarray doesn't have iterators of its own, which makes...
|
by: ES Kim |
last post by:
Here's a code fragment from TC++PL, p679:
void f(valarray<double>& v)
{
size_t i = { 3, 2, 1, 0 };
valarray<size_t> index(i, 4);
valarray<double> vv = log(v);
}
Every compiler I tried...
|
by: Michael Hopkins |
last post by:
Hi all
I have a subclass of valarray<T> thus
template <typename T>
class uo_val : public std::valarray<T>
{
public:
uo_val ( ) : std::valarray<T>() {}
uo_val (const int sz ) :...
|
by: Oliver Block |
last post by:
I have a (9x9) valarray
std::valarray<int> va(81);
va = 0; // fil all elements with zeros
I am taking row slices like that:
std::slice_array<int> slr = va; // r = row; a
value between 1...
|
by: Dack |
last post by:
Hi,
I want to track memory leaks in my application (that is using <valarray>).
I used the following code:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
But then, when I...
|
by: Chris Forone |
last post by:
Hello group,
g++ (3.4.2, mingw):
float init = {1.f, 2.f, 3.f};
std::map<std::string, std::valarray<float mp;
mp = std::valarray(init, 3);
mp.size(); // should be 3, but IS 0!
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |