Whole document tree
    

Whole document tree

valarray-inst.cc Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

valarray-inst.cc

Go to the documentation of this file.
00001 // Explicit instantiation file.
00002 
00003 // Copyright (C) 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 //
00031 // ISO C++ 14882:
00032 //
00033 
00034 #include <bits/std_valarray.h>
00035 
00036 namespace std
00037 {
00038   // Some explicit instanciations.
00039   template void
00040      __valarray_fill(size_t* __restrict__, size_t, const size_t&);
00041   
00042   template void
00043      __valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__);
00044   
00045   template valarray<size_t>::valarray(size_t);
00046   template valarray<size_t>::valarray(const valarray<size_t>&);
00047   template valarray<size_t>::~valarray();
00048   template size_t valarray<size_t>::size() const;
00049   template size_t& valarray<size_t>::operator[](size_t);
00050 
00051 
00052   inline size_t
00053   __valarray_product(const valarray<size_t>& __a)
00054   {
00055     typedef const size_t* __restrict__ _Tp;
00056     const size_t __n = __a.size();
00057     // XXX: This ugly cast is necessary because
00058     //      valarray::operator[]() const return a VALUE!
00059     //      Try to get the committee to correct that gross error.
00060     valarray<size_t>& __t = const_cast<valarray<size_t>&>(__a);
00061     return __valarray_product(&__t[0], &__t[0] + __n);
00062   }
00063   
00064   // Map a gslice, described by its multidimensional LENGTHS
00065   // and corresponding STRIDES, to a linear array of INDEXES
00066   // for the purpose of indexing a flat, one-dimensional array
00067   // representation of a gslice_array.
00068   void
00069   __gslice_to_index(size_t __o, const valarray<size_t>& __l,
00070                     const valarray<size_t>& __s, valarray<size_t>& __i)
00071   {
00072     // There are as much as dimensions as there are strides.
00073     size_t __n = __l.size();
00074 
00075     // Get a buffer to hold current multi-index as we go through
00076     // the gslice for the purpose of computing its linear-image.
00077     size_t* const __t = static_cast<size_t*>
00078       (__builtin_alloca(__n * sizeof (size_t)));
00079     __valarray_fill(__t, __n, size_t(0));
00080 
00081     // Note that this should match the product of all numbers appearing
00082     // in __l which describes the multidimensional sizes of the
00083     // the generalized slice.
00084     const size_t __z = __i.size();
00085     
00086     for (size_t __j = 0; __j < __z; ++__j)
00087       {
00088         // Compute the linear-index image of (t_0, ... t_{n-1}).
00089         // Normaly, we should use inner_product<>(), but we do it the
00090         // the hard way here to avoid link-time can of worms.
00091         size_t __a = __o;
00092         for (size_t __k = 0; __k < __n; ++__k)
00093           __a += __s[__k] * __t[__k];
00094 
00095         __i[__j] = __a;
00096 
00097         // Process the next multi-index.  The loop ought to be
00098         // backward since we're making a lexicagraphical visit.
00099         ++__t[__n - 1];
00100         for (size_t __k2 = __n - 1; __k2; --__k2)
00101           {
00102             if (__t[__k2] >= __l[__k2])
00103               {
00104                 __t[__k2] = 0;
00105                 ++__t[__k2 - 1];
00106               }
00107           }
00108       }
00109   }
00110   
00111   gslice::_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l,
00112                              const valarray<size_t>& __s)
00113       : _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s),
00114         _M_index(__l.size() == 0 ? 0 : __valarray_product(__l))
00115   { __gslice_to_index(__o, __l, __s, _M_index); }
00116   
00117 } // namespace std
00118 

Generated on Mon Apr 8 03:11:47 2002 for libstdc++-v3 Source by doxygen1.2.15