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