/* =========================== piro_band_matlab.h =========================== */

/* -----------------------------------------------------------------------------
 * PIRO_BAND.  Version 0.9.
 * Copyright (C) 2009, Sivasankaran Rajamanickam, Timothy A. Davis.
 * PIRO_BAND is licensed under Version 2.0 of the GNU
 * General Public License.  See gpl.txt for a text of the license.
 * PIRO_BAND is also available under other licenses; contact authors for 
 * details. http://www.cise.ufl.edu/research/sparse
 * -------------------------------------------------------------------------- */

/* Macro definitions for complex/real usage. 
 * */

#ifndef PIRO_BAND_MATLAB_H
#define PIRO_BAND_MATLAB_H

#undef MULT_I 
#undef MULT_ADD_I 
#undef MULT_SUB_I 
#undef PRINT_QRVALUES

/* Make sure we use the LONG version */
#ifndef LONG
#define LONG
#endif

#include "piro_band_util.h"
#include "piro_band_internal.h" /* Include the appropriate MACROS for LONG */
#include "matrix.h"


/* ========================================================================== */
/* ========================== Macros for Complex/Real usage ================= */
/* ========================================================================== */

#ifndef COMPLEX
/* [ */

#define MULT_I(c, i1, a, i2, b, i3) (c[i1]) = (a[i2]) * (b[i3]) ;

#define MULT_ADD_I(c, i1, a, i2, b, i3) (c[i1]) += (a[i2]) * (b[i3]) ;

#define MULT_SUB_I(c, i1, a, i2, b, i3) (c[i1]) -= (a[i2]) * (b[i3]) ;

/* ] */
#else
/* [ */

#define MULT_I(c, i1, a, i2, b, i3)  \
                        (c[i1]) = (a[i2]) * (b[i3]) - (a[i2+1]) * (b[i3+1]) ; \
                        (c[i1+1]) = (a[i2]) * (b[i3+1]) + (a[i2+1]) * (b[i3]) ;

#define MULT_ADD_I(c, i1, a, i2, b, i3)  \
                        (c[i1]) += (a[i2]) * (b[i3]) - (a[i2+1]) * (b[i3+1]) ; \
                        (c[i1+1]) += (a[i2]) * (b[i3+1]) + (a[i2+1]) * (b[i3]) ;

#define MULT_SUB_I(c, i1, a, i2, b, i3)  \
                        (c[i1]) -= (a[i2]) * (b[i3]) - (a[i2+1]) * (b[i3+1]) ; \
                        (c[i1+1]) -= (a[i2]) * (b[i3+1]) + (a[i2+1]) * (b[i3]) ;

/* ] */
#endif

/* ========================================================================== */
/* ========================== Macros for printing complex/real data ========= */
/* ========================================================================== */
#ifndef NDEBUG

#ifdef COMPLEX
#define PRINT_QRVALUES(str, i, val, i2) \
            mexPrintf(str "%0.4f %0.4f \n", i, val[i2+0], val[i2+1]) 
#else
#define PRINT_QRVALUES(str, i, val, i2) \
            mexPrintf(str "%0.4f \n", i, val[i2+0]) 
#endif

#else 

#define PRINT_QRVALUES(str, i, val, i2)

#endif

#endif

