259 lines
11 KiB
HTML
259 lines
11 KiB
HTML
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed
|
|
with this work for additional information regarding copyright
|
|
ownership. The ASF licenses this file to you under the Apache
|
|
License, Version 2.0 (the License); you may not use this file
|
|
except in compliance with the License. You may obtain a copy of
|
|
the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
implied. See the License for the specific language governing
|
|
permissions and limitations under the License.
|
|
|
|
Copyright 1999-2007 Rogue Wave Software, Inc.
|
|
-->
|
|
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>gslice_array</TITLE>
|
|
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
|
|
<BODY BGCOLOR=#FFFFFF>
|
|
<A HREF="gslice.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="has-facet.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV>
|
|
<H2>gslice_array</H2>
|
|
<P><B>Library:</B> <A HREF="2-10.html">Numerics</A></P>
|
|
|
|
<PRE><HR><B><I>Does not inherit</I></B><HR></PRE>
|
|
|
|
<UL>
|
|
<LI><A HREF="#sec1">Local Index</A></LI>
|
|
<LI><A HREF="#sec2">Summary</A></LI>
|
|
<LI><A HREF="#sec3">Synopsis</A></LI>
|
|
<LI><A HREF="#sec4">Description</A></LI>
|
|
<LI><A HREF="#sec5">Interface</A></LI>
|
|
<LI><A HREF="#sec6">Constructors</A></LI>
|
|
<LI><A HREF="#sec7">Assignment Operators</A></LI>
|
|
<LI><A HREF="#sec8">Computed Assignment Operators</A></LI>
|
|
<LI><A HREF="#sec9">Example</A></LI>
|
|
<LI><A HREF="#sec10">See Also</A></LI>
|
|
<LI><A HREF="#sec11">Standards Conformance</A></LI>
|
|
</UL>
|
|
<A NAME="sec1"><H3>Local Index</H3></A>
|
|
<H4>Members</H4>
|
|
<UL><TABLE CELLPADDING=3>
|
|
<TR><TD VALIGN=top>
|
|
<A HREF="#idx653">gslice_array()</A><BR>
|
|
<A HREF="#idx657">operator%=()</A><BR>
|
|
<A HREF="#idx657">operator&=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx657">operator>>=()</A><BR>
|
|
<A HREF="#idx657">operator<<=()</A><BR>
|
|
<A HREF="#idx657">operator*=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx657">operator+=()</A><BR>
|
|
<A HREF="#idx657">operator-=()</A><BR>
|
|
<A HREF="#idx657">operator/=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx654">operator=()</A><BR>
|
|
<A HREF="#idx657">operator^=()</A><BR>
|
|
<A HREF="#idx657">operator|=()</A><BR>
|
|
</TD></TR>
|
|
</TABLE></UL>
|
|
|
|
<A NAME="sec2"><H3>Summary</H3></A>
|
|
<P>A numeric array class used to represent a BLAS-like slice from a <B><I><A HREF="valarray.html">valarray</A></I></B></P>
|
|
<A NAME="sec3"><H3>Synopsis</H3></A>
|
|
|
|
<PRE>#include <valarray>
|
|
|
|
namespace std {
|
|
template <class T>
|
|
class gslice_array;
|
|
}
|
|
</PRE>
|
|
<A NAME="sec4"><H3>Description</H3></A>
|
|
<P><B><I>gslice_array</I></B> creates a <B><I><A HREF="gslice.html">gslice</A></I></B> view into a <B><I><A HREF="valarray.html">valarray</A></I></B>. A <B><I>gslice_array</I></B> can only be produced by applying the <B><I>gslice</I></B> subscript operator to a <B><I>valarray</I></B>. The elements in a <B><I>gslice_array</I></B> are references to selected elements in the <B><I>valarray</I></B> (so changing an element in the <B><I>gslice_array</I></B> really changes the corresponding element in the <B><I>valarray</I></B>). A <B><I>gslice_array</I></B> does not itself hold any distinct elements. The template cannot be instantiated directly since all its constructors are private. However, you can copy a <B><I>gslice_array</I></B> to a <B><I>valarray</I></B> using either the <B><I>valarray</I></B> copy constructor or the assignment operator. Reference semantics are lost at that point. </P>
|
|
<A NAME="sec5"><H3>Interface</H3></A>
|
|
|
|
<UL><PRE>namespace std{
|
|
|
|
template <class T> class gslice_array {
|
|
public:
|
|
|
|
// types
|
|
typedef T value_type;
|
|
|
|
// destructor
|
|
~gslice_array();
|
|
|
|
// public assignment
|
|
void operator=(const valarray<T>& array) const;
|
|
|
|
// computed assignment
|
|
void operator*=(const valarray<T>& array) const;
|
|
void operator/=(const valarray<T>& array) const;
|
|
void operator%=(const valarray<T>& array) const;
|
|
void operator+=(const valarray<T>& array) const;
|
|
void operator-=(const valarray<T>& array) const;
|
|
void operator^=(const valarray<T>& array) const;
|
|
void operator&=(const valarray<T>& array) const;
|
|
void operator|=(const valarray<T>& array) const;
|
|
void operator<<=(const valarray<T>& array) const;
|
|
void operator>>=(const valarray<T>& array) const;
|
|
|
|
// fill function
|
|
void operator=(const T&);
|
|
|
|
private:
|
|
|
|
// constructors
|
|
gslice_array();
|
|
gslice_array(const gslice_array<T>&);
|
|
|
|
// operator =
|
|
gslice_array<T>& operator= (const gslice_array<T>& array);
|
|
};
|
|
}
|
|
</PRE></UL>
|
|
<A NAME="sec6"><H3>Constructors</H3></A>
|
|
|
|
<A NAME="idx653"></A><PRE><B>gslice_array</B>();
|
|
<B>gslice_array</B>(const gslice_array&);</PRE>
|
|
<UL>
|
|
<P>All <B><I>gslice_array</I></B> constructors are private and cannot be called directly. This prevents copy construction of <B><I>gslice_arrays</I></B>.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec7"><H3>Assignment Operators</H3></A>
|
|
|
|
<A NAME="idx654"></A><PRE>void <B>operator=</B>(const valarray<T>& x) const;</PRE>
|
|
<UL>
|
|
<P>Assigns values from <SAMP>x</SAMP> to the selected elements of the <B><I><A HREF="valarray.html">valarray</A></I></B> that self refers to. Remember that a <B><I>gslice_array</I></B> never holds any elements itself; it simply refers to selected elements in the <B><I>valarray</I></B> used to generate it.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx655"></A><PRE>gslice_array<T>&
|
|
<B>operator=</B>(const gslice_array<T>& x);</PRE>
|
|
<UL>
|
|
<P>Private assignment operator. Cannot be called directly, thus preventing assignment between <B><I>gslice_array</I></B>s.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx656"></A><PRE>void <B>operator=</B>(const T& x) const;</PRE>
|
|
<UL>
|
|
<P>Assigns <SAMP>x</SAMP> to the selected elements of the <B><I><A HREF="valarray.html">valarray</A></I></B> that self refers to. </P>
|
|
</UL>
|
|
|
|
<A NAME="sec8"><H3>Computed Assignment Operators</H3></A>
|
|
|
|
<A NAME="idx657"></A><PRE>void <B>operator*=</B>(const valarray<T>& val) const;
|
|
void <B>operator/=</B>(const valarray<T>& val) const;
|
|
void <B>operator%=</B>(const valarray<T>& val) const;
|
|
void <B>operator+=</B>(const valarray<T>& val) const;
|
|
void <B>operator-=</B>(const valarray<T>& val) const;
|
|
void <B>operator^=</B>(const valarray<T>& val) const;
|
|
void <B>operator&=</B>(const valarray<T>& val) const;
|
|
void <B>operator|=</B>(const valarray<T>& val) const;
|
|
void <B>operator<<=</B>(const valarray<T>& val) const;
|
|
void <B>operator>>=</B>(const valarray<T>& val) const;</PRE>
|
|
<UL>
|
|
<P>Applies the indicated operation using elements from <SAMP>val</SAMP> to the selected elements of the <B><I><A HREF="valarray.html">valarray</A></I></B> that self refers to. Remember that a <B><I>gslice_array</I></B> never holds any elements itself; it simply refers to selected elements in the <B><I>valarray</I></B> used to generate it.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec9"><H3>Example</H3></A>
|
|
|
|
<UL><PRE>//
|
|
// gslice_array.cpp
|
|
//
|
|
|
|
#include <valarray.h> // Includes valarray and
|
|
// provides stream inserter.
|
|
|
|
typedef std::valarray<int> valarray_t;
|
|
|
|
int main(void) {
|
|
|
|
valarray_t::value_type
|
|
ibuf[22] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
|
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
|
|
|
|
// Create a valarray of ints
|
|
valarray_t vi (ibuf,(sizeof ibuf / sizeof *ibuf));
|
|
|
|
// Print out the valarray
|
|
std::cout << "original valarray vi:\n\n" << vi << "\n\n";
|
|
|
|
// Get a two dimensional diagonal slice out of the middle
|
|
size_t length_ary[] = {4, 2};
|
|
size_t stride_ary[] = {4, 6};
|
|
|
|
std::valarray<size_t> length_val(length_ary, 2);
|
|
std::valarray<size_t> stride_val(stride_ary, 2);
|
|
|
|
|
|
// Print out the slices starting at positions 0 and 2
|
|
// respectively.
|
|
std::cout << "vi[gslice(0,[4,2],[4,6])]\n\n"
|
|
<< vi[std::gslice(0,length_val,stride_val)]
|
|
<< "\n\n";
|
|
|
|
std::cout << "vi[gslice(2,[4,2],[4,6])]\n\n"
|
|
<< vi[std::gslice(2,length_val,stride_val)]
|
|
<< "\n\n";
|
|
|
|
// Multiply the first slice by the second.
|
|
vi[std::gslice(0,length_val,stride_val)]
|
|
*= static_cast<valarray_t > (vi[std::gslice(2,length_val,
|
|
stride_val)]);
|
|
|
|
std::cout << "vi[gslice(0,[4,2],[4,8])] *= "
|
|
<< "vi[gslice(2,[4,2],[4,6])]\n\n"
|
|
<< vi << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
Program Output:
|
|
</PRE></UL>
|
|
<UL><PRE>original valarray vi:
|
|
|
|
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
|
|
|
|
vi[gslice(0,[4,2],[4,6])]
|
|
|
|
[0,6,4,10,8,14,12,18]
|
|
|
|
vi[gslice(2,[4,2],[4,6])]
|
|
|
|
[2,8,6,12,10,16,14,20]
|
|
|
|
vi[gslice(0,[4,2],[4,8])] *= vi[gslice(2,[4,2],[4,6])]
|
|
|
|
[0,1,2,3,24,5,48,7,80,9,120,11,168,13,224,15,16,17,360,19,20,21]
|
|
</PRE></UL>
|
|
<A NAME="sec10"><H3>See Also</H3></A>
|
|
<P><B><I><A HREF="slice.html">slice</A></I></B>, <B><I><A HREF="valarray.html">valarray</A></I></B>, <B><I><A HREF="gslice.html">gslice</A></I></B>, <B><I><A HREF="slice-array.html">slice_array</A></I></B>, <B><I><A HREF="mask-array.html">mask_array</A></I></B>, <B><I><A HREF="indirect-array.html">indirect_array</A></I></B></P>
|
|
<A NAME="sec11"><H3>Standards Conformance</H3></A>
|
|
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 26.3.7</I></P>
|
|
|
|
<BR>
|
|
<HR>
|
|
<A HREF="gslice.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="has-facet.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
|
|
|
|
<!-- Google Analytics tracking code -->
|
|
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
|
</script>
|
|
<script type="text/javascript">
|
|
_uacct = "UA-1775151-1";
|
|
urchinTracker();
|
|
</script>
|
|
<!-- end of Google Analytics tracking code -->
|
|
|
|
</BODY>
|
|
</HTML>
|