Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Amath.h

Go to the documentation of this file.
00001 // SuperMix version 1.0  C++ source file
00002 //
00003 // Copyright (c) 1999 California Institute of Technology.
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms for noncommercial
00007 // purposes are permitted provided that the above copyright notice and
00008 // this paragraph are duplicated in all such forms and that any
00009 // documentation and other materials related to such distribution and
00010 // use acknowledge that the software was developed by California
00011 // Institute of Technology. Redistribution and/or use in source or
00012 // binary forms is not permitted for any commercial purpose. Use of
00013 // this software does not include a permitted use of the Institute's
00014 // name or trademark for any purpose.
00015 //
00016 // DISCLAIMER:
00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00021 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00026 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00028 // MATERIALS.
00029 //
00030 // ********************************************************************
00031 // Amath.h - fast c-style array routines for Complex and double
00032 //
00033 // optimized code is in Amath.o (from Amath.cc)
00034 //
00035 // F.Rice 9/12/97
00036 //
00037 // 11/11/98: Changed appropriate arguments to const *
00038 // 9/19/97:  Added Aapply().
00039 //
00040 // ********************************************************************
00041 //                         The Amath Routines
00042 //
00043 // These routines provide fast manipulation of c-style arrays for use
00044 // in numerical routines.  They require that a length of the arrays be
00045 // included as a parameter, and assume that the source and destination
00046 // arrays are each at least this long.
00047 //
00048 // Cautions:
00049 //  The source and destination arrays must not overlap.
00050 //  The length must be nonnegative.
00051 //
00052 // The Amath routines do no validity checks, so violating either of
00053 // the above restrictions will result in unpredictable behavior.
00054 // The array addresses must be that of the first (ie, lowest address
00055 // value) elements of the arrays.
00056 //
00057 // The result of each routine is overwritten into the first array
00058 // argument (except for Adot).
00059 //
00060 // ********************************************************************
00061 // In the following list:
00062 //  c denotes type Complex, d denotes type double
00063 //  D is the destination array, S is the source array, F is a scalar
00064 //  L is an integer length (must be nonnegative!)
00065 //
00066 // Acopy(cD, cS, L)          copy S onto D
00067 // Acopy(dD, dS, L)
00068 //
00069 // Aset(cD, cF, L)           set all elements of D to F
00070 // Aset(dD, dF, L)
00071 //
00072 // Ascale(cD, dF, L)         multiply each element of D by F
00073 // Ascale(cD, cF, L)
00074 // Ascale(dD, dF, L)
00075 //
00076 // Aadd(cD, cS, L)           add elements of S into elements of D
00077 // Aadd(cD, dS, L)
00078 // Aadd(dD, dS, L)
00079 //
00080 // Asub(cD, cS, L)           subtract elements of S from elements of D
00081 // Asub(cD, dS, L)
00082 // Asub(dD, dS, L)
00083 //
00084 // Ascalesub(cD, cS, cF, L)  subtract elemnts of S, each multiplied by
00085 // Ascalesub(dD, dS, dF, L)  F first, from elements of D (S unmodified)
00086 //
00087 // c Adot(cS1, cS2, L)       return dot product of S1 and S2: <S1|S2>
00088 // d Adot(dS1, dS2, L)
00089 //
00090 // Aapply(cD, Func, L)       replace each element e of D with the result
00091 // Aapply(dD, Func, L)       F(e).  F is called L times.
00092 //
00093 // Note for Aapply: the function Func must have the declaration:
00094 //  Complex Func(Complex);   for applying to a Complex array
00095 //  double Func(double);     for applying to a double array
00096 // or its result must be automatically castable to the required type.
00097 // Additionally Func may accept types <type>& and const <type>&, where
00098 // type is Complex or double, as appropriate.
00099 //
00100 // ********************************************************************
00101 
00102 #ifndef A_MATH_H
00103 #define A_MATH_H
00104 
00105 #include "SIScmplx.h"
00106 #include <string.h>  /* for memcpy(), in Acopy() */
00107 #include <stddef.h>  /* for size_t, in Acopy() */
00108 
00109 inline void Acopy( Complex *dest, const Complex *source, int len )
00110 {
00111   memcpy((void*)dest, (void*)source, (size_t)(len * sizeof(Complex)));
00112 }
00113 inline void Acopy( double *dest, const double *source, int len )
00114 {
00115   memcpy((void*)dest, (void*)source, (size_t)(len * sizeof(double)));
00116 }
00117 
00118 void Aset( Complex dest[], Complex s, int len );
00119 void Aset( double dest[], double s, int len );
00120 
00121 void Ascale( Complex dest[], double s, int len );
00122 void Ascale( Complex dest[], Complex s, int len );
00123 void Ascale( double dest[], double s, int len );
00124 
00125 void Aadd( Complex *dest, const Complex *source, int len );
00126 void Aadd( double *dest, const double *source, int len );
00127 void Aadd( Complex *dest, const double *source, int len );
00128 
00129 void Asub( Complex *dest, const Complex *source, int len );
00130 void Asub( double *dest, const double *source, int len );
00131 void Asub( Complex *dest, const double *source, int len );
00132 
00133 void Ascalesub( Complex *dest, const Complex *source, Complex scale, int len );
00134 void Ascalesub( double *dest, const double *source, double scale, int len );
00135 
00136 Complex Adot( const Complex *a1, const Complex *a2, int len );
00137 inline Complex Adot( Complex *a1, Complex *a2, int len )
00138 { return Adot( (const Complex *)a1, (const Complex *)a2, len); }
00139 double Adot( const double *a1, const double *a2, int len );
00140 inline double Adot( double *a1, double *a2, int len )
00141 { return Adot( (const double *)a1, (const double *)a2, len); }
00142 
00143 void Aapply( Complex a[], Complex (* f)(Complex), int len);
00144 void Aapply( Complex a[], Complex (* f)(Complex &), int len);
00145 void Aapply( Complex a[], Complex (* f)(const Complex &), int len);
00146 void Aapply( double a[], double (* f)(double), int len);
00147 void Aapply( double a[], double (* f)(double &), int len);
00148 void Aapply( double a[], double (* f)(const double &), int len);
00149 
00150 #endif /* A_MATH_H */

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7