Questions tagged [valarray]

C++ std::valarray is the class for representing and manipulating arrays of values. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access.

A valarray object is designed to hold an array of values and easily perform mathematical operations on them. It also allows special mechanisms to refer to subsets of elements in the arrays.

Most mathematical operations can be applied directly to valarray objects, including arithmetical and comparison operators, affecting all its elements.

The valarray specification allows for libraries to implement it with several efficiency optimizations, such as parallelization of certain operations, memory recycling or support for copy-on-reference / copy-on-write optimizations.

std::valarray and helper classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized similar to the effect of the keyword restrict in the C programming language.

Some C++ standard library implementations use expression templates to implement efficient operations on std::valarray (e.g. GNU libstdc++ and LLVM libc++).

Further details:

110 questions
0
votes
3 answers

Using std::valarray in numerical simulation

I posted a simple n-body class that I have written in C++ here in Code Review. There I was told to use std::valarray instead of plain std::array with the goal that I can rewrite some code that looks currently like this void…
Gilfoyle
  • 3,282
  • 3
  • 47
  • 83
0
votes
0 answers

Integrating `std::valarray` into data structure

I'm trying to incorporate the STL std::valarray into my program. I want to be able to change parts of my program from something like this for (unsigned int d = 0; d < DIM; ++d) { position[d] += dt*(velocity[d] + a*force_new[d]); …
Gilfoyle
  • 3,282
  • 3
  • 47
  • 83
0
votes
2 answers

Avoid initialization in c++ vector or valarray

In my project I've to copy a lot of numerical data in an std::valarray (or std::vector) from a CUDA (GPU) device (from the memory of the video-card to std::valarray). So I need to resize these data-structures as faster as possible but when I call…
Giggi
  • 681
  • 2
  • 9
  • 17
0
votes
1 answer

Wrong value from valarray after initialization

I'm trying to use std::valarray setting some initial values. Printing the array values, I get something different from what I expect. I'm on Windows (10) with CodeBlocks (GCC 4.9.2, C++11 build option). Here is the code: #include…
Sergio
  • 891
  • 9
  • 27
0
votes
1 answer

How an access an element within a valarray contained in a c array

I have a c array which contains valarrays as shown in the following code snipper, #include #include #include using namespace std; typedef uint uint32_t; typedef std::valarray uivector; int main() { …
Naveen
  • 458
  • 1
  • 10
  • 29
0
votes
0 answers

Valarray in c++ don't want to return element

Need help with valarray. Here is my code: #include #include typedef std::complex Complex; typedef std::valarray CArray; //some code CArray *abc = new CArray(10); Complex mem = abc[5]; //Error here It…
user2090826
  • 145
  • 1
  • 2
  • 9
0
votes
0 answers

std::begin for valarray on XCode 4 + 10.5 SDK

I have to build a soft with XCode 4 + Base SDK 10.5 for legacy support. It seems that I cannot turn on C++11 as detailed here (i.e. by setting "C++ Language Dialect" to "C++11" and "C++ Standard Library" to "libc++"), because when I do it, I…
Basj
  • 41,386
  • 99
  • 383
  • 673
0
votes
3 answers

The highest element (highest real part ) in Valarray of complex numbers in C++

How can I print out the highest element of Valarray of complex numbers in C++ ? I have tried with this code but it is returning error messages #include // std::cout #include #include // std::valarray typedef…
Serge
  • 3
  • 5
0
votes
1 answer

Working with arrays of real numbers and complex numbers

I'm working with an array of complex numbers a and an array of real numbers b (as double). typedef std::complex Complex; std::valarray a(1024); std::valarray b(1024); std::valarray modulus = std::abs(a); //…
Basj
  • 41,386
  • 99
  • 383
  • 673
0
votes
1 answer

error: no matching function for call to ‘conj(CArray&)’

I am getting the error message : iterDelayEst.cpp:32:21: error: no matching function for call to ‘conj(CArray&)’ auto nf1= ((x*conj(x)) * (x2*conj(x2))) ^ iterDelayEst.cpp:32:21: note: candidates are: In file included from…
Serge
  • 3
  • 5
0
votes
1 answer

Element wise multiplication of two arrays in C/C++

I would like to perform Element wise multiplication of two arrays, both are of type complex but I am getting the following error message: serge@ubuntu:~/Downloads/OpenCV/opencv-2.4.9/build$ g++ -o myfft myfft.cpp -std=c++14 In file included from…
Serge
  • 3
  • 5
0
votes
0 answers

Why do std::valarray and std::vector have swapped names?

First of all, I am sorry for asking a rather subjective question, but maybe there is a quite simple answer to my question. In math when I have a vector, I can do operations on it, e.g. v_3 = v_1 + v_2. In c++ I can do the same with valarray. On the…
Arne
  • 7,921
  • 9
  • 48
  • 66
0
votes
0 answers

Why does std::valarray not have a constructor taking a pair of iterators?

Question comes from my off-the-top-of-my-head answer to this question (which I have deleted cause, well, std::valarray has no constructor taking a pair of iterators...). The question is: why?
rubenvb
  • 74,642
  • 33
  • 187
  • 332
0
votes
1 answer

Using unspecified std::_ARRAY in structs after VC++2005

I am migrating an old project up to be compiled in newer versions of Visual Studio. I am getting a compiler error C4430 while compiling an old struct: struct SHOP_ITEM_LIST { char title[50]; char description[200]; _ARRAY(SHOP_ITEM); // Another…
Vinz
  • 3,030
  • 4
  • 31
  • 52
0
votes
0 answers

How to solve *** glibc detected *** free(): invalid pointer:

I am using valarray class and I get the following error: *** glibc detected *** /pathaToMyProject/Debug/BoundaryElements: free(): invalid pointer: 0x0000000000608dd0 *** ======= Backtrace:…
Gabs
  • 292
  • 5
  • 23