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
1
vote
1 answer

What are the differences of valarray in gcc and msvc (or Linux and Windows)

I experience different behavior of valarray in Windows and Linux. Does anyone know about this or know where to look at? It is obvious, the one version working on both system is correct C++, but why does the other works in Windows? Are there more…
this.myself
  • 2,101
  • 2
  • 22
  • 36
1
vote
1 answer

Ambiguity in explicit initialization of a valarray to zero?

std::valarray< double > myArray(3) produces a valarray of length 3, initialized to zero. std::valarray< double > myArray(1,3) produces a valarray of length 3, initialized to one. std::valarray< double > myArray(0,3) produces error: call to…
sudo make install
  • 5,629
  • 3
  • 36
  • 48
1
vote
1 answer

C++ Boost valarray

I am looking for a convenient and optimized way to compare 2 valarrays for equality. I've seen that Boost somewhat supports that: In /boost/accumulators/numeric/functional/valarray.hpp -- // for "promoting" a std::valarray to a bool, useful…
1
vote
1 answer

Multidimensional std::valarray and inequalities

The following piece of code does not compile: #include int main() { std::valarray> a; std::valarray> b; //std::valarray> c; std::valarray c; c = (a == b); …
1
vote
0 answers

Default valarray passing doesn't work

In C++, I have two functions: do_work(args, std::valarray arr=std::valarray(0.0, 1)) { very_complicated_things } wrapper(args, std::valarray arr=std::valarray(0.0, 1)) { do_work(args, arr); } Calling…
ideasrule
  • 210
  • 1
  • 7
1
vote
1 answer

Concatenating valarrays

I have some data stored in a std::vector. I used this to create a std::valarray from my std::vector. std:valarray corpX(corps_tmp[i].data(), corps_tmp[i].size()); With this new std:valarray I…
user1434698
0
votes
1 answer

-use-intel-optimized-headers not recognized ("argument unused during compilation") for compilation, only for linking?

Trying to follow this (Intel64/Linux): https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/libraries/intel-c-class-libraries/intel-s-valarray-implementation.html But…
c1mth0g
  • 1
  • 1
0
votes
2 answers

How to pass a vector or a valarray as an argument to a C++ template function

I feel this is probably an elementary question, but I can't find a simple answer after quite a bit of searching, so I thought I'd ask. I have a function that is meant to return the nth percentile value in a container, but for legacy reasons the…
Bill Heitler
  • 187
  • 3
  • 13
0
votes
2 answers

error: declaration of ‘operator*’ as non-function

I have some problems with bound template friend functions of template classes. I've refered the page which has the similar and simple problem as me: vect.hpp:13:33: error: declaration of ‘operator<<’ as non-function , but I still confused, the…
On_My_Way
  • 11
  • 5
0
votes
0 answers

Use c++ gslice to hide specific elements in valarray

I want to hide multiple elements in a valarray which has consecutive integers starting from 0. For example, from {0, 1, 2, 3, 4, 5} to {0, 2, 3, 5}. I have found that I can use indirect array to specify elements indices with valarray.…
0
votes
3 answers

Operator += applied to std::valarray

Here is the example: #include #include #include int main() { std::valarray vs(2); // vs[0] += "hello"; // works // vs[1] += "hello"; // works vs += "hello"; //…
bou
  • 147
  • 1
  • 8
0
votes
1 answer

Valarray slice array no match for 'operator*'

I'm trying to do multidimensional dot product with two valarray, i.e. return a valarray such that each element is the dot product on two rows of the input valarrays. I use slices to divide by array into rows. Checking the documentation, it states…
NukeyFox
  • 11
  • 1
  • 1
0
votes
2 answers

How to use std::valarray in if statement without redundant computation?

I have the following code with float, for example: std::vector v = {0.f, 1.f, 2.f}; for(size_t i = 0; i < v.size(); ++i) if(v[i] != 0) // An optimization for `v[i] != 0`. v[i] = v[i] * v[i] * v[i]; // Time-consuming…
chaosink
  • 1,329
  • 13
  • 27
0
votes
0 answers

Are Valarrays a specialized Templates?

Can we be sure that valarray is a specialized class template ? and that's why it doesn't let implicite conversion happen ? std::valarray values={1.0,2.0}; for(int it: values ){ std::cout<
rekkalmd
  • 171
  • 1
  • 12
0
votes
1 answer

Processing Valarrays

Thanks for the attention in advance. So i'm processing a valarray from STL, i'm curious about capturing values using a Closure. Why i can't pass values by reference. Taking as instance the following code : #include #include…
rekkalmd
  • 171
  • 1
  • 12