nnfw/include/memutils.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef MEMUTILS_H
00021 #define MEMUTILS_H
00022 
00026 #include "nnfwconfig.h"
00027 
00028 namespace farsa {
00029 
00033 template<class T>
00034 inline FARSA_NNFW_TEMPLATE void memoryCopy( T* dest, const T* src, unsigned int size ) {
00035     for( unsigned int i=0; i<size; i++ ) {
00036         dest[i] = src[i];
00037     };
00038 };
00039 
00043 template<class T>
00044 inline FARSA_NNFW_TEMPLATE void memoryZeroing( T* data, unsigned int size ) {
00045     for( unsigned int i=0; i<size; i++ ) {
00046         data[i] = T();
00047     };
00048 };
00049 
00053 inline FARSA_NNFW_TEMPLATE void memoryCopy( float* dest, const float* src, unsigned int size ) {
00054     memcpy( dest, src, sizeof(float)*size );
00055 };
00056 
00060 inline FARSA_NNFW_TEMPLATE void memoryZeroing( float* data, unsigned int size ) {
00061     memset( data, 0, sizeof(float)*size );
00062 };
00063 
00067 inline FARSA_NNFW_TEMPLATE void memoryCopy( double* dest, const double* src, unsigned int size ) {
00068     memcpy( dest, src, sizeof(double)*size );
00069 };
00070 
00074 inline FARSA_NNFW_TEMPLATE void memoryZeroing( double* data, unsigned int size ) {
00075     memset( data, 0, sizeof(double)*size );
00076 };
00077 
00081 inline FARSA_NNFW_TEMPLATE void memoryCopy( bool* dest, const bool* src, unsigned int size ) {
00082     memcpy( dest, src, sizeof(bool)*size );
00083 };
00084 
00088 inline FARSA_NNFW_TEMPLATE void memoryZeroing( bool* data, unsigned int size ) {
00089     memset( data, 0, sizeof(bool)*size );
00090 };
00091 
00092 }
00093 
00094 #endif