/* Copyright 1998-2011 Research Foundation State University of New York */ /* This file is part of QuB. */ /* QuB 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 3 of the License, or */ /* (at your option) any later version. */ /* QuB 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, */ /* named LICENSE.txt, in the QuB program directory. If not, see */ /* . */ /* begin_html See also: Up: Index end_html */ #ifdef _WIN32 #include #else #include #define BOOL int #define TRUE 1 #define FALSE 0 #endif #include "milutil.h" /* -------------------------- memory allocation routines One dimensional arrays are normal. Two dimensional arrays are block allocated, then a 1D array of ptrs to the rows of the array is constructed and returned. Three dimensional arrays are similarly block allocated then returned as an array of ptrs to an array of ptrs to rows. int *int_alloc1D(int size) Allocate 1-D array of ints float *float_alloc1D(int size) Allocate 1-D array of floats double *double_alloc1D(int size) Allocate 1-D array of doubles double **double_alloc2D(int row, int col) Allocate 2-D array of doubles double ***double_alloc3D(int row, int col, int depth) Allocate 3-D array of doubles void free_2D(char **ptr) Free 2-d array void free_3D(char ***ptr) Free 3-d array void mxv(int m, int n, double **a, double *beta, double *alpha) void vxm(int m, int n, double **a, double *beta, double *alpha) int imaxv(int *d, int n) void mxm(int m, int n, int p, double **a, double **b, double **c) -------------------------- 10/2004 - Unused functions commented out so we don't waste time trying to optimize them. - changed constructs like : double **ptr = (double **)malloc(row*sizeof(double)); to : double **ptr = (double **)malloc(row*sizeof(double *)); Need to check if the 2x allocation size was being used anywhere for padding. void Message( char *szFormat, ... ); void Message( char *szFormat, ... ){ char * pArgs; pArgs = (char *) &szFormat + sizeof( szFormat ); char msg[ 2048 ]; vsprintf( msg, szFormat, pArgs ); } */ void Message( const char * pchMessage ){ // 9/05 - function was not doing anything... // left this shell as a place to put a breakpoint if desired. } int *int_alloc1D(int size){ int *ptr = (int *)malloc(size*sizeof(int)); if( ptr == NULL ) Message("Memory allocation error\n"); return ptr; } float *float_alloc1D(int size){ float *ptr = (float *)malloc(size*sizeof(float)); if( ptr == NULL ) Message("Memory allocation error\n"); return ptr; } double *double_alloc1D(int size){ double *ptr = (double *)malloc(size*sizeof(double)); if( ptr == NULL ) Message("Memory allocation error\n"); return ptr; } double **double_alloc2D(int row, int col){ int i; double **ptr = (double **)malloc(row*sizeof(double *)); double *ptr0 = (double *)malloc(row*col*sizeof(double)); if( ptr==NULL || ptr0==NULL ) { free(ptr); Message("Memory allocation error\n"); return NULL; } for(i=0;idm) dm=d[i]; return dm; } //----- Sum() double vector double dsumv(double *d, int n){ int i; double s; for (s=0.0,i=0; i