1*404b540aSrobert // Explicit instantiation file.
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the
7*404b540aSrobert // terms of the GNU General Public License as published by the
8*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert // any later version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful,
12*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert // GNU General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License along
17*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert // USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free software
22*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert // this file and link it with other files to produce an executable, this
25*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert // the GNU General Public License.  This exception does not however
27*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert // the GNU General Public License.
29*404b540aSrobert 
30*404b540aSrobert //
31*404b540aSrobert // ISO C++ 14882:
32*404b540aSrobert //
33*404b540aSrobert 
34*404b540aSrobert #include <valarray>
35*404b540aSrobert 
36*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
37*404b540aSrobert 
38*404b540aSrobert   // Some explicit instantiations.
39*404b540aSrobert   template void
40*404b540aSrobert      __valarray_fill(size_t* __restrict__, size_t, const size_t&);
41*404b540aSrobert 
42*404b540aSrobert   template void
43*404b540aSrobert      __valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__);
44*404b540aSrobert 
45*404b540aSrobert   template valarray<size_t>::valarray(size_t);
46*404b540aSrobert   template valarray<size_t>::valarray(const valarray<size_t>&);
47*404b540aSrobert   template valarray<size_t>::~valarray();
48*404b540aSrobert   template size_t valarray<size_t>::size() const;
49*404b540aSrobert   template size_t& valarray<size_t>::operator[](size_t);
50*404b540aSrobert 
51*404b540aSrobert   inline size_t
__valarray_product(const valarray<size_t> & __a)52*404b540aSrobert   __valarray_product(const valarray<size_t>& __a)
53*404b540aSrobert   {
54*404b540aSrobert     typedef const size_t* __restrict__ _Tp;
55*404b540aSrobert     const size_t __n = __a.size();
56*404b540aSrobert     // XXX: This ugly cast is necessary because
57*404b540aSrobert     //      valarray::operator[]() const return a VALUE!
58*404b540aSrobert     //      Try to get the committee to correct that gross error.
59*404b540aSrobert     valarray<size_t>& __t = const_cast<valarray<size_t>&>(__a);
60*404b540aSrobert     return __valarray_product(&__t[0], &__t[0] + __n);
61*404b540aSrobert   }
62*404b540aSrobert 
63*404b540aSrobert   // Map a gslice, described by its multidimensional LENGTHS
64*404b540aSrobert   // and corresponding STRIDES, to a linear array of INDEXES
65*404b540aSrobert   // for the purpose of indexing a flat, one-dimensional array
66*404b540aSrobert   // representation of a gslice_array.
67*404b540aSrobert   void
__gslice_to_index(size_t __o,const valarray<size_t> & __l,const valarray<size_t> & __s,valarray<size_t> & __i)68*404b540aSrobert   __gslice_to_index(size_t __o, const valarray<size_t>& __l,
69*404b540aSrobert                     const valarray<size_t>& __s, valarray<size_t>& __i)
70*404b540aSrobert   {
71*404b540aSrobert     // There are as much as dimensions as there are strides.
72*404b540aSrobert     size_t __n = __l.size();
73*404b540aSrobert 
74*404b540aSrobert     // Get a buffer to hold current multi-index as we go through
75*404b540aSrobert     // the gslice for the purpose of computing its linear-image.
76*404b540aSrobert     size_t* const __t = static_cast<size_t*>
77*404b540aSrobert       (__builtin_alloca(__n * sizeof (size_t)));
78*404b540aSrobert     __valarray_fill(__t, __n, size_t(0));
79*404b540aSrobert 
80*404b540aSrobert     // Note that this should match the product of all numbers appearing
81*404b540aSrobert     // in __l which describes the multidimensional sizes of the
82*404b540aSrobert     // the generalized slice.
83*404b540aSrobert     const size_t __z = __i.size();
84*404b540aSrobert 
85*404b540aSrobert     for (size_t __j = 0; __j < __z; ++__j)
86*404b540aSrobert       {
87*404b540aSrobert         // Compute the linear-index image of (t_0, ... t_{n-1}).
88*404b540aSrobert         // Normaly, we should use inner_product<>(), but we do it the
89*404b540aSrobert         // the hard way here to avoid link-time can of worms.
90*404b540aSrobert         size_t __a = __o;
91*404b540aSrobert         for (size_t __k = 0; __k < __n; ++__k)
92*404b540aSrobert           __a += __s[__k] * __t[__k];
93*404b540aSrobert 
94*404b540aSrobert         __i[__j] = __a;
95*404b540aSrobert 
96*404b540aSrobert         // Process the next multi-index.  The loop ought to be
97*404b540aSrobert         // backward since we're making a lexicagraphical visit.
98*404b540aSrobert         ++__t[__n - 1];
99*404b540aSrobert         for (size_t __k2 = __n - 1; __k2; --__k2)
100*404b540aSrobert           {
101*404b540aSrobert             if (__t[__k2] >= __l[__k2])
102*404b540aSrobert               {
103*404b540aSrobert                 __t[__k2] = 0;
104*404b540aSrobert                 ++__t[__k2 - 1];
105*404b540aSrobert               }
106*404b540aSrobert           }
107*404b540aSrobert       }
108*404b540aSrobert   }
109*404b540aSrobert 
_Indexer(size_t __o,const valarray<size_t> & __l,const valarray<size_t> & __s)110*404b540aSrobert   gslice::_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l,
111*404b540aSrobert                              const valarray<size_t>& __s)
112*404b540aSrobert   : _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s),
113*404b540aSrobert     _M_index(__l.size() == 0 ? 0 : __valarray_product(__l))
114*404b540aSrobert   { __gslice_to_index(__o, __l, __s, _M_index); }
115*404b540aSrobert 
116*404b540aSrobert _GLIBCXX_END_NAMESPACE
117