📄 copy_neuron_array.c
字号:
/* copy_neuron_array.c *//* Copyright 2004-2007 Oswaldo Morizaki *//* This file is part of ga-nn-ag. ga-nn-ag is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ga-nn-ag is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ga-nn-ag; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "my_header.h"#include "aux_prot.h"/*** Copy the contents of one neuron array into another ***///Assuming destiny is already cleanvoid * copy_neuron_array(int num_neuron, struct neuron ** origin, struct neuron ** destiny){ char * name = "copy_neuron_array"; int k; if ( destiny == NULL ) { if( !(destiny = (struct neuron **)malloc(num_neuron*sizeof(struct neuron *)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny",name); return(NULL); } } else { syslog(LOG_CRIT,"%s: destiny still asigned",name); return(NULL); } for (k=0; k< num_neuron; k++) { if( !(destiny[k] = (struct neuron *)malloc(sizeof(struct neuron)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]",name,k); return(NULL); } memset(destiny[k],0,sizeof(struct neuron )); } for (k=0; k< num_neuron; k++) { if (origin[k]->num_con) { if (!( destiny[k]->con_x = (float *) malloc(origin[k]->num_con*sizeof(float)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]->con_x",name,k); return(NULL); } if (!( destiny[k]->con_y = (float *) malloc(origin[k]->num_con*sizeof(float)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]->con_y",name,k); return(NULL); } if (!( destiny[k]->con_w = (double *) malloc(origin[k]->num_con*sizeof(double)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]->con_w",name,k); return(NULL); } if (!( destiny[k]->age = (int *) malloc(origin[k]->num_con*sizeof(int)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]->age",name,k); return(NULL); } if (origin[k]->momentum == 1) { if (!( destiny[k]->delta_con_w = (double *) malloc(origin[k]->num_con*sizeof(double)) )) { syslog(LOG_CRIT,"%s: Couldn't malloc destiny[%d]->delta_con_w",name,k); return(NULL); } } } else { destiny[k]->con_x = NULL; destiny[k]->con_y = NULL; destiny[k]->con_w = NULL; destiny[k]->age = NULL; destiny[k]->delta_con_w = NULL; } } //couldn't use memcpy for (k=0; k< num_neuron; k++) { copy_neuron(origin[k],destiny[k]); } return(destiny);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -