valarray-inst.cc revision 228780
197403Sobrien// Explicit instantiation file. 297403Sobrien 3169691Skan// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. 497403Sobrien// 597403Sobrien// This file is part of the GNU ISO C++ Library. This library is free 697403Sobrien// software; you can redistribute it and/or modify it under the 797403Sobrien// terms of the GNU General Public License as published by the 897403Sobrien// Free Software Foundation; either version 2, or (at your option) 997403Sobrien// any later version. 1097403Sobrien 1197403Sobrien// This library is distributed in the hope that it will be useful, 1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of 1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1497403Sobrien// GNU General Public License for more details. 1597403Sobrien 1697403Sobrien// You should have received a copy of the GNU General Public License along 1797403Sobrien// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 1997403Sobrien// USA. 2097403Sobrien 2197403Sobrien// As a special exception, you may use this file as part of a free software 2297403Sobrien// library without restriction. Specifically, if other files instantiate 2397403Sobrien// templates or use macros or inline functions from this file, or you compile 2497403Sobrien// this file and link it with other files to produce an executable, this 2597403Sobrien// file does not by itself cause the resulting executable to be covered by 2697403Sobrien// the GNU General Public License. This exception does not however 2797403Sobrien// invalidate any other reasons why the executable file might be covered by 2897403Sobrien// the GNU General Public License. 2997403Sobrien 3097403Sobrien// 3197403Sobrien// ISO C++ 14882: 3297403Sobrien// 3397403Sobrien 3497403Sobrien#include <valarray> 3597403Sobrien 36169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 37169691Skan 38117397Skan // Some explicit instantiations. 3997403Sobrien template void 4097403Sobrien __valarray_fill(size_t* __restrict__, size_t, const size_t&); 4197403Sobrien 4297403Sobrien template void 4397403Sobrien __valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__); 4497403Sobrien 4597403Sobrien template valarray<size_t>::valarray(size_t); 4697403Sobrien template valarray<size_t>::valarray(const valarray<size_t>&); 4797403Sobrien template valarray<size_t>::~valarray(); 4897403Sobrien template size_t valarray<size_t>::size() const; 4997403Sobrien template size_t& valarray<size_t>::operator[](size_t); 5097403Sobrien 5197403Sobrien inline size_t 5297403Sobrien __valarray_product(const valarray<size_t>& __a) 5397403Sobrien { 5497403Sobrien typedef const size_t* __restrict__ _Tp; 5597403Sobrien const size_t __n = __a.size(); 5697403Sobrien // XXX: This ugly cast is necessary because 5797403Sobrien // valarray::operator[]() const return a VALUE! 5897403Sobrien // Try to get the committee to correct that gross error. 5997403Sobrien valarray<size_t>& __t = const_cast<valarray<size_t>&>(__a); 6097403Sobrien return __valarray_product(&__t[0], &__t[0] + __n); 6197403Sobrien } 6297403Sobrien 6397403Sobrien // Map a gslice, described by its multidimensional LENGTHS 6497403Sobrien // and corresponding STRIDES, to a linear array of INDEXES 6597403Sobrien // for the purpose of indexing a flat, one-dimensional array 6697403Sobrien // representation of a gslice_array. 6797403Sobrien void 6897403Sobrien __gslice_to_index(size_t __o, const valarray<size_t>& __l, 6997403Sobrien const valarray<size_t>& __s, valarray<size_t>& __i) 7097403Sobrien { 71228780Spfg // There are as many dimensions as there are strides. 7297403Sobrien size_t __n = __l.size(); 7397403Sobrien 7497403Sobrien // Get a buffer to hold current multi-index as we go through 7597403Sobrien // the gslice for the purpose of computing its linear-image. 7697403Sobrien size_t* const __t = static_cast<size_t*> 7797403Sobrien (__builtin_alloca(__n * sizeof (size_t))); 7897403Sobrien __valarray_fill(__t, __n, size_t(0)); 7997403Sobrien 8097403Sobrien // Note that this should match the product of all numbers appearing 8197403Sobrien // in __l which describes the multidimensional sizes of the 8297403Sobrien // the generalized slice. 8397403Sobrien const size_t __z = __i.size(); 8497403Sobrien 8597403Sobrien for (size_t __j = 0; __j < __z; ++__j) 8697403Sobrien { 8797403Sobrien // Compute the linear-index image of (t_0, ... t_{n-1}). 8897403Sobrien // Normaly, we should use inner_product<>(), but we do it the 8997403Sobrien // the hard way here to avoid link-time can of worms. 9097403Sobrien size_t __a = __o; 9197403Sobrien for (size_t __k = 0; __k < __n; ++__k) 9297403Sobrien __a += __s[__k] * __t[__k]; 9397403Sobrien 9497403Sobrien __i[__j] = __a; 9597403Sobrien 9697403Sobrien // Process the next multi-index. The loop ought to be 9797403Sobrien // backward since we're making a lexicagraphical visit. 9897403Sobrien ++__t[__n - 1]; 9997403Sobrien for (size_t __k2 = __n - 1; __k2; --__k2) 10097403Sobrien { 10197403Sobrien if (__t[__k2] >= __l[__k2]) 10297403Sobrien { 10397403Sobrien __t[__k2] = 0; 10497403Sobrien ++__t[__k2 - 1]; 10597403Sobrien } 10697403Sobrien } 10797403Sobrien } 10897403Sobrien } 10997403Sobrien 11097403Sobrien gslice::_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l, 11197403Sobrien const valarray<size_t>& __s) 112169691Skan : _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s), 113169691Skan _M_index(__l.size() == 0 ? 0 : __valarray_product(__l)) 114117397Skan { __gslice_to_index(__o, __l, __s, _M_index); } 115169691Skan 116169691Skan_GLIBCXX_END_NAMESPACE 117