XMLIOSERVER 0.4
Serveur d'Entrées/Sorties parallèles
array_util_impl.hpp
Aller à la documentation de ce fichier.
00001 /* ************************************************************************** *
00002  *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
00003  * ************************************************************************** */
00004 
00005 #ifndef __ARRAY_UTIL_IMPL_HPP__
00006 #define __ARRAY_UTIL_IMPL_HPP__
00007 
00016 // ////////////////////////////// Déclarations ////////////////////////////// //
00017 
00018 namespace xmlioserver
00019 {
00020    // ---------------------- Conversion de tableau typé ------------------------
00021    
00022    // Convertit un tableau de données d'un certain type vers un autre.
00023    template <typename ODataType, typename IDataType, std::size_t Size>
00024       void CArrayUtil::Convert(const boost::multi_array<IDataType, Size> & _array_in,
00025                                      boost::multi_array<ODataType, Size> & _array_out)
00026    {
00027       _array_out.assign(_array_in.data(), _array_in.data()+_array_in.num_elements());
00028    }
00029    
00030    // --------------------- Opérations sur les tableaux  -----------------------
00031    
00032    // Applique une opération binaire à des tableaux (tableau et tableau).             
00033    template <typename DataType, std::size_t Size>
00034       void CArrayUtil::Apply1(const boost::multi_array<DataType, Size> & _input_array1,
00035                               const boost::multi_array<DataType, Size> & _input_array2,
00036                                     boost::multi_array<DataType, Size> & _output_array,
00037                               DataType (*_function) (DataType, DataType))
00038    {     
00039       const DataType * it1 = _input_array1.data(), * it2 = _input_array2.data(), 
00040                      * end = _input_array1.data() + _input_array1.num_elements();
00041             DataType * it = _output_array.data();
00042       
00043       for (; it1 != end; it1++, it2++, it++) *it = (*_function)(*it1, *it2);
00044    }
00045    
00046    // Applique une opération binaire à un tableau (tableau et scalaire).
00047    template <typename DataType, typename ScalDataType, std::size_t Size>
00048       void CArrayUtil::Apply2(const boost::multi_array<DataType, Size> & _input_array,
00049                                     boost::multi_array<DataType, Size> & _output_array,
00050                                     ScalDataType _scalar,
00051                               DataType (*_function) (DataType, ScalDataType))
00052    {
00053       const DataType * it1 = _input_array.data(),
00054                      * end = _input_array.data() + _input_array.num_elements();
00055             DataType * it = _output_array.data();
00056       for (; it1 != end; it1++, it++) *it = (*_function)(*it1, _scalar);
00057    }
00058    
00059    // --------------------------- Autres méthodes ------------------------------
00060    
00061    // Associe au tableau de sortie le même profil que le tableau d'entrée.
00062    template <typename ODataType, typename IDataType, std::size_t Size>
00063       void CArrayUtil::SameShape(const boost::multi_array<IDataType, Size> & _array_in,
00064                                        boost::multi_array<ODataType, Size> & _array_out)
00065    {
00066       const std::size_t * _shape = _array_in.shape();
00067       std::vector<std::size_t> shape(_shape, _shape+Size);
00068       _array_out.resize(shape);
00069    }
00070    
00071    // ----------------------- Opération élémentaires ---------------------------
00072 
00073    // Somme de _value_1 et _value_2
00074    template <typename DataType, typename ScalDataType>
00075       DataType AUSum (DataType _value_1, ScalDataType _value_2)
00076    { return (_value_1+_value_2); }
00077                                      
00078 } // namespace xmlioserver
00079 
00080 #endif // __ARRAY_UTIL_IMPL_HPP__
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définition de type Énumérations Valeurs énumérées Amis Macros