📄 valarray.htm
字号:
<html>
<head>
<title> The valarray Class</title>
</head>
<body bgcolor="#FFFFFF">
<a name="here"></a>
<img src="valarban.gif">
<pre>
<font size=5>Class Name</font> valarray
<font size=5>Header File</font> <valarray>
<font size=5>Classification</font> ADT (Format Class)
</pre>
<a href="valarray.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>
<p>
None
</p>
<h1>Methods</h1>
<pre>
<a href="valarray.htm#apply1">valarray<T> apply(T func(T)) const</a><br>
<a href="valarray.htm#apply2">valarray<T> apply(T func(const T&)) const</a><br>
<a href="valarray.htm#cshift">valarray<T> cshift(int Num) const</a><br>
<a href="valarray.htm#max">T max() const</a><br>
<a href="valarray.htm#min">T min() const</a><br>
<a href="valarray.htm#resize">void resize(size_t Sz, T Value = T()</a><br>
<a href="valarray.htm#shift">valarray<T> shift (int) const</a><br>
<a href="valarray.htm#size">size_t size() const</a><br>
<a href="valarray.htm#sum">T sum() const</a><br>
<a href="valarray.htm#valarray1">valarray()</a><br>
<a href="valarray.htm#valarray2">explicit valarray(size_t Sz)</a><br>
<a href="valarray.htm#valarray3">valarray(const T &X, size_t Sz)</a><br>
<a href="valarray.htm#valarray4">valarray(const T *X, size_t Sz)</a><br>
<a href="valarray.htm#valarray5">valarray(const valarray &X)</a><br>
<a href="valarray.htm#valarray6">valarray(const slice_array<T> &X)</a><br>
<a href="valarray.htm#valarray7">valarray(const gslice_array<T> &X)</a><br>
<a href="valarray.htm#valarray8">valarray(const mask_array<T> &X)</a><br>
<a href="valarray.htm#valarray9">valarray(const indirect_array<T> &X)</a><br>
<a href="valarray.htm#valarray10">~valarray()</a><br>
</pre>
<a href="valarray.htm#tablefunction"><h1>Operators</h1></a>
<a href="valarray.htm#tablefunction"><h1>Functions</h1></a>
<a href="valarray.htm#example"><h2>Example</h2></a>
<hr>
<h2><a name="desc"> Class Description</a></h2>
<p>
The valarray class is single dimension array that is optimized specifically
for mathematical operations. The valarray class is designed to provide vector operations on
numeric values. The valarray class defines vector addition, vector substraction.
Scalar vector multiplication, and a host of transendental mathematical functions. The standard
vector class does not provide these mathematical operations.
</p>
<hr>
<pre>
<a name="apply1">Method apply()</a>
Access Public
Classification Accessor
Syntax valarray<T> apply(T func(T)) const
Parameters <i>func</i> is the name of a function that takes a single argument
T is the type of elements that are contained in the
valarray.
Return The method returns a copy of the valarray that has been modified
by <i>func</i>.
</pre>
<h3>Description</h3>
<p>
This apply() method applies the function <i>func</i> to each element of the valarray. It returns
a new valarray with the new values that were generated by <i>func</i>.
</p>
<hr>
<pre>
<a name="apply2">Method apply()</a>
Access Public
Classification Accessor
Syntax apply(T func(const T&)) const
Parameters <i>func</i> is the name of a function that takes a single argument
T is the type of elements that are contained in the
valarray.
Return The method returns a copy of the valarray that has been modified
by <i>func</i>.
</pre>
<h3>Description</h3>
<p>
This apply() method applies the function <i>func</i> to each element of the valarray. It returns
a new valarray with the new values that were generated by <i>func</i>.
</p>
<hr>
<pre>
<a name="cshift">Method cshift()</a>
Access Public
Classification Accessor
Syntax cshift(int Num) const
Parameters Num is the number of positions to the left to shift the valarray.
Return This method returns a copy of the valarray with each element shifted
Num positions.
</pre>
<h3>Description</h3>
<p>
The cshift() method returns a valarray that has been left shifted Num positions. If Num is
negative Then the shift starts with the element[abs(Num)] at stores that element at position
Zero and performs a circular shift of the remaining elements accordingly.
</p>
<hr>
<pre>
<a name="max">Method max()</a>
Access Public
Classification Accessor
Syntax T max() const
Parameters None
Return The largest element in the valarray object.
</pre>
<h3>Description</h3>
<p>
The max() method returns the largest element in the valarray object.
</p>
<hr>
<pre>
<a name="min">Method min()</a>
Access Public
Classification Accessor
Syntax T min() const
Parameters None
Return The smallest element in the valarray object.
</pre>
<h3>Description</h3>
<p>
The min() method returns the smallest element in the valarray object.
</p>
<hr>
<pre>
<a name="resize">Method resize()</a>
Access Public
Classification Accessor
Syntax void resize(size_t Sz, T Value = T()
Parameters Sz is the new size of the valarray. Value will be used to initialize
each element in the valarray.
Return None
</pre>
<h3>Description</h3>
<p>
The resize() method resizes the valarray so that it has Sz elements. Value is assigned
to each element in the valarray. All pointers and references to elements in the valarray
prior to the resize() call are invalid.
</p>
<hr>
<pre>
<a name="shift">Method shift()</a>
Access Public
Classification Accessor
Syntax valarray<T> shift (int Num) const
Parameters Num is the number of positions to the left to shift the valarray.
Return This method returns a copy of the valarray with each element shifted
Num positions.
</pre>
<h3>Description</h3>
<p>
The shift() method returns a valarray that has been left shifted Num positions. If Num is
negative Then the shift starts with the element[abs(Num)] at stores that element at position
Zero and shifts of the remaining elements accordingly.
</p>
<hr>
<pre>
<a name="size">Method size()</a>
Access Public
Classification Accessor
Syntax valarray<T> size () const
Parameters None
Return This method returns the number of elements in the valarray.
</pre>
<h3>Description</h3>
<p>
The size() method returns the number of elements in the valarray.
</p>
<hr>
<pre>
<a name="sum">Method sum()</a>
Access Public
Classification Accessor
Syntax T sum () const
Parameters None
Return This method returns the sum of the elements in the valarray.
</pre>
<h3>Description</h3>
<p>
The sum() method returns the sum of the of elements in the valarray.
</p>
<hr>
<pre>
<a name="valarray1">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an empty valarray.
</p>
<hr>
<pre>
<a name="valarray2">Method valarray()</a>
Access Public
Classification Modifier
Syntax explicit valarray(size_t Sz)
Parameters Sz is the number of elements that the valarray will contain.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an valarray that has Sz number of elements.
</p>
<hr>
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an empty valarray.
</p>
<hr>
<pre>
<a name="valarray3">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const T &X, size_t Sz)
Parameters Sz is the number of elements that the valarray will contain.
The elements in the valarray will be initialized with X.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an valarray that has Sz number of elements and
that are initialized with the value of X.
</p>
<hr>
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an empty valarray.
</p>
<hr>
<pre>
<a name="valarray4">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const T *X, size_t Sz)
Parameters Sz is the number of elements that the valarray will contain.
The elements in the valarray will be initialized with X.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an valarray that has Sz number of elements and
that are initialized with the first Sz values that X points to. X should point to
at least Sz elements. If X points to less than Sz elements the results of this
construction are unpredictable.
</p>
<hr>
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs an empty valarray.
</p>
<hr>
<pre>
<a name="valarray5">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const valarray &X)
Parameters X is an vector used to construct this valarray.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() method constructs a valarray from the vector X. The valarray will
contain copies of the elements in X.
</p>
<hr>
<pre>
<a name="valarray6">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const slice_array<T> &X)
Parameters X is a slice_array used to construct this valarray.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() is constructed using the elements of the slice_array X.
</p>
<hr>
<pre>
<a name="valarray7">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const gslice_array<T> &X)
Parameters X is a gslice_array used to construct this valarray.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() is constructed using the elements of the gslice_array X.
</p>
<hr>
<pre>
<a name="valarray8">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const mask_array<T> &X)
Parameters X is a mask_array used to construct this valarray.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() is constructed using the elements of the mask_array X.
</p>
<hr>
<pre>
<a name="valarray9">Method valarray()</a>
Access Public
Classification Modifier
Syntax valarray(const indirect_array<T> &X)
Parameters X is a indirect_array used to construct this valarray.
Return None
</pre>
<h3>Description</h3>
<p>
This valarray() is constructed using the elements of the indirect_array X.
</p>
<hr>
<pre>
<a name="valarray10">Method valarray()</a>
Access Public
Classification Modifier
Syntax ~valarray()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
This ~valarray() destructs an object of type valarray.
</p>
<hr>
<a name="tablefunction"><h1>valarray: Arithmetic Operations Description</h2></a>
<pre>
___________________________________________________________________________________
Computed Assignment
+= addition
-= subtraction
%= modulus
*= multiplication
/= division
Global Operators
sin() sine
sinh() hyperbolic sine
asin() arcsine
cos() cosine
cosh() hyperbolic cosine
acos() arccosine
tan() tangent
tanh() hyperbolic tangent
atan() arctangent
atan2() arctangent of x[i] / y[i]
pow() raised to a power
exp() base e exponential
log() base e logarithm
log10() base 10 logarithm
abs() magnitude
sqrt() square root
___________________________________________________________________________________
<i><font color =RED>NOTE: There is a global non-assignment counterpart for all bolded member operators.</font></i>
</pre>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>
1 #include <valarray>
2 #include <iostream>
3
4
5 using namespace std;
6
7
8 double triple(double X)
9 {
10 return(X * X * X);
11 }
12
13 void main(void)
14 {
15
16 valarray<double> X(5);
17 int N;
18 for(N = 0; N < 5;N++)
19 {
20 X[N] = N+5;
21 }
22 valarray<double> Y = abs(sin(X));
23 valarray<double> Z = abs(cos(Y));
24 Z = Z * Y;
25 valarray<double> Alpha = Z.apply(triple);
26 for(N = 0; N < Alpha.size();N++)
27 {
28 cout << X[N] << '\t' << Y[N] << '\t' << Z[N] << '\t'<< Alpha[N] << endl;
29 }
30 }
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -