📄 spdefs.h
字号:
#ifndef _SPDEFS_H#define _SPDEFS_H/* * DATA STRUCTURE AND MACRO DEFINITIONS for Sparse. * * Author: Advising professor: * Kenneth S. Kundert Alberto Sangiovanni-Vincentelli * UC Berkeley * * This file contains common type definitions and macros for the sparse * matrix routines. These definitions are of no interest to the user. *//* * Revision and copyright information. * * Copyright (c) 1985,86,87,88,89,90 * by Kenneth S. Kundert and the University of California. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby granted, * provided that the copyright notices appear in all copies and * supporting documentation and that the authors and the University of * California are properly credited. The authors and the University of * California make no representations as to the suitability of this * software for any purpose. It is provided `as is', without express * or implied warranty. * * $Date: 2003/08/23 19:49:03 $ * $Revision: 1.10 $ *//* * IMPORTS */#include <stdio.h>#undef ABORT#undef MALLOC#undef FREE#undef REALLOC/* * MACRO DEFINITIONS * * Macros are distinguished by using solely capital letters in their * identifiers. This contrasts with C defined identifiers which are * strictly lower case, and program variable and procedure names * which use both upper and lower case. *//* Begin macros. *//* Boolean data type */#define BOOLEAN int#define NO 0#define YES 1#define NOT !#define AND &&#define OR ||#define SPARSE_ID 0x772773 /* Arbitrary (is Sparse on phone). */#define IS_SPARSE(matrix) ((matrix) != NULL && \ (matrix)->ID == SPARSE_ID)#define IS_VALID(matrix) ((matrix) != NULL && \ (matrix)->ID == SPARSE_ID && \ (matrix)->Error >= spOKAY && \ (matrix)->Error < spFATAL)#define IS_FACTORED(matrix) ((matrix)->Factored && !(matrix)->NeedsOrdering)/* Macro commands *//* Macro functions that return the maximum or minimum independent of type. */#define MAX(a,b) ((a) > (b) ? (a) : (b))#define MIN(a,b) ((a) < (b) ? (a) : (b))/* Macro function that returns the absolute value of a floating point number. */#define ABS(a) ((a) < 0 ? -(a) : (a))/* Macro function that returns the square of a number. */#define SQR(a) ((a)*(a))/* Macro procedure that swaps two entities. */#define SWAP(type, a, b) {type swapx; swapx = a; a = b; b = swapx;}/* Real and Complex numbers definition */#define spREAL double/* Begin `realNumber'. */typedef spREAL RealNumber, *RealVector;/* Begin `ComplexNumber'. */typedef struct{ RealNumber Real; RealNumber Imag;} ComplexNumber, *ComplexVector;/* Macro function that returns the approx absolute value of a complex number. */#define ELEMENT_MAG(ptr) (ABS((ptr)->Real) + ABS((ptr)->Imag)) #define CMPLX_ASSIGN_VALUE(cnum, vReal, vImag) \{ (cnum).Real = vReal; \ (cnum).Imag = vImag; \} /* Complex assignment statements. */#define CMPLX_ASSIGN(to,from) \{ (to).Real = (from).Real; \ (to).Imag = (from).Imag; \}#define CMPLX_CONJ_ASSIGN(to,from) \{ (to).Real = (from).Real; \ (to).Imag = -(from).Imag; \}#define CMPLX_NEGATE_ASSIGN(to,from) \{ (to).Real = -(from).Real; \ (to).Imag = -(from).Imag; \}#define CMPLX_CONJ_NEGATE_ASSIGN(to,from) \{ (to).Real = -(from).Real; \ (to).Imag = (from).Imag; \}#define CMPLX_CONJ(a) (a).Imag = -(a).Imag#define CONJUGATE(a) (a).Imag = -(a).Imag#define CMPLX_NEGATE(a) \{ (a).Real = -(a).Real; \ (a).Imag = -(a).Imag; \}#define CMPLX_NEGATE_SELF(cnum) \{ (cnum).Real = -(cnum).Real; \ (cnum).Imag = -(cnum).Imag; \}/* Macro that returns the approx magnitude (L-1 norm) of a complex number. */#define CMPLX_1_NORM(a) (ABS((a).Real) + ABS((a).Imag))/* Macro that returns the approx magnitude (L-infinity norm) of a complex. */#define CMPLX_INF_NORM(a) (MAX (ABS((a).Real),ABS((a).Imag)))/* Macro function that returns the magnitude (L-2 norm) of a complex number. */#define CMPLX_2_NORM(a) (sqrt((a).Real*(a).Real + (a).Imag*(a).Imag))/* Macro function that performs complex addition. */#define CMPLX_ADD(to,from_a,from_b) \{ (to).Real = (from_a).Real + (from_b).Real; \ (to).Imag = (from_a).Imag + (from_b).Imag; \}/* Macro function that performs addition of a complex and a scalar. */#define CMPLX_ADD_SELF_SCALAR(cnum, scalar) \{ (cnum).Real += scalar; \}/* Macro function that performs complex subtraction. */#define CMPLX_SUBT(to,from_a,from_b) \{ (to).Real = (from_a).Real - (from_b).Real; \ (to).Imag = (from_a).Imag - (from_b).Imag; \}/* Macro function that is equivalent to += operator for complex numbers. */#define CMPLX_ADD_ASSIGN(to,from) \{ (to).Real += (from).Real; \ (to).Imag += (from).Imag; \}/* Macro function that is equivalent to -= operator for complex numbers. */#define CMPLX_SUBT_ASSIGN(to,from) \{ (to).Real -= (from).Real; \ (to).Imag -= (from).Imag; \} /* Macro function that multiplies a complex number by a scalar. */#define SCLR_MULT(to,sclr,cmplx) \{ (to).Real = (sclr) * (cmplx).Real; \ (to).Imag = (sclr) * (cmplx).Imag; \}/* Macro function that multiply-assigns a complex number by a scalar. */#define SCLR_MULT_ASSIGN(to,sclr) \{ (to).Real *= (sclr); \ (to).Imag *= (sclr); \}/* Macro function that multiplies two complex numbers. */#define CMPLX_MULT(to,from_a,from_b) \{ (to).Real = (from_a).Real * (from_b).Real - \ (from_a).Imag * (from_b).Imag; \ (to).Imag = (from_a).Real * (from_b).Imag + \ (from_a).Imag * (from_b).Real; \} /* Macro function that multiplies a complex number and a scalar. */#define CMPLX_MULT_SCALAR(to,from, scalar) \{ (to).Real = (from).Real * scalar; \ (to).Imag = (from).Imag * scalar; \} /* Macro function that implements *= for a complex and a scalar number. */ #define CMPLX_MULT_SELF_SCALAR(cnum, scalar) \{ (cnum).Real *= scalar; \ (cnum).Imag *= scalar; \}/* Macro function that multiply-assigns a complex number by a scalar. */#define SCLR_MULT_ASSIGN(to,sclr) \{ (to).Real *= (sclr); \ (to).Imag *= (sclr); \}/* Macro function that implements to *= from for complex numbers. */#define CMPLX_MULT_ASSIGN(to,from) \{ RealNumber to_Real_ = (to).Real; \ (to).Real = to_Real_ * (from).Real - \ (to).Imag * (from).Imag; \ (to).Imag = to_Real_ * (from).Imag + \ (to).Imag * (from).Real; \}/* Macro function that multiplies two complex numbers, the first of which is * conjugated. */#define CMPLX_CONJ_MULT(to,from_a,from_b) \{ (to).Real = (from_a).Real * (from_b).Real + \ (from_a).Imag * (from_b).Imag; \ (to).Imag = (from_a).Real * (from_b).Imag - \ (from_a).Imag * (from_b).Real; \}/* Macro function that multiplies two complex numbers and then adds them * to another. to = add + mult_a * mult_b */#define CMPLX_MULT_ADD(to,mult_a,mult_b,add) \{ (to).Real = (mult_a).Real * (mult_b).Real - \ (mult_a).Imag * (mult_b).Imag + (add).Real; \ (to).Imag = (mult_a).Real * (mult_b).Imag + \ (mult_a).Imag * (mult_b).Real + (add).Imag; \}/* Macro function that subtracts the product of two complex numbers from * another. to = subt - mult_a * mult_b */#define CMPLX_MULT_SUBT(to,mult_a,mult_b,subt) \{ (to).Real = (subt).Real - (mult_a).Real * (mult_b).Real + \ (mult_a).Imag * (mult_b).Imag; \ (to).Imag = (subt).Imag - (mult_a).Real * (mult_b).Imag - \ (mult_a).Imag * (mult_b).Real; \}/* Macro function that multiplies two complex numbers and then adds them * to another. to = add + mult_a* * mult_b where mult_a* represents mult_a * conjugate. */#define CMPLX_CONJ_MULT_ADD(to,mult_a,mult_b,add) \{ (to).Real = (mult_a).Real * (mult_b).Real + \ (mult_a).Imag * (mult_b).Imag + (add).Real; \ (to).Imag = (mult_a).Real * (mult_b).Imag - \ (mult_a).Imag * (mult_b).Real + (add).Imag; \}/* Macro function that multiplies two complex numbers and then adds them
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -