blob: 2d8f3da8136fb9a3575125a185ee159bd818eb45 [file] [log] [blame]
<!--
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</TITLE>
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
<BODY BGCOLOR=#FFFFFF>
<A HREF="greater-equal.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="gslice-array.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</H2>
<P><B>Library:</B>&nbsp;&nbsp;<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">Accessors</A></LI>
<LI><A HREF="#sec8">Example</A></LI>
<LI><A HREF="#sec9">See Also</A></LI>
<LI><A HREF="#sec10">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="#idx647">gslice()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx651">size()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx650">start()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx652">stride()</A><BR>
</TD></TR>
</TABLE></UL>
<A NAME="sec2"><H3>Summary</H3></A>
<P>A numeric array class used to represent a generalized slice from an array</P>
<A NAME="sec3"><H3>Synopsis</H3></A>
<PRE>#include &lt;valarray&gt;
namespace std {
class gslice;
}
</PRE>
<A NAME="sec4"><H3>Description</H3></A>
<P><B><I>gslice</I></B> represents a generalized slice from an array. A generalized slice contains a starting index, a set of lengths, and a set of strides. The number of lengths and strides must be equal. Together the lengths and strides allow a slice from a multiple dimension array (with the dimension equal to the number of strides) to be represented on a one-dimensional <B><I><A HREF="valarray.html">valarray</A></I></B>. The <B><I>gslice</I></B> maps a set of <SAMP>n</SAMP> indices <SAMP>(ij)</SAMP>, where <SAMP>n</SAMP> is equal to the number of strides, to a single index <SAMP>k</SAMP>. </P>
<P>When applied to a <B><I><A HREF="valarray.html">valarray</A></I></B> using the <B><I>gslice</I></B> subscript operator (see <B><I>valarray</I></B>), a <B><I>gslice</I></B> produces a <B><I><A HREF="gslice-array.html">gslice_array</A></I></B>. The <B><I>gslice_array</I></B> class creates a view into the original <B><I>valarray</I></B> that is tailored to match parameters of the <B><I>gslice</I></B>. The elements in a <B><I>gslice_array</I></B> are references to the elements in the original array. </P>
<A NAME="sec5"><H3>Interface</H3></A>
<UL><PRE>namespace std{
class gslice {
public:
// constructors
gslice();
gslice(size_t, const valarray&lt;size_t&gt;&amp;,
const valarray&lt;size_t&gt;&amp;);
gslice(const gslice&amp;);
// Accessors
size_t start() const;
valarray&lt;size_t&gt; size() const;
valarray&lt;size_t&gt; stride() const;
};
}
</PRE></UL>
<A NAME="sec6"><H3>Constructors</H3></A>
<A NAME="idx647"></A><PRE><B>gslice</B>();</PRE>
<UL>
<P>Default constructor creates a <B><I>gslice</I></B> specifying no elements. </P>
</UL>
<A NAME="idx648"></A><PRE><B>gslice</B>(size_t start, const valarray&lt;size_t&gt;&amp; length,
const valarray&lt;size_t&gt;&amp; stride);</PRE>
<UL>
<P>Creates a <B><I>gslice</I></B> with starting index, length, and stride as indicated by the arguments. </P>
</UL>
<A NAME="idx649"></A><PRE><B>gslice</B>(const gslice&amp;)</PRE>
<UL>
<P>Creates a <B><I>gslice</I></B> with starting index, length, and stride as indicated by the slice argument. </P>
</UL>
<A NAME="sec7"><H3>Accessors</H3></A>
<A NAME="idx650"></A><PRE>size_t <B>start</B>() const;</PRE>
<UL>
<P>Returns the starting index of the <B><I>gslice</I></B>.</P>
</UL>
<A NAME="idx651"></A><PRE>valarray&lt;size_t&gt; <B>size</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>valarray&lt;size_t&gt;</SAMP> containing the lengths of the <B><I>gslice</I></B>.</P>
</UL>
<A NAME="idx652"></A><PRE>valarray&lt;size_t&gt; <B>stride</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>valarray&lt;size_t&gt;</SAMP> containing the strides of the <B><I>gslice</I></B>. </P>
</UL>
<A NAME="sec8"><H3>Example</H3></A>
<UL><PRE>//
// gslice.cpp
//
#include &lt;valarray.h&gt; // Includes valarray and provides
// stream inserter.
typedef std::valarray&lt;int&gt; valarray_t;
typedef std::valarray&lt;size_t&gt; selector_t;
int main(void) {
// Create a valarray of ints.
valarray_t::value_type ibuf[27] =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26 };
valarray_t vi(ibuf, 27);
// Create length and stride valarray
selector_t::value_type length_buf[3] = {3,3,3};
selector_t::value_type stride_buf[3] = {9,3,1};
selector_t length_val(length_buf, 3);
selector_t stride_val(stride_buf, 3);
// Print out the valarray&lt;int&gt;.
std::cout &lt;&lt; "original valarray vi\n\n" &lt;&lt; vi &lt;&lt; "\n\n";
// Print out all three dimensions (the entire valarray).
std::cout &lt;&lt; "vi[gslice(0,{3,3,3},{9,3,1})]\n\n"
&lt;&lt; vi[std::gslice(0,length_val,stride_val)]
&lt;&lt; "\n\n";
// Print a two dimensional slice out of the middle.
selector_t::value_type length_buf2[] = {3, 3};
selector_t::value_type stride_buf2[] = {3, 1};
selector_t length_val2(length_buf2, 2);
selector_t stride_val2(stride_buf2, 2);
std::cout &lt;&lt; "vi[gslice(9,{3,3},{3,1})]\n\n"
&lt;&lt; vi[std::gslice(9,length_val2,stride_val2)]
&lt;&lt; "\n\n";
// Print another two dimensional slice out of the middle but
// orthogonal to one we just did.
stride_val2[0] = 9;
stride_val2[1] = 1;
std::cout &lt;&lt; "vi[gslice(3,{3,3},{9,1})]\n\n"
&lt;&lt; vi[std::gslice(3,length_val2,stride_val2)]
&lt;&lt; "\n\n";
// Print out the last plane in the middle -- orthogonal to
// both of the previous ones.
stride_val2[0] = 3;
stride_val2[1] = 9;
std::cout &lt;&lt; "vi[gslice(1,{3,3},{3,9})]\n\n"
&lt;&lt; vi[std::gslice(1,length_val2,stride_val2)]
&lt;&lt; "\n\n";
// Now how about a diagonal slice, upper left front to lower right
// back.
stride_val2[0] = 3;
stride_val2[1] = 10;
std::cout &lt;&lt; "vi[gslice(0,{3,3},{3,10})]\n\n"
&lt;&lt; vi[std::gslice(0,length_val2,stride_val2)]
&lt;&lt; "\n\n";
return 0;
}
Program Output:
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,22,
23,24,25,26]
vi[gslice(0,{3,3,3},{9,3,1})]
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26]
vi[gslice(9,{3,3},{3,1})]
[9,10,11,12,13,14,15,16,17]
vi[gslice(3,{3,3},{9,1})]
[3,4,5,12,13,14,21,22,23]
vi[gslice(1,{3,3},{3,9})]
[1,10,19,4,13,22,7,16,25]
vi[gslice(0,{3,3},{3,10})]
[0,10,20,3,13,23,6,16,26]
</PRE></UL>
<UL><PRE></PRE></UL>
<A NAME="sec9"><H3>See Also</H3></A>
<P><B><I><A HREF="valarray.html">valarray</A></I></B>, <B><I><A HREF="slice-array.html">slice_array</A></I></B>, <B><I><A HREF="slice.html">slice</A></I></B>, <B><I><A HREF="gslice-array.html">gslice_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="sec10"><H3>Standards Conformance</H3></A>
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 26.3.6</I></P>
<BR>
<HR>
<A HREF="greater-equal.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="gslice-array.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>