update KLU to version 2.3.5

This commit is contained in:
dwarning 2024-12-02 07:34:24 +01:00
parent 4589821df3
commit c638b9678c
42 changed files with 1286 additions and 1398 deletions

View File

@ -136,7 +136,8 @@ noinst_HEADERS = \
fftext.h \ fftext.h \
wallace.h \ wallace.h \
wincolornames.h \ wincolornames.h \
wstdio.h wstdio.h \
SuiteSparse_config.h
if SHARED_MODULE if SHARED_MODULE
pkginclude_HEADERS = \ pkginclude_HEADERS = \

View File

@ -1,19 +1,18 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD: approximate minimum degree ordering =========================== */ // AMD/Include/amd.h: approximate minimum degree ordering
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2024, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD Version 2.2, Copyright (c) 2007 by Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* AMD finds a symmetric ordering P of a matrix A so that the Cholesky /* AMD finds a symmetric ordering P of a matrix A so that the Cholesky
* factorization of P*A*P' has fewer nonzeros and takes less work than the * factorization of P*A*P' has fewer nonzeros and takes less work than the
* Cholesky factorization of A. If A is not symmetric, then it performs its * Cholesky factorization of A. If A is not symmetric, then it performs its
* ordering on the matrix A+A'. Two sets of user-callable routines are * ordering on the matrix A+A'. Two sets of user-callable routines are
* provided, one for int integers and the other for UF_long integers. * provided, one for int32_t integers and the other for int64_t integers.
* *
* The method is based on the approximate minimum degree algorithm, discussed * The method is based on the approximate minimum degree algorithm, discussed
* in Amestoy, Davis, and Duff, "An approximate degree ordering algorithm", * in Amestoy, Davis, and Duff, "An approximate degree ordering algorithm",
@ -36,54 +35,51 @@
#ifndef AMD_H #ifndef AMD_H
#define AMD_H #define AMD_H
#include "SuiteSparse_config.h"
/* make it easy for C++ programs to include AMD */ /* make it easy for C++ programs to include AMD */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* get the definition of size_t: */ int amd_order /* returns AMD_OK, AMD_OK_BUT_JUMBLED,
#include <stddef.h> * AMD_INVALID, or AMD_OUT_OF_MEMORY */
/* define UF_long */
#include "UFconfig.h"
int amd_order /* returns AMD_OK, AMD_OK_BUT_JUMBLED,
* AMD_INVALID, or AMD_OUT_OF_MEMORY */
( (
int n, /* A is n-by-n. n must be >= 0. */ int32_t n, /* A is n-by-n. n must be >= 0. */
const int Ap [ ], /* column pointers for A, of size n+1 */ const int32_t Ap [ ], /* column pointers for A, of size n+1 */
const int Ai [ ], /* row indices of A, of size nz = Ap [n] */ const int32_t Ai [ ], /* row indices of A, of size nz = Ap [n] */
int P [ ], /* output permutation, of size n */ int32_t P [ ], /* output permutation, of size n */
double Control [ ], /* input Control settings, of size AMD_CONTROL */ double Control [ ], /* input Control settings, of size AMD_CONTROL */
double Info [ ] /* output Info statistics, of size AMD_INFO */ double Info [ ] /* output Info statistics, of size AMD_INFO */
) ; ) ;
UF_long amd_l_order /* see above for description of arguments */ int amd_l_order /* see above for description */
( (
UF_long n, int64_t n,
const UF_long Ap [ ], const int64_t Ap [ ],
const UF_long Ai [ ], const int64_t Ai [ ],
UF_long P [ ], int64_t P [ ],
double Control [ ], double Control [ ],
double Info [ ] double Info [ ]
) ; ) ;
/* Input arguments (not modified): /* Input arguments (not modified):
* *
* n: the matrix A is n-by-n. * n: the matrix A is n-by-n.
* Ap: an int/UF_long array of size n+1, containing column pointers of A. * Ap: an int32_t/int64_t array of size n+1, containing column
* Ai: an int/UF_long array of size nz, containing the row indices of A, * pointers of A.
* where nz = Ap [n]. * Ai: an int32_t/int64_t array of size nz, containing the row
* Control: a double array of size AMD_CONTROL, containing control * indices of A, where nz = Ap [n].
* parameters. Defaults are used if Control is NULL. * Control: a double array of size AMD_CONTROL, containing control
* parameters. Defaults are used if Control is NULL.
* *
* Output arguments (not defined on input): * Output arguments (not defined on input):
* *
* P: an int/UF_long array of size n, containing the output permutation. If * P: an int32_t/int64_t array of size n, containing the output
* row i is the kth pivot row, then P [k] = i. In MATLAB notation, * permutation. If row i is the kth pivot row, then P [k] = i. In
* the reordered matrix is A (P,P). * MATLAB notation, the reordered matrix is A (P,P).
* Info: a double array of size AMD_INFO, containing statistical * Info: a double array of size AMD_INFO, containing statistical
* information. Ignored if Info is NULL. * information. Ignored if Info is NULL.
* *
* On input, the matrix A is stored in column-oriented form. The row indices * On input, the matrix A is stored in column-oriented form. The row indices
* of nonzero entries in column j are stored in Ai [Ap [j] ... Ap [j+1]-1]. * of nonzero entries in column j are stored in Ai [Ap [j] ... Ap [j+1]-1].
@ -92,8 +88,7 @@ UF_long amd_l_order /* see above for description of arguments */
* are no duplicate entries, then amd_order is slightly more efficient in * are no duplicate entries, then amd_order is slightly more efficient in
* terms of time and memory usage. If this condition does not hold, a copy * terms of time and memory usage. If this condition does not hold, a copy
* of the matrix is created (where these conditions do hold), and the copy is * of the matrix is created (where these conditions do hold), and the copy is
* ordered. This feature is new to v2.0 (v1.2 and earlier required this * ordered.
* condition to hold for the input matrix).
* *
* Row indices must be in the range 0 to * Row indices must be in the range 0 to
* n-1. Ap [0] must be zero, and thus nz = Ap [n] is the number of nonzeros * n-1. Ap [0] must be zero, and thus nz = Ap [n] is the number of nonzeros
@ -105,25 +100,25 @@ UF_long amd_l_order /* see above for description of arguments */
* pattern of the matrix A is the same as that used internally by MATLAB. * pattern of the matrix A is the same as that used internally by MATLAB.
* If you wish to use a more flexible input structure, please see the * If you wish to use a more flexible input structure, please see the
* umfpack_*_triplet_to_col routines in the UMFPACK package, at * umfpack_*_triplet_to_col routines in the UMFPACK package, at
* http://www.cise.ufl.edu/research/sparse/umfpack. * http://www.suitesparse.com.
* *
* Restrictions: n >= 0. Ap [0] = 0. Ap [j] <= Ap [j+1] for all j in the * Restrictions: n >= 0. Ap [0] = 0. Ap [j] <= Ap [j+1] for all j in the
* range 0 to n-1. nz = Ap [n] >= 0. Ai [0..nz-1] must be in the range 0 * range 0 to n-1. nz = Ap [n] >= 0. Ai [0..nz-1] must be in the range 0
* to n-1. Finally, Ai, Ap, and P must not be NULL. If any of these * to n-1. Finally, Ai, Ap, and P must not be NULL. If any of these
* restrictions are not met, AMD returns AMD_INVALID. * restrictions are not met, AMD returns AMD_INVALID.
* *
* AMD returns: * AMD returns:
* *
* AMD_OK if the matrix is valid and sufficient memory can be allocated to * AMD_OK if the matrix is valid and sufficient memory can be allocated to
* perform the ordering. * perform the ordering.
* *
* AMD_OUT_OF_MEMORY if not enough memory can be allocated. * AMD_OUT_OF_MEMORY if not enough memory can be allocated.
* *
* AMD_INVALID if the input arguments n, Ap, Ai are invalid, or if P is * AMD_INVALID if the input arguments n, Ap, Ai are invalid, or if P is
* NULL. * NULL.
* *
* AMD_OK_BUT_JUMBLED if the matrix had unsorted columns, and/or duplicate * AMD_OK_BUT_JUMBLED if the matrix had unsorted columns, and/or duplicate
* entries, but was otherwise valid. * entries, but was otherwise valid.
* *
* The AMD routine first forms the pattern of the matrix A+A', and then * The AMD routine first forms the pattern of the matrix A+A', and then
* computes a fill-reducing ordering, P. If P [k] = i, then row/column i of * computes a fill-reducing ordering, P. If P [k] = i, then row/column i of
@ -135,93 +130,93 @@ UF_long amd_l_order /* see above for description of arguments */
* pointer is passed, default values are used. The Control array is not * pointer is passed, default values are used. The Control array is not
* modified. * modified.
* *
* Control [AMD_DENSE]: controls the threshold for "dense" rows/columns. * Control [AMD_DENSE]: controls the threshold for "dense" rows/columns.
* A dense row/column in A+A' can cause AMD to spend a lot of time in * A dense row/column in A+A' can cause AMD to spend a lot of time in
* ordering the matrix. If Control [AMD_DENSE] >= 0, rows/columns * ordering the matrix. If Control [AMD_DENSE] >= 0, rows/columns
* with more than Control [AMD_DENSE] * sqrt (n) entries are ignored * with more than Control [AMD_DENSE] * sqrt (n) entries are ignored
* during the ordering, and placed last in the output order. The * during the ordering, and placed last in the output order. The
* default value of Control [AMD_DENSE] is 10. If negative, no * default value of Control [AMD_DENSE] is 10. If negative, no
* rows/columns are treated as "dense". Rows/columns with 16 or * rows/columns are treated as "dense". Rows/columns with 16 or
* fewer off-diagonal entries are never considered "dense". * fewer off-diagonal entries are never considered "dense".
* *
* Control [AMD_AGGRESSIVE]: controls whether or not to use aggressive * Control [AMD_AGGRESSIVE]: controls whether or not to use aggressive
* absorption, in which a prior element is absorbed into the current * absorption, in which a prior element is absorbed into the current
* element if is a subset of the current element, even if it is not * element if is a subset of the current element, even if it is not
* adjacent to the current pivot element (refer to Amestoy, Davis, * adjacent to the current pivot element (refer to Amestoy, Davis,
* & Duff, 1996, for more details). The default value is nonzero, * & Duff, 1996, for more details). The default value is nonzero,
* which means to perform aggressive absorption. This nearly always * which means to perform aggressive absorption. This nearly always
* leads to a better ordering (because the approximate degrees are * leads to a better ordering (because the approximate degrees are
* more accurate) and a lower execution time. There are cases where * more accurate) and a lower execution time. There are cases where
* it can lead to a slightly worse ordering, however. To turn it off, * it can lead to a slightly worse ordering, however. To turn it off,
* set Control [AMD_AGGRESSIVE] to 0. * set Control [AMD_AGGRESSIVE] to 0.
* *
* Control [2..4] are not used in the current version, but may be used in * Control [2..4] are not used in the current version, but may be used in
* future versions. * future versions.
* *
* The Info array provides statistics about the ordering on output. If it is * The Info array provides statistics about the ordering on output. If it is
* not present, the statistics are not returned. This is not an error * not present, the statistics are not returned. This is not an error
* condition. * condition.
* *
* Info [AMD_STATUS]: the return value of AMD, either AMD_OK, * Info [AMD_STATUS]: the return value of AMD, either AMD_OK,
* AMD_OK_BUT_JUMBLED, AMD_OUT_OF_MEMORY, or AMD_INVALID. * AMD_OK_BUT_JUMBLED, AMD_OUT_OF_MEMORY, or AMD_INVALID.
* *
* Info [AMD_N]: n, the size of the input matrix * Info [AMD_N]: n, the size of the input matrix
* *
* Info [AMD_NZ]: the number of nonzeros in A, nz = Ap [n] * Info [AMD_NZ]: the number of nonzeros in A, nz = Ap [n]
* *
* Info [AMD_SYMMETRY]: the symmetry of the matrix A. It is the number * Info [AMD_SYMMETRY]: the symmetry of the matrix A. It is the number
* of "matched" off-diagonal entries divided by the total number of * of "matched" off-diagonal entries divided by the total number of
* off-diagonal entries. An entry A(i,j) is matched if A(j,i) is also * off-diagonal entries. An entry A(i,j) is matched if A(j,i) is also
* an entry, for any pair (i,j) for which i != j. In MATLAB notation, * an entry, for any pair (i,j) for which i != j. In MATLAB notation,
* S = spones (A) ; * S = spones (A) ;
* B = tril (S, -1) + triu (S, 1) ; * B = tril (S, -1) + triu (S, 1) ;
* symmetry = nnz (B & B') / nnz (B) ; * symmetry = nnz (B & B') / nnz (B) ;
* *
* Info [AMD_NZDIAG]: the number of entries on the diagonal of A. * Info [AMD_NZDIAG]: the number of entries on the diagonal of A.
* *
* Info [AMD_NZ_A_PLUS_AT]: the number of nonzeros in A+A', excluding the * Info [AMD_NZ_A_PLUS_AT]: the number of nonzeros in A+A', excluding the
* diagonal. If A is perfectly symmetric (Info [AMD_SYMMETRY] = 1) * diagonal. If A is perfectly symmetric (Info [AMD_SYMMETRY] = 1)
* with a fully nonzero diagonal, then Info [AMD_NZ_A_PLUS_AT] = nz-n * with a fully nonzero diagonal, then Info [AMD_NZ_A_PLUS_AT] = nz-n
* (the smallest possible value). If A is perfectly unsymmetric * (the smallest possible value). If A is perfectly unsymmetric
* (Info [AMD_SYMMETRY] = 0, for an upper triangular matrix, for * (Info [AMD_SYMMETRY] = 0, for an upper triangular matrix, for
* example) with no diagonal, then Info [AMD_NZ_A_PLUS_AT] = 2*nz * example) with no diagonal, then Info [AMD_NZ_A_PLUS_AT] = 2*nz
* (the largest possible value). * (the largest possible value).
* *
* Info [AMD_NDENSE]: the number of "dense" rows/columns of A+A' that were * Info [AMD_NDENSE]: the number of "dense" rows/columns of A+A' that were
* removed from A prior to ordering. These are placed last in the * removed from A prior to ordering. These are placed last in the
* output order P. * output order P.
* *
* Info [AMD_MEMORY]: the amount of memory used by AMD, in bytes. In the * Info [AMD_MEMORY]: the amount of memory used by AMD, in bytes. In the
* current version, this is 1.2 * Info [AMD_NZ_A_PLUS_AT] + 9*n * current version, this is 1.2 * Info [AMD_NZ_A_PLUS_AT] + 9*n
* times the size of an integer. This is at most 2.4nz + 9n. This * times the size of an integer. This is at most 2.4nz + 9n. This
* excludes the size of the input arguments Ai, Ap, and P, which have * excludes the size of the input arguments Ai, Ap, and P, which have
* a total size of nz + 2*n + 1 integers. * a total size of nz + 2*n + 1 integers.
* *
* Info [AMD_NCMPA]: the number of garbage collections performed. * Info [AMD_NCMPA]: the number of garbage collections performed.
* *
* Info [AMD_LNZ]: the number of nonzeros in L (excluding the diagonal). * Info [AMD_LNZ]: the number of nonzeros in L (excluding the diagonal).
* This is a slight upper bound because mass elimination is combined * This is a slight upper bound because mass elimination is combined
* with the approximate degree update. It is a rough upper bound if * with the approximate degree update. It is a rough upper bound if
* there are many "dense" rows/columns. The rest of the statistics, * there are many "dense" rows/columns. The rest of the statistics,
* below, are also slight or rough upper bounds, for the same reasons. * below, are also slight or rough upper bounds, for the same reasons.
* The post-ordering of the assembly tree might also not exactly * The post-ordering of the assembly tree might also not exactly
* correspond to a true elimination tree postordering. * correspond to a true elimination tree postordering.
* *
* Info [AMD_NDIV]: the number of divide operations for a subsequent LDL' * Info [AMD_NDIV]: the number of divide operations for a subsequent LDL'
* or LU factorization of the permuted matrix A (P,P). * or LU factorization of the permuted matrix A (P,P).
* *
* Info [AMD_NMULTSUBS_LDL]: the number of multiply-subtract pairs for a * Info [AMD_NMULTSUBS_LDL]: the number of multiply-subtract pairs for a
* subsequent LDL' factorization of A (P,P). * subsequent LDL' factorization of A (P,P).
* *
* Info [AMD_NMULTSUBS_LU]: the number of multiply-subtract pairs for a * Info [AMD_NMULTSUBS_LU]: the number of multiply-subtract pairs for a
* subsequent LU factorization of A (P,P), assuming that no numerical * subsequent LU factorization of A (P,P), assuming that no numerical
* pivoting is required. * pivoting is required.
* *
* Info [AMD_DMAX]: the maximum number of nonzeros in any column of L, * Info [AMD_DMAX]: the maximum number of nonzeros in any column of L,
* including the diagonal. * including the diagonal.
* *
* Info [14..19] are not used in the current version, but may be used in * Info [14..19] are not used in the current version, but may be used in
* future versions. * future versions.
*/ */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -238,38 +233,38 @@ UF_long amd_l_order /* see above for description of arguments */
void amd_2 void amd_2
( (
int n, int32_t n,
int Pe [ ], int32_t Pe [ ],
int Iw [ ], int32_t Iw [ ],
int Len [ ], int32_t Len [ ],
int iwlen, int32_t iwlen,
int pfree, int32_t pfree,
int Nv [ ], int32_t Nv [ ],
int Next [ ], int32_t Next [ ],
int Last [ ], int32_t Last [ ],
int Head [ ], int32_t Head [ ],
int Elen [ ], int32_t Elen [ ],
int Degree [ ], int32_t Degree [ ],
int W [ ], int32_t W [ ],
double Control [ ], double Control [ ],
double Info [ ] double Info [ ]
) ; ) ;
void amd_l2 void amd_l2
( (
UF_long n, int64_t n,
UF_long Pe [ ], int64_t Pe [ ],
UF_long Iw [ ], int64_t Iw [ ],
UF_long Len [ ], int64_t Len [ ],
UF_long iwlen, int64_t iwlen,
UF_long pfree, int64_t pfree,
UF_long Nv [ ], int64_t Nv [ ],
UF_long Next [ ], int64_t Next [ ],
UF_long Last [ ], int64_t Last [ ],
UF_long Head [ ], int64_t Head [ ],
UF_long Elen [ ], int64_t Elen [ ],
UF_long Degree [ ], int64_t Degree [ ],
UF_long W [ ], int64_t W [ ],
double Control [ ], double Control [ ],
double Info [ ] double Info [ ]
) ; ) ;
@ -284,43 +279,24 @@ void amd_l2
* matrix cannot be passed to amd_order. For amd_order, the matrix must also * matrix cannot be passed to amd_order. For amd_order, the matrix must also
* be square. The first two arguments are the number of rows and the number * be square. The first two arguments are the number of rows and the number
* of columns of the matrix. For its use in AMD, these must both equal n. * of columns of the matrix. For its use in AMD, these must both equal n.
*
* NOTE: this routine returned TRUE/FALSE in v1.2 and earlier.
*/ */
int amd_valid int amd_valid
( (
int n_row, /* # of rows */ int32_t n_row, /* # of rows */
int n_col, /* # of columns */ int32_t n_col, /* # of columns */
const int Ap [ ], /* column pointers, of size n_col+1 */ const int32_t Ap [ ], /* column pointers, of size n_col+1 */
const int Ai [ ] /* row indices, of size Ap [n_col] */ const int32_t Ai [ ] /* row indices, of size Ap [n_col] */
) ; ) ;
UF_long amd_l_valid int amd_l_valid
( (
UF_long n_row, int64_t n_row,
UF_long n_col, int64_t n_col,
const UF_long Ap [ ], const int64_t Ap [ ],
const UF_long Ai [ ] const int64_t Ai [ ]
) ; ) ;
/* ------------------------------------------------------------------------- */
/* AMD memory manager and printf routines */
/* ------------------------------------------------------------------------- */
/* The user can redefine these to change the malloc, free, and printf routines
* that AMD uses. */
#ifndef EXTERN
#define EXTERN extern
#endif
EXTERN void *(*amd_malloc) (size_t) ; /* pointer to malloc */
EXTERN void (*amd_free) (void *) ; /* pointer to free */
EXTERN void *(*amd_realloc) (void *, size_t) ; /* pointer to realloc */
EXTERN void *(*amd_calloc) (size_t, size_t) ; /* pointer to calloc */
EXTERN int (*amd_printf) (const char *, ...) ; /* pointer to printf */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* AMD Control and Info arrays */ /* AMD Control and Info arrays */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -337,6 +313,14 @@ void amd_l_control (double Control [ ]) ;
void amd_info (double Info [ ]) ; void amd_info (double Info [ ]) ;
void amd_l_info (double Info [ ]) ; void amd_l_info (double Info [ ]) ;
// amd_version: return AMD version. The version array is returned with
// version [0..2] = {AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION}
void amd_version (int version [3]) ;
#ifdef __cplusplus
}
#endif
#define AMD_CONTROL 5 /* size of Control array */ #define AMD_CONTROL 5 /* size of Control array */
#define AMD_INFO 20 /* size of Info array */ #define AMD_INFO 20 /* size of Info array */
@ -398,15 +382,18 @@ void amd_l_info (double Info [ ]) ;
* Versions 1.1 and earlier of AMD do not include a #define'd version number. * Versions 1.1 and earlier of AMD do not include a #define'd version number.
*/ */
#define AMD_DATE "Dec 7, 2011" #define AMD_DATE "June 20, 2024"
#define AMD_VERSION_CODE(main,sub) ((main) * 1000 + (sub)) #define AMD_MAIN_VERSION 3
#define AMD_MAIN_VERSION 2 #define AMD_SUB_VERSION 3
#define AMD_SUB_VERSION 2
#define AMD_SUBSUB_VERSION 3 #define AMD_SUBSUB_VERSION 3
#define AMD_VERSION AMD_VERSION_CODE(AMD_MAIN_VERSION,AMD_SUB_VERSION)
#ifdef __cplusplus #define AMD_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub)
} #define AMD_VERSION AMD_VERSION_CODE(3,3)
#define AMD__VERSION SUITESPARSE__VERCODE(3,3,3)
#if !defined (SUITESPARSE__VERSION) || \
(SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0))
#error "AMD 3.3.3 requires SuiteSparse_config 7.8.0 or later"
#endif #endif
#endif #endif

View File

@ -1,17 +1,19 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === BTF package ========================================================== */ // BTF/Include/btf.h: include file for BTF
/* ========================================================================== */ //------------------------------------------------------------------------------
// BTF, Copyright (c) 2004-2024, University of Florida. All Rights Reserved.
// Author: Timothy A. Davis.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* BTF_MAXTRANS: find a column permutation Q to give A*Q a zero-free diagonal /* BTF_MAXTRANS: find a column permutation Q to give A*Q a zero-free diagonal
* BTF_STRONGCOMP: find a symmetric permutation P to put P*A*P' into block * BTF_STRONGCOMP: find a symmetric permutation P to put P*A*P' into block
* upper triangular form. * upper triangular form.
* BTF_ORDER: do both of the above (btf_maxtrans then btf_strongcomp). * BTF_ORDER: do both of the above (btf_maxtrans then btf_strongcomp).
*
* Copyright (c) 2004-2007. Tim Davis, University of Florida,
* with support from Sandia National Laboratories. All Rights Reserved.
*/ */
/* ========================================================================== */ /* ========================================================================== */
/* === BTF_MAXTRANS ========================================================= */ /* === BTF_MAXTRANS ========================================================= */
/* ========================================================================== */ /* ========================================================================== */
@ -88,20 +90,20 @@
#ifndef _BTF_H #ifndef _BTF_H
#define _BTF_H #define _BTF_H
#include "SuiteSparse_config.h"
/* make it easy for C++ programs to include BTF */ /* make it easy for C++ programs to include BTF */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "UFconfig.h" int32_t btf_maxtrans /* returns # of columns matched */
int btf_maxtrans /* returns # of columns matched */
( (
/* --- input, not modified: --- */ /* --- input, not modified: --- */
int nrow, /* A is nrow-by-ncol in compressed column form */ int32_t nrow, /* A is nrow-by-ncol in compressed column form */
int ncol, int32_t ncol,
int Ap [ ], /* size ncol+1 */ int32_t Ap [ ], /* size ncol+1 */
int Ai [ ], /* size nz = Ap [ncol] */ int32_t Ai [ ], /* size nz = Ap [ncol] */
double maxwork, /* maximum amount of work to do is maxwork*nnz(A); no limit double maxwork, /* maximum amount of work to do is maxwork*nnz(A); no limit
* if <= 0 */ * if <= 0 */
@ -110,16 +112,17 @@ int btf_maxtrans /* returns # of columns matched */
* reached the maximum of maxwork*nnz(A). * reached the maximum of maxwork*nnz(A).
* Otherwise, work = the total work performed. */ * Otherwise, work = the total work performed. */
int Match [ ], /* size nrow. Match [i] = j if column j matched to row i int32_t Match [ ], /* size nrow. Match [i] = j if column j matched to row i
* (see above for the singular-matrix case) */ * (see above for the singular-matrix case) */
/* --- workspace, not defined on input or output --- */ /* --- workspace, not defined on input or output --- */
int Work [ ] /* size 5*ncol */ int32_t Work [ ] /* size 5*ncol */
) ; ) ;
/* long integer version (all "int" parameters become "UF_long") */ /* int64_t integer version */
UF_long btf_l_maxtrans (UF_long, UF_long, UF_long *, UF_long *, double, int64_t btf_l_maxtrans (int64_t, int64_t,
double *, UF_long *, UF_long *) ; int64_t *, int64_t *, double, double *,
int64_t *, int64_t *) ;
/* ========================================================================== */ /* ========================================================================== */
@ -144,28 +147,29 @@ UF_long btf_l_maxtrans (UF_long, UF_long, UF_long *, UF_long *, double,
* number of strongly connected components found. * number of strongly connected components found.
*/ */
int btf_strongcomp /* return # of strongly connected components */ int32_t btf_strongcomp /* return # of strongly connected components */
( (
/* input, not modified: */ /* input, not modified: */
int n, /* A is n-by-n in compressed column form */ int32_t n, /* A is n-by-n in compressed column form */
int Ap [ ], /* size n+1 */ int32_t Ap [ ], /* size n+1 */
int Ai [ ], /* size nz = Ap [n] */ int32_t Ai [ ], /* size nz = Ap [n] */
/* optional input, modified (if present) on output: */ /* optional input, modified (if present) on output: */
int Q [ ], /* size n, input column permutation */ int32_t Q [ ], /* size n, input column permutation */
/* output, not defined on input */ /* output, not defined on input */
int P [ ], /* size n. P [k] = j if row and column j are kth row/col int32_t P [ ], /* size n. P [k] = j if row and column j are kth row/col
* in permuted matrix. */ * in permuted matrix. */
int R [ ], /* size n+1. block b is in rows/cols R[b] ... R[b+1]-1 */ int32_t R [ ], /* size n+1. block b is in rows/cols R[b] ... R[b+1]-1 */
/* workspace, not defined on input or output */ /* workspace, not defined on input or output */
int Work [ ] /* size 4n */ int32_t Work [ ] /* size 4n */
) ; ) ;
UF_long btf_l_strongcomp (UF_long, UF_long *, UF_long *, UF_long *, UF_long *, int64_t btf_l_strongcomp (int64_t, int64_t *,
UF_long *, UF_long *) ; int64_t *, int64_t *, int64_t *,
int64_t *, int64_t *) ;
/* ========================================================================== */ /* ========================================================================== */
@ -191,28 +195,38 @@ UF_long btf_l_strongcomp (UF_long, UF_long *, UF_long *, UF_long *, UF_long *,
* number of strongly connected components found. * number of strongly connected components found.
*/ */
int btf_order /* returns number of blocks found */ int32_t btf_order /* returns number of blocks found */
( (
/* --- input, not modified: --- */ /* --- input, not modified: --- */
int n, /* A is n-by-n in compressed column form */ int32_t n, /* A is n-by-n in compressed column form */
int Ap [ ], /* size n+1 */ int32_t Ap [ ], /* size n+1 */
int Ai [ ], /* size nz = Ap [n] */ int32_t Ai [ ], /* size nz = Ap [n] */
double maxwork, /* do at most maxwork*nnz(A) work in the maximum double maxwork, /* do at most maxwork*nnz(A) work in the maximum
* transversal; no limit if <= 0 */ * transversal; no limit if <= 0 */
/* --- output, not defined on input --- */ /* --- output, not defined on input --- */
double *work, /* return value from btf_maxtrans */ double *work, /* return value from btf_maxtrans */
int P [ ], /* size n, row permutation */ int32_t P [ ], /* size n, row permutation */
int Q [ ], /* size n, column permutation */ int32_t Q [ ], /* size n, column permutation */
int R [ ], /* size n+1. block b is in rows/cols R[b] ... R[b+1]-1 */ int32_t R [ ], /* size n+1. block b is in rows/cols R[b] ... R[b+1]-1 */
int *nmatch, /* # nonzeros on diagonal of P*A*Q */ int32_t *nmatch, /* # nonzeros on diagonal of P*A*Q */
/* --- workspace, not defined on input or output --- */ /* --- workspace, not defined on input or output --- */
int Work [ ] /* size 5n */ int32_t Work [ ] /* size 5n */
) ; ) ;
UF_long btf_l_order (UF_long, UF_long *, UF_long *, double , double *, int64_t btf_l_order (int64_t, int64_t *, int64_t *, double , double *,
UF_long *, UF_long *, UF_long *, UF_long *, UF_long *) ; int64_t *, int64_t *, int64_t *, int64_t *, int64_t *) ;
//------------------------------------------------------------------------------
// btf_version: return BTF version
//------------------------------------------------------------------------------
void btf_version (int version [3]) ;
#ifdef __cplusplus
}
#endif
/* ========================================================================== */ /* ========================================================================== */
@ -243,21 +257,25 @@ UF_long btf_l_order (UF_long, UF_long *, UF_long *, double , double *,
* *
* This also works during compile-time: * This also works during compile-time:
* *
* #if (BTF >= BTF_VERSION_CODE (1,2)) * #if (BTF_VERSION >= BTF_VERSION_CODE (1,2))
* printf ("This is version 1.2 or later\n") ; * printf ("This is version 1.2 or later\n") ;
* #else * #else
* printf ("This is an early version\n") ; * printf ("This is an early version\n") ;
* #endif * #endif
*/ */
#define BTF_DATE "Dec 7, 2011" #define BTF_DATE "Mar 22, 2024"
#define BTF_VERSION_CODE(main,sub) ((main) * 1000 + (sub)) #define BTF_MAIN_VERSION 2
#define BTF_MAIN_VERSION 1 #define BTF_SUB_VERSION 3
#define BTF_SUB_VERSION 1 #define BTF_SUBSUB_VERSION 2
#define BTF_SUBSUB_VERSION 3
#define BTF_VERSION BTF_VERSION_CODE(BTF_MAIN_VERSION,BTF_SUB_VERSION)
#ifdef __cplusplus #define BTF_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub)
} #define BTF_VERSION BTF_VERSION_CODE(2,3)
#define BTF__VERSION SUITESPARSE__VERCODE(2,3,2)
#if !defined (SUITESPARSE__VERSION) || \
(SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,7,0))
#error "BTF 2.3.2 requires SuiteSparse_config 7.7.0 or later"
#endif #endif
#endif #endif

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === colamd/symamd prototypes and definitions ============================= */ // COLAMD/Include/colamd.h: include file for COLAMD
/* ========================================================================== */ //------------------------------------------------------------------------------
// COLAMD, Copyright (c) 1998-2024, Timothy A. Davis and Stefan Larimore,
// All Rights Reserved.
// SPDX-License-Identifier: BSD-3-clause
//------------------------------------------------------------------------------
/* COLAMD / SYMAMD include file /* COLAMD / SYMAMD include file
@ -9,55 +15,33 @@
Authors: Authors:
The authors of the code itself are Stefan I. Larimore and Timothy A. The authors of the code itself are Stefan I. Larimore and Timothy A.
Davis (davis at cise.ufl.edu), University of Florida. The algorithm was Davis (DrTimothyAldenDavis@gmail.com). The algorithm was
developed in collaboration with John Gilbert, Xerox PARC, and Esmond developed in collaboration with John Gilbert, Xerox PARC, and Esmond
Ng, Oak Ridge National Laboratory. Ng, Oak Ridge National Laboratory.
Acknowledgements: Acknowledgements:
This work was supported by the National Science Foundation, under This work was supported by the National Science Foundation, under
grants DMS-9504974 and DMS-9803599. grants DMS-9504974 and DMS-9803599.
Notice:
Copyright (c) 1998-2007, Timothy A. Davis, All Rights Reserved.
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
Permission is hereby granted to use, copy, modify, and/or distribute
this program, provided that the Copyright, this License, and the
Availability of the original version is retained on all copies and made
accessible to the end-user of any code or package that includes COLAMD
or any modified version of COLAMD.
Availability: Availability:
The colamd/symamd library is available at The colamd/symamd library is available at http://www.suitesparse.com
This file is required by the colamd.c, colamdmex.c, and symamdmex.c
http://www.cise.ufl.edu/research/sparse/colamd/ files, and by any C code that calls the routines whose prototypes are
listed below, or that uses the colamd/symamd definitions listed below.
This is the http://www.cise.ufl.edu/research/sparse/colamd/colamd.h
file. It is required by the colamd.c, colamdmex.c, and symamdmex.c
files, and by any C code that calls the routines whose prototypes are
listed below, or that uses the colamd/symamd definitions listed below.
*/ */
#ifndef COLAMD_H #ifndef COLAMD_H
#define COLAMD_H #define COLAMD_H
/* make it easy for C++ programs to include COLAMD */
#ifdef __cplusplus
extern "C" {
#endif
/* ========================================================================== */ /* ========================================================================== */
/* === Include files ======================================================== */ /* === Include files ======================================================== */
/* ========================================================================== */ /* ========================================================================== */
#include <stdlib.h> #include "SuiteSparse_config.h"
/* ========================================================================== */ /* ========================================================================== */
/* === COLAMD version ======================================================= */ /* === COLAMD version ======================================================= */
@ -67,7 +51,7 @@ extern "C" {
* As an example, to test if the version you are using is 2.4 or later: * As an example, to test if the version you are using is 2.4 or later:
* *
* #ifdef COLAMD_VERSION * #ifdef COLAMD_VERSION
* if (COLAMD_VERSION >= COLAMD_VERSION_CODE (2,4)) ... * if (COLAMD_VERSION >= COLAMD_VERSION_CODE (2,4)) ...
* #endif * #endif
* *
* This also works during compile-time: * This also works during compile-time:
@ -81,13 +65,19 @@ extern "C" {
* Versions 2.3 and earlier of COLAMD do not include a #define'd version number. * Versions 2.3 and earlier of COLAMD do not include a #define'd version number.
*/ */
#define COLAMD_DATE "Dec 7, 2011" #define COLAMD_DATE "June 20, 2024"
#define COLAMD_VERSION_CODE(main,sub) ((main) * 1000 + (sub)) #define COLAMD_MAIN_VERSION 3
#define COLAMD_MAIN_VERSION 2 #define COLAMD_SUB_VERSION 3
#define COLAMD_SUB_VERSION 7
#define COLAMD_SUBSUB_VERSION 4 #define COLAMD_SUBSUB_VERSION 4
#define COLAMD_VERSION \
COLAMD_VERSION_CODE(COLAMD_MAIN_VERSION,COLAMD_SUB_VERSION) #define COLAMD_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub)
#define COLAMD_VERSION COLAMD_VERSION_CODE(3,3)
#define COLAMD__VERSION SUITESPARSE__VERCODE(3,3,4)
#if !defined (SUITESPARSE__VERSION) || \
(SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0))
#error "COLAMD 3.3.4 requires SuiteSparse_config 7.8.0 or later"
#endif
/* ========================================================================== */ /* ========================================================================== */
/* === Knob and statistics definitions ====================================== */ /* === Knob and statistics definitions ====================================== */
@ -120,133 +110,131 @@ extern "C" {
#define COLAMD_INFO3 6 #define COLAMD_INFO3 6
/* error codes returned in stats [3]: */ /* error codes returned in stats [3]: */
#define COLAMD_OK (0) #define COLAMD_OK (0)
#define COLAMD_OK_BUT_JUMBLED (1) #define COLAMD_OK_BUT_JUMBLED (1)
#define COLAMD_ERROR_A_not_present (-1) #define COLAMD_ERROR_A_not_present (-1)
#define COLAMD_ERROR_p_not_present (-2) #define COLAMD_ERROR_p_not_present (-2)
#define COLAMD_ERROR_nrow_negative (-3) #define COLAMD_ERROR_nrow_negative (-3)
#define COLAMD_ERROR_ncol_negative (-4) #define COLAMD_ERROR_ncol_negative (-4)
#define COLAMD_ERROR_nnz_negative (-5) #define COLAMD_ERROR_nnz_negative (-5)
#define COLAMD_ERROR_p0_nonzero (-6) #define COLAMD_ERROR_p0_nonzero (-6)
#define COLAMD_ERROR_A_too_small (-7) #define COLAMD_ERROR_A_too_small (-7)
#define COLAMD_ERROR_col_length_negative (-8) #define COLAMD_ERROR_col_length_negative (-8)
#define COLAMD_ERROR_row_index_out_of_bounds (-9) #define COLAMD_ERROR_row_index_out_of_bounds (-9)
#define COLAMD_ERROR_out_of_memory (-10) #define COLAMD_ERROR_out_of_memory (-10)
#define COLAMD_ERROR_internal_error (-999) #define COLAMD_ERROR_internal_error (-999)
/* ========================================================================== */ /* ========================================================================== */
/* === Prototypes of user-callable routines ================================= */ /* === Prototypes of user-callable routines ================================= */
/* ========================================================================== */ /* ========================================================================== */
/* define UF_long */ /* make it easy for C++ programs to include COLAMD */
#include "UFconfig.h" #ifdef __cplusplus
extern "C" {
#endif
size_t colamd_recommended /* returns recommended value of Alen, */ size_t colamd_recommended /* returns recommended value of Alen, */
/* or 0 if input arguments are erroneous */ /* or 0 if input arguments are erroneous */
( (
int nnz, /* nonzeros in A */ int32_t nnz, /* nonzeros in A */
int n_row, /* number of rows in A */ int32_t n_row, /* number of rows in A */
int n_col /* number of columns in A */ int32_t n_col /* number of columns in A */
) ; ) ;
size_t colamd_l_recommended /* returns recommended value of Alen, */ size_t colamd_l_recommended /* returns recommended value of Alen, */
/* or 0 if input arguments are erroneous */ /* or 0 if input arguments are erroneous */
( (
UF_long nnz, /* nonzeros in A */ int64_t nnz, /* nonzeros in A */
UF_long n_row, /* number of rows in A */ int64_t n_row, /* number of rows in A */
UF_long n_col /* number of columns in A */ int64_t n_col /* number of columns in A */
) ; ) ;
void colamd_set_defaults /* sets default parameters */ void colamd_set_defaults /* sets default parameters */
( /* knobs argument is modified on output */ ( /* knobs argument is modified on output */
double knobs [COLAMD_KNOBS] /* parameter settings for colamd */ double knobs [COLAMD_KNOBS] /* parameter settings for colamd */
) ; ) ;
void colamd_l_set_defaults /* sets default parameters */ void colamd_l_set_defaults /* sets default parameters */
( /* knobs argument is modified on output */ ( /* knobs argument is modified on output */
double knobs [COLAMD_KNOBS] /* parameter settings for colamd */ double knobs [COLAMD_KNOBS] /* parameter settings for colamd */
) ; ) ;
int colamd /* returns (1) if successful, (0) otherwise*/ int colamd /* returns (1) if successful, (0) otherwise*/
( /* A and p arguments are modified on output */ ( /* A and p arguments are modified on output */
int n_row, /* number of rows in A */ int32_t n_row, /* number of rows in A */
int n_col, /* number of columns in A */ int32_t n_col, /* number of columns in A */
int Alen, /* size of the array A */ int32_t Alen, /* size of the array A */
int A [], /* row indices of A, of size Alen */ int32_t A [], /* row indices of A, of size Alen */
int p [], /* column pointers of A, of size n_col+1 */ int32_t p [], /* column pointers of A, of size n_col+1 */
double knobs [COLAMD_KNOBS],/* parameter settings for colamd */ double knobs [COLAMD_KNOBS], /* parameter settings for colamd */
int stats [COLAMD_STATS] /* colamd output statistics and error codes */ int32_t stats [COLAMD_STATS] /* colamd output stats and error codes */
) ; ) ;
UF_long colamd_l /* returns (1) if successful, (0) otherwise*/ int colamd_l /* returns (1) if successful, (0) otherwise*/
( /* A and p arguments are modified on output */ ( /* A and p arguments are modified on output */
UF_long n_row, /* number of rows in A */ int64_t n_row, /* number of rows in A */
UF_long n_col, /* number of columns in A */ int64_t n_col, /* number of columns in A */
UF_long Alen, /* size of the array A */ int64_t Alen, /* size of the array A */
UF_long A [], /* row indices of A, of size Alen */ int64_t A [], /* row indices of A, of size Alen */
UF_long p [], /* column pointers of A, of size n_col+1 */ int64_t p [], /* column pointers of A, of size n_col+1 */
double knobs [COLAMD_KNOBS],/* parameter settings for colamd */ double knobs [COLAMD_KNOBS], /* parameter settings for colamd */
UF_long stats [COLAMD_STATS]/* colamd output statistics and error codes */ int64_t stats [COLAMD_STATS] /* colamd output stats and error codes */
) ; ) ;
int symamd /* return (1) if OK, (0) otherwise */ int symamd /* return (1) if OK, (0) otherwise */
( (
int n, /* number of rows and columns of A */ int32_t n, /* number of rows and columns of A */
int A [], /* row indices of A */ int32_t A [], /* row indices of A */
int p [], /* column pointers of A */ int32_t p [], /* column pointers of A */
int perm [], /* output permutation, size n_col+1 */ int32_t perm [], /* output permutation, size n_col+1 */
double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */ double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */
int stats [COLAMD_STATS], /* output statistics and error codes */ int32_t stats [COLAMD_STATS], /* output stats and error codes */
void * (*allocate) (size_t, size_t), void * (*allocate) (size_t, size_t),
/* pointer to calloc (ANSI C) or */ /* pointer to calloc (ANSI C) or */
/* mxCalloc (for MATLAB mexFunction) */ /* mxCalloc (for MATLAB mexFunction) */
void (*release) (void *) void (*release) (void *)
/* pointer to free (ANSI C) or */ /* pointer to free (ANSI C) or */
/* mxFree (for MATLAB mexFunction) */ /* mxFree (for MATLAB mexFunction) */
) ; ) ;
UF_long symamd_l /* return (1) if OK, (0) otherwise */ int symamd_l /* return (1) if OK, (0) otherwise */
( (
UF_long n, /* number of rows and columns of A */ int64_t n, /* number of rows and columns of A */
UF_long A [], /* row indices of A */ int64_t A [], /* row indices of A */
UF_long p [], /* column pointers of A */ int64_t p [], /* column pointers of A */
UF_long perm [], /* output permutation, size n_col+1 */ int64_t perm [], /* output permutation, size n_col+1 */
double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */ double knobs [COLAMD_KNOBS], /* parameters (uses defaults if NULL) */
UF_long stats [COLAMD_STATS], /* output statistics and error codes */ int64_t stats [COLAMD_STATS], /* output stats and error codes */
void * (*allocate) (size_t, size_t), void * (*allocate) (size_t, size_t),
/* pointer to calloc (ANSI C) or */ /* pointer to calloc (ANSI C) or */
/* mxCalloc (for MATLAB mexFunction) */ /* mxCalloc (for MATLAB mexFunction) */
void (*release) (void *) void (*release) (void *)
/* pointer to free (ANSI C) or */ /* pointer to free (ANSI C) or */
/* mxFree (for MATLAB mexFunction) */ /* mxFree (for MATLAB mexFunction) */
) ; ) ;
void colamd_report void colamd_report
( (
int stats [COLAMD_STATS] int32_t stats [COLAMD_STATS]
) ; ) ;
void colamd_l_report void colamd_l_report
( (
UF_long stats [COLAMD_STATS] int64_t stats [COLAMD_STATS]
) ; ) ;
void symamd_report void symamd_report
( (
int stats [COLAMD_STATS] int32_t stats [COLAMD_STATS]
) ; ) ;
void symamd_l_report void symamd_l_report
( (
UF_long stats [COLAMD_STATS] int64_t stats [COLAMD_STATS]
) ; ) ;
#ifndef EXTERN void colamd_version (int version [3]) ;
#define EXTERN extern
#endif
EXTERN int (*colamd_printf) (const char *, ...) ;
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,21 +1,27 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === klu include file ===================================================== */ // KLU/Source/klu.h: include file for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2024, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Include file for user programs that call klu_* routines */ /* Include file for user programs that call klu_* routines */
#ifndef _KLU_H #ifndef _KLU_H
#define _KLU_H #define _KLU_H
#include "amd.h"
#include "colamd.h"
#include "btf.h"
/* make it easy for C++ programs to include KLU */ /* make it easy for C++ programs to include KLU */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "amd.h"
#include "colamd.h"
#include "btf.h"
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Symbolic object - contains the pre-ordering computed by klu_analyze */ /* Symbolic object - contains the pre-ordering computed by klu_analyze */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -34,7 +40,7 @@ typedef struct
double *Lnz ; /* size n, but only Lnz [0..nblocks-1] is used */ double *Lnz ; /* size n, but only Lnz [0..nblocks-1] is used */
/* computed for all orderings: */ /* computed for all orderings: */
int int32_t
n, /* input matrix A is n-by-n */ n, /* input matrix A is n-by-n */
nz, /* # entries in input matrix */ nz, /* # entries in input matrix */
*P, /* size n */ *P, /* size n */
@ -43,11 +49,11 @@ typedef struct
nzoff, /* nz in off-diagonal blocks */ nzoff, /* nz in off-diagonal blocks */
nblocks, /* number of blocks */ nblocks, /* number of blocks */
maxblock, /* size of largest block */ maxblock, /* size of largest block */
ordering, /* ordering used (AMD, COLAMD, or GIVEN) */ ordering, /* ordering used (0:AMD, 1:COLAMD, 2:given, ... */
do_btf ; /* whether or not BTF preordering was requested */ do_btf ; /* whether or not BTF preordering was requested */
/* only computed if BTF preordering requested */ /* only computed if BTF preordering requested */
int structural_rank ; /* 0 to n-1 if the matrix is structurally rank int32_t structural_rank ; /* 0 to n-1 if the matrix is structurally rank
* deficient. -1 if not computed. n if the matrix has * deficient. -1 if not computed. n if the matrix has
* full structural rank */ * full structural rank */
@ -57,8 +63,8 @@ typedef struct /* 64-bit version (otherwise same as above) */
{ {
double symmetry, est_flops, lnz, unz ; double symmetry, est_flops, lnz, unz ;
double *Lnz ; double *Lnz ;
UF_long n, nz, *P, *Q, *R, nzoff, nblocks, maxblock, ordering, do_btf, int64_t n, nz, *P, *Q, *R, nzoff, nblocks, maxblock, ordering,
structural_rank ; do_btf, structural_rank ;
} klu_l_symbolic ; } klu_l_symbolic ;
@ -71,20 +77,20 @@ typedef struct
/* LU factors of each block, the pivot row permutation, and the /* LU factors of each block, the pivot row permutation, and the
* entries in the off-diagonal blocks */ * entries in the off-diagonal blocks */
int n ; /* A is n-by-n */ int32_t n ; /* A is n-by-n */
int nblocks ; /* number of diagonal blocks */ int32_t nblocks ; /* number of diagonal blocks */
int lnz ; /* actual nz in L, including diagonal */ int32_t lnz ; /* actual nz in L, including diagonal */
int unz ; /* actual nz in U, including diagonal */ int32_t unz ; /* actual nz in U, including diagonal */
int max_lnz_block ; /* max actual nz in L in any one block, incl. diag */ int32_t max_lnz_block ; /* max actual nz in L in any one block, incl. diag */
int max_unz_block ; /* max actual nz in U in any one block, incl. diag */ int32_t max_unz_block ; /* max actual nz in U in any one block, incl. diag */
int *Pnum ; /* size n. final pivot permutation */ int32_t *Pnum ; /* size n. final pivot permutation */
int *Pinv ; /* size n. inverse of final pivot permutation */ int32_t *Pinv ; /* size n. inverse of final pivot permutation */
/* LU factors of each block */ /* LU factors of each block */
int *Lip ; /* size n. pointers into LUbx[block] for L */ int32_t *Lip ; /* size n. pointers into LUbx[block] for L */
int *Uip ; /* size n. pointers into LUbx[block] for U */ int32_t *Uip ; /* size n. pointers into LUbx[block] for U */
int *Llen ; /* size n. Llen [k] = # of entries in kth column of L */ int32_t *Llen ; /* size n. Llen [k] = # of entries in kth column of L */
int *Ulen ; /* size n. Ulen [k] = # of entries in kth column of U */ int32_t *Ulen ; /* size n. Ulen [k] = # of entries in kth column of U */
void **LUbx ; /* L and U indices and entries (excl. diagonal of U) */ void **LUbx ; /* L and U indices and entries (excl. diagonal of U) */
size_t *LUsize ; /* size of each LUbx [block], in sizeof (Unit) */ size_t *LUsize ; /* size of each LUbx [block], in sizeof (Unit) */
void *Udiag ; /* diagonal of U */ void *Udiag ; /* diagonal of U */
@ -96,30 +102,30 @@ typedef struct
size_t worksize ; /* size (in bytes) of Work */ size_t worksize ; /* size (in bytes) of Work */
void *Work ; /* workspace */ void *Work ; /* workspace */
void *Xwork ; /* alias into Numeric->Work */ void *Xwork ; /* alias into Numeric->Work */
int *Iwork ; /* alias into Numeric->Work */ int32_t *Iwork ; /* alias into Numeric->Work */
/* off-diagonal entries in a conventional compressed-column sparse matrix */ /* off-diagonal entries in a conventional compressed-column sparse matrix */
int *Offp ; /* size n+1, column pointers */ int32_t *Offp ; /* size n+1, column pointers */
int *Offi ; /* size nzoff, row indices */ int32_t *Offi ; /* size nzoff, row indices */
void *Offx ; /* size nzoff, numerical values */ void *Offx ; /* size nzoff, numerical values */
int nzoff ; int32_t nzoff ;
} klu_numeric ; } klu_numeric ;
typedef struct /* 64-bit version (otherwise same as above) */ typedef struct /* 64-bit version (otherwise same as above) */
{ {
UF_long n, nblocks, lnz, unz, max_lnz_block, max_unz_block, *Pnum, *Pinv, int64_t n, nblocks, lnz, unz, max_lnz_block, max_unz_block, *Pnum,
*Lip, *Uip, *Llen, *Ulen ; *Pinv, *Lip, *Uip, *Llen, *Ulen ;
void **LUbx ; void **LUbx ;
size_t *LUsize ; size_t *LUsize ;
void *Udiag ; void *Udiag ;
double *Rs ; double *Rs ;
size_t worksize ; size_t worksize ;
void *Work, *Xwork ; void *Work, *Xwork ;
UF_long *Iwork ; int64_t *Iwork ;
UF_long *Offp, *Offi ; int64_t *Offp, *Offi ;
void *Offx ; void *Offx ;
UF_long nzoff ; int64_t nzoff ;
} klu_l_numeric ; } klu_l_numeric ;
@ -154,14 +160,9 @@ typedef struct klu_common_struct
int scale ; /* row scaling: -1: none (and no error check), int scale ; /* row scaling: -1: none (and no error check),
* 0: none, 1: sum, 2: max */ * 0: none, 1: sum, 2: max */
/* memory management routines */
void *(*malloc_memory) (size_t) ; /* pointer to malloc */
void *(*realloc_memory) (void *, size_t) ; /* pointer to realloc */
void (*free_memory) (void *) ; /* pointer to free */
void *(*calloc_memory) (size_t, size_t) ; /* pointer to calloc */
/* pointer to user ordering function */ /* pointer to user ordering function */
int (*user_order) (int, int *, int *, int *, struct klu_common_struct *) ; int32_t (*user_order) (int32_t, int32_t *, int32_t *, int32_t *,
struct klu_common_struct *) ;
/* pointer to user data, passed unchanged as the last parameter to the /* pointer to user data, passed unchanged as the last parameter to the
* user ordering function (optional, the user function need not use this * user ordering function (optional, the user function need not use this
@ -184,23 +185,23 @@ typedef struct klu_common_struct
int status ; /* KLU_OK if OK, < 0 if error */ int status ; /* KLU_OK if OK, < 0 if error */
int nrealloc ; /* # of reallocations of L and U */ int nrealloc ; /* # of reallocations of L and U */
int structural_rank ; /* 0 to n-1 if the matrix is structurally rank int32_t structural_rank ; /* 0 to n-1 if the matrix is structurally rank
* deficient (as determined by maxtrans). -1 if not computed. n if the * deficient (as determined by maxtrans). -1 if not computed. n if the
* matrix has full structural rank. This is computed by klu_analyze * matrix has full structural rank. This is computed by klu_analyze
* if a BTF preordering is requested. */ * if a BTF preordering is requested. */
int numerical_rank ; /* First k for which a zero U(k,k) was found, int32_t numerical_rank ; /* First k for which a zero U(k,k) was found,
* if the matrix was singular (in the range 0 to n-1). n if the matrix * if the matrix was singular (in the range 0 to n-1). n if the matrix
* has full rank. This is not a true rank-estimation. It just reports * has full rank. This is not a true rank-estimation. It just reports
* where the first zero pivot was found. -1 if not computed. * where the first zero pivot was found. -1 if not computed.
* Computed by klu_factor and klu_refactor. */ * Computed by klu_factor and klu_refactor. */
int singular_col ; /* n if the matrix is not singular. If in the int32_t singular_col ; /* n if the matrix is not singular. If in the
* range 0 to n-1, this is the column index of the original matrix A that * range 0 to n-1, this is the column index of the original matrix A that
* corresponds to the column of U that contains a zero diagonal entry. * corresponds to the column of U that contains a zero diagonal entry.
* -1 if not computed. Computed by klu_factor and klu_refactor. */ * -1 if not computed. Computed by klu_factor and klu_refactor. */
int noffdiag ; /* # of off-diagonal pivots, -1 if not computed */ int32_t noffdiag ; /* # of off-diagonal pivots, -1 if not computed */
double flops ; /* actual factorization flop count, from klu_flops */ double flops ; /* actual factorization flop count, from klu_flops */
double rcond ; /* crude reciprocal condition est., from klu_rcond */ double rcond ; /* crude reciprocal condition est., from klu_rcond */
@ -217,17 +218,12 @@ typedef struct klu_l_common_struct /* 64-bit version (otherwise same as above)*/
{ {
double tol, memgrow, initmem_amd, initmem, maxwork ; double tol, memgrow, initmem_amd, initmem, maxwork ;
UF_long btf, ordering, scale ; int btf, ordering, scale ;
void *(*malloc_memory) (size_t) ; int64_t (*user_order) (int64_t, int64_t *, int64_t *, int64_t *,
void *(*realloc_memory) (void *, size_t) ;
void (*free_memory) (void *) ;
void *(*calloc_memory) (size_t, size_t) ;
UF_long (*user_order) (UF_long, UF_long *, UF_long *, UF_long *,
struct klu_l_common_struct *) ; struct klu_l_common_struct *) ;
void *user_data ; void *user_data ;
UF_long halt_if_singular ; int halt_if_singular, status, nrealloc ;
UF_long status, nrealloc, structural_rank, numerical_rank, singular_col, int64_t structural_rank, numerical_rank, singular_col, noffdiag ;
noffdiag ;
double flops, rcond, condest, rgrowth, work ; double flops, rcond, condest, rgrowth, work ;
size_t memusage, mempeak ; size_t memusage, mempeak ;
@ -242,7 +238,7 @@ int klu_defaults
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_defaults (klu_l_common *Common) ; int klu_l_defaults (klu_l_common *Common) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* klu_analyze: orders and analyzes a matrix */ /* klu_analyze: orders and analyzes a matrix */
@ -254,13 +250,13 @@ UF_long klu_l_defaults (klu_l_common *Common) ;
klu_symbolic *klu_analyze klu_symbolic *klu_analyze
( (
/* inputs, not modified */ /* inputs, not modified */
int n, /* A is n-by-n */ int32_t n, /* A is n-by-n */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
klu_common *Common klu_common *Common
) ; ) ;
klu_l_symbolic *klu_l_analyze (UF_long, UF_long *, UF_long *, klu_l_symbolic *klu_l_analyze (int64_t, int64_t *, int64_t *,
klu_l_common *Common) ; klu_l_common *Common) ;
@ -275,16 +271,16 @@ klu_l_symbolic *klu_l_analyze (UF_long, UF_long *, UF_long *,
klu_symbolic *klu_analyze_given klu_symbolic *klu_analyze_given
( (
/* inputs, not modified */ /* inputs, not modified */
int n, /* A is n-by-n */ int32_t n, /* A is n-by-n */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
int P [ ], /* size n, user's row permutation (may be NULL) */ int32_t P [ ], /* size n, user's row permutation (may be NULL) */
int Q [ ], /* size n, user's column permutation (may be NULL) */ int32_t Q [ ], /* size n, user's column permutation (may be NULL) */
klu_common *Common klu_common *Common
) ; ) ;
klu_l_symbolic *klu_l_analyze_given (UF_long, UF_long *, UF_long *, UF_long *, klu_l_symbolic *klu_l_analyze_given (int64_t, int64_t *, int64_t *, int64_t *,
UF_long *, klu_l_common *) ; int64_t *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -294,8 +290,8 @@ klu_l_symbolic *klu_l_analyze_given (UF_long, UF_long *, UF_long *, UF_long *,
klu_numeric *klu_factor /* returns KLU_OK if OK, < 0 if error */ klu_numeric *klu_factor /* returns KLU_OK if OK, < 0 if error */
( (
/* inputs, not modified */ /* inputs, not modified */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], /* size nz, numerical values */ double Ax [ ], /* size nz, numerical values */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_common *Common klu_common *Common
@ -304,20 +300,20 @@ klu_numeric *klu_factor /* returns KLU_OK if OK, < 0 if error */
klu_numeric *klu_z_factor /* returns KLU_OK if OK, < 0 if error */ klu_numeric *klu_z_factor /* returns KLU_OK if OK, < 0 if error */
( (
/* inputs, not modified */ /* inputs, not modified */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], /* size 2*nz, numerical values (real,imag pairs) */ double Ax [ ], /* size 2*nz, numerical values (real,imag pairs) */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_common *Common klu_common *Common
) ; ) ;
/* long / real version */ /* int64_t / real version */
klu_l_numeric *klu_l_factor (UF_long *, UF_long *, double *, klu_l_symbolic *, klu_l_numeric *klu_l_factor (int64_t *, int64_t *, double *,
klu_l_common *) ; klu_l_symbolic *, klu_l_common *) ;
/* long / complex version */ /* int64_t / complex version */
klu_l_numeric *klu_zl_factor (UF_long *, UF_long *, double *, klu_l_symbolic *, klu_l_numeric *klu_zl_factor (int64_t *, int64_t *, double *,
klu_l_common *) ; klu_l_symbolic *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -329,8 +325,8 @@ int klu_solve
/* inputs, not modified */ /* inputs, not modified */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
int ldim, /* leading dimension of B */ int32_t ldim, /* leading dimension of B */
int nrhs, /* number of right-hand-sides */ int32_t nrhs, /* number of right-hand-sides */
/* right-hand-side on input, overwritten with solution to Ax=b on output */ /* right-hand-side on input, overwritten with solution to Ax=b on output */
double B [ ], /* size ldim*nrhs */ double B [ ], /* size ldim*nrhs */
@ -342,19 +338,19 @@ int klu_z_solve
/* inputs, not modified */ /* inputs, not modified */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
int ldim, /* leading dimension of B */ int32_t ldim, /* leading dimension of B */
int nrhs, /* number of right-hand-sides */ int32_t nrhs, /* number of right-hand-sides */
/* right-hand-side on input, overwritten with solution to Ax=b on output */ /* right-hand-side on input, overwritten with solution to Ax=b on output */
double B [ ], /* size 2*ldim*nrhs */ double B [ ], /* size 2*ldim*nrhs */
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_solve (klu_l_symbolic *, klu_l_numeric *, UF_long, UF_long, int klu_l_solve (klu_l_symbolic *, klu_l_numeric *,
double *, klu_l_common *) ; int64_t, int64_t, double *, klu_l_common *) ;
UF_long klu_zl_solve (klu_l_symbolic *, klu_l_numeric *, UF_long, UF_long, int klu_zl_solve (klu_l_symbolic *, klu_l_numeric *,
double *, klu_l_common *) ; int64_t, int64_t, double *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -366,8 +362,8 @@ int klu_tsolve
/* inputs, not modified */ /* inputs, not modified */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
int ldim, /* leading dimension of B */ int32_t ldim, /* leading dimension of B */
int nrhs, /* number of right-hand-sides */ int32_t nrhs, /* number of right-hand-sides */
/* right-hand-side on input, overwritten with solution to Ax=b on output */ /* right-hand-side on input, overwritten with solution to Ax=b on output */
double B [ ], /* size ldim*nrhs */ double B [ ], /* size ldim*nrhs */
@ -379,8 +375,8 @@ int klu_z_tsolve
/* inputs, not modified */ /* inputs, not modified */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
int ldim, /* leading dimension of B */ int32_t ldim, /* leading dimension of B */
int nrhs, /* number of right-hand-sides */ int32_t nrhs, /* number of right-hand-sides */
/* right-hand-side on input, overwritten with solution to Ax=b on output */ /* right-hand-side on input, overwritten with solution to Ax=b on output */
double B [ ], /* size 2*ldim*nrhs */ double B [ ], /* size 2*ldim*nrhs */
@ -389,11 +385,11 @@ int klu_z_tsolve
) ; ) ;
UF_long klu_l_tsolve (klu_l_symbolic *, klu_l_numeric *, UF_long, UF_long, int klu_l_tsolve (klu_l_symbolic *, klu_l_numeric *,
double *, klu_l_common *) ; int64_t, int64_t, double *, klu_l_common *) ;
UF_long klu_zl_tsolve (klu_l_symbolic *, klu_l_numeric *, UF_long, UF_long, int klu_zl_tsolve (klu_l_symbolic *, klu_l_numeric *,
double *, UF_long, klu_l_common * ) ; int64_t, int64_t, double *, int, klu_l_common * ) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -403,8 +399,8 @@ UF_long klu_zl_tsolve (klu_l_symbolic *, klu_l_numeric *, UF_long, UF_long,
int klu_refactor /* return TRUE if successful, FALSE otherwise */ int klu_refactor /* return TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], /* size nz, numerical values */ double Ax [ ], /* size nz, numerical values */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
/* input, and numerical values modified on output */ /* input, and numerical values modified on output */
@ -415,8 +411,8 @@ int klu_refactor /* return TRUE if successful, FALSE otherwise */
int klu_z_refactor /* return TRUE if successful, FALSE otherwise */ int klu_z_refactor /* return TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], /* size 2*nz, numerical values */ double Ax [ ], /* size 2*nz, numerical values */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
/* input, and numerical values modified on output */ /* input, and numerical values modified on output */
@ -424,11 +420,11 @@ int klu_z_refactor /* return TRUE if successful, FALSE otherwise */
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_refactor (UF_long *, UF_long *, double *, klu_l_symbolic *, int klu_l_refactor (int64_t *, int64_t *,
klu_l_numeric *, klu_l_common *) ; double *, klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_refactor (UF_long *, UF_long *, double *, klu_l_symbolic *, int klu_zl_refactor (int64_t *, int64_t *,
klu_l_numeric *, klu_l_common *) ; double *, klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -441,7 +437,7 @@ int klu_free_symbolic
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_free_symbolic (klu_l_symbolic **, klu_l_common *) ; int klu_l_free_symbolic (klu_l_symbolic **, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -463,8 +459,8 @@ int klu_z_free_numeric
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_free_numeric (klu_l_numeric **, klu_l_common *) ; int klu_l_free_numeric (klu_l_numeric **, klu_l_common *) ;
UF_long klu_zl_free_numeric (klu_l_numeric **, klu_l_common *) ; int klu_zl_free_numeric (klu_l_numeric **, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -491,8 +487,8 @@ int klu_z_sort
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_sort (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ; int klu_l_sort (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_sort (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ; int klu_zl_sort (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -517,9 +513,8 @@ int klu_z_flops
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_flops (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ; int klu_l_flops (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_flops (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ; int klu_zl_flops (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -541,8 +536,8 @@ UF_long klu_zl_flops (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
int klu_rgrowth int klu_rgrowth
( (
int Ap [ ], int32_t Ap [ ],
int Ai [ ], int32_t Ai [ ],
double Ax [ ], double Ax [ ],
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
@ -551,19 +546,19 @@ int klu_rgrowth
int klu_z_rgrowth int klu_z_rgrowth
( (
int Ap [ ], int32_t Ap [ ],
int Ai [ ], int32_t Ai [ ],
double Ax [ ], double Ax [ ],
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
klu_common *Common /* Common->rgrowth = reciprocal pivot growth */ klu_common *Common /* Common->rgrowth = reciprocal pivot growth */
) ; ) ;
UF_long klu_l_rgrowth (UF_long *, UF_long *, double *, klu_l_symbolic *, int klu_l_rgrowth (int64_t *, int64_t *,
klu_l_numeric *, klu_l_common *) ; double *, klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_rgrowth (UF_long *, UF_long *, double *, klu_l_symbolic *, int klu_zl_rgrowth (int64_t *, int64_t *,
klu_l_numeric *, klu_l_common *) ; double *, klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -576,7 +571,7 @@ UF_long klu_zl_rgrowth (UF_long *, UF_long *, double *, klu_l_symbolic *,
int klu_condest int klu_condest
( (
int Ap [ ], /* size n+1, column pointers, not modified */ int32_t Ap [ ], /* size n+1, column pointers, not modified */
double Ax [ ], /* size nz = Ap[n], numerical values, not modified*/ double Ax [ ], /* size nz = Ap[n], numerical values, not modified*/
klu_symbolic *Symbolic, /* symbolic analysis, not modified */ klu_symbolic *Symbolic, /* symbolic analysis, not modified */
klu_numeric *Numeric, /* numeric factorization, not modified */ klu_numeric *Numeric, /* numeric factorization, not modified */
@ -585,18 +580,18 @@ int klu_condest
int klu_z_condest int klu_z_condest
( (
int Ap [ ], int32_t Ap [ ],
double Ax [ ], /* size 2*nz */ double Ax [ ], /* size 2*nz */
klu_symbolic *Symbolic, klu_symbolic *Symbolic,
klu_numeric *Numeric, klu_numeric *Numeric,
klu_common *Common /* result returned in Common->condest */ klu_common *Common /* result returned in Common->condest */
) ; ) ;
UF_long klu_l_condest (UF_long *, double *, klu_l_symbolic *, klu_l_numeric *, int klu_l_condest (int64_t *, double *, klu_l_symbolic *,
klu_l_common *) ; klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_condest (UF_long *, double *, klu_l_symbolic *, klu_l_numeric *, int klu_zl_condest (int64_t *, double *, klu_l_symbolic *,
klu_l_common *) ; klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -617,11 +612,8 @@ int klu_z_rcond
klu_common *Common /* result in Common->rcond */ klu_common *Common /* result in Common->rcond */
) ; ) ;
UF_long klu_l_rcond (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ; int klu_l_rcond (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
int klu_zl_rcond (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
UF_long klu_zl_rcond (klu_l_symbolic *, klu_l_numeric *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* klu_scale */ /* klu_scale */
@ -631,14 +623,14 @@ int klu_scale /* return TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
int scale, /* <0: none, no error check; 0: none, 1: sum, 2: max */ int scale, /* <0: none, no error check; 0: none, 1: sum, 2: max */
int n, int32_t n,
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], double Ax [ ],
/* outputs, not defined on input */ /* outputs, not defined on input */
double Rs [ ], double Rs [ ],
/* workspace, not defined on input or output */ /* workspace, not defined on input or output */
int W [ ], /* size n, can be NULL */ int32_t W [ ], /* size n, can be NULL */
klu_common *Common klu_common *Common
) ; ) ;
@ -646,22 +638,22 @@ int klu_z_scale /* return TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
int scale, /* <0: none, no error check; 0: none, 1: sum, 2: max */ int scale, /* <0: none, no error check; 0: none, 1: sum, 2: max */
int n, int32_t n,
int Ap [ ], /* size n+1, column pointers */ int32_t Ap [ ], /* size n+1, column pointers */
int Ai [ ], /* size nz, row indices */ int32_t Ai [ ], /* size nz, row indices */
double Ax [ ], double Ax [ ],
/* outputs, not defined on input */ /* outputs, not defined on input */
double Rs [ ], double Rs [ ],
/* workspace, not defined on input or output */ /* workspace, not defined on input or output */
int W [ ], /* size n, can be NULL */ int32_t W [ ], /* size n, can be NULL */
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_scale (UF_long, UF_long, UF_long *, UF_long *, double *, int klu_l_scale (int, int64_t, int64_t *, int64_t *, double *,
double *, UF_long *, klu_l_common *) ; double *, int64_t *, klu_l_common *) ;
UF_long klu_zl_scale (UF_long, UF_long, UF_long *, UF_long *, double *, int klu_zl_scale (int, int64_t, int64_t *, int64_t *, double *,
double *, UF_long *, klu_l_common *) ; double *, int64_t *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -677,36 +669,35 @@ int klu_extract /* returns TRUE if successful, FALSE otherwise */
/* outputs, either allocated on input, or ignored otherwise */ /* outputs, either allocated on input, or ignored otherwise */
/* L */ /* L */
int *Lp, /* size n+1 */ int32_t *Lp, /* size n+1 */
int *Li, /* size Numeric->lnz */ int32_t *Li, /* size Numeric->lnz */
double *Lx, /* size Numeric->lnz */ double *Lx, /* size Numeric->lnz */
/* U */ /* U */
int *Up, /* size n+1 */ int32_t *Up, /* size n+1 */
int *Ui, /* size Numeric->unz */ int32_t *Ui, /* size Numeric->unz */
double *Ux, /* size Numeric->unz */ double *Ux, /* size Numeric->unz */
/* F */ /* F */
int *Fp, /* size n+1 */ int32_t *Fp, /* size n+1 */
int *Fi, /* size Numeric->nzoff */ int32_t *Fi, /* size Numeric->nzoff */
double *Fx, /* size Numeric->nzoff */ double *Fx, /* size Numeric->nzoff */
/* P, row permutation */ /* P, row permutation */
int *P, /* size n */ int32_t *P, /* size n */
/* Q, column permutation */ /* Q, column permutation */
int *Q, /* size n */ int32_t *Q, /* size n */
/* Rs, scale factors */ /* Rs, scale factors */
double *Rs, /* size n */ double *Rs, /* size n */
/* R, block boundaries */ /* R, block boundaries */
int *R, /* size Symbolic->nblocks+1 (nblocks is at most n) */ int32_t *R, /* size Symbolic->nblocks+1 (nblocks is at most n) */
klu_common *Common klu_common *Common
) ; ) ;
/* Francesco - Extract only Udiag */ /* Francesco - Extract only Udiag */
int klu_extract_Udiag /* returns TRUE if successful, FALSE otherwise */ int klu_extract_Udiag /* returns TRUE if successful, FALSE otherwise */
( (
@ -726,7 +717,6 @@ int klu_extract_Udiag /* returns TRUE if successful, FALSE otherwise */
klu_common *Common klu_common *Common
) ; ) ;
int klu_z_extract /* returns TRUE if successful, FALSE otherwise */ int klu_z_extract /* returns TRUE if successful, FALSE otherwise */
( (
/* inputs: */ /* inputs: */
@ -736,34 +726,34 @@ int klu_z_extract /* returns TRUE if successful, FALSE otherwise */
/* outputs, all of which must be allocated on input */ /* outputs, all of which must be allocated on input */
/* L */ /* L */
int *Lp, /* size n+1 */ int32_t *Lp, /* size n+1 */
int *Li, /* size nnz(L) */ int32_t *Li, /* size nnz(L) */
double *Lx, /* size nnz(L) */ double *Lx, /* size nnz(L) */
double *Lz, /* size nnz(L) for the complex case, ignored if real */ double *Lz, /* size nnz(L) for the complex case, ignored if real */
/* U */ /* U */
int *Up, /* size n+1 */ int32_t *Up, /* size n+1 */
int *Ui, /* size nnz(U) */ int32_t *Ui, /* size nnz(U) */
double *Ux, /* size nnz(U) */ double *Ux, /* size nnz(U) */
double *Uz, /* size nnz(U) for the complex case, ignored if real */ double *Uz, /* size nnz(U) for the complex case, ignored if real */
/* F */ /* F */
int *Fp, /* size n+1 */ int32_t *Fp, /* size n+1 */
int *Fi, /* size nnz(F) */ int32_t *Fi, /* size nnz(F) */
double *Fx, /* size nnz(F) */ double *Fx, /* size nnz(F) */
double *Fz, /* size nnz(F) for the complex case, ignored if real */ double *Fz, /* size nnz(F) for the complex case, ignored if real */
/* P, row permutation */ /* P, row permutation */
int *P, /* size n */ int32_t *P, /* size n */
/* Q, column permutation */ /* Q, column permutation */
int *Q, /* size n */ int32_t *Q, /* size n */
/* Rs, scale factors */ /* Rs, scale factors */
double *Rs, /* size n */ double *Rs, /* size n */
/* R, block boundaries */ /* R, block boundaries */
int *R, /* size Symbolic->nblocks+1 (nblocks is at most n) */ int32_t *R, /* size Symbolic->nblocks+1 (nblocks is at most n) */
klu_common *Common klu_common *Common
) ; ) ;
@ -788,17 +778,19 @@ int klu_z_extract_Udiag /* returns TRUE if successful, FALSE otherwise */
klu_common *Common klu_common *Common
) ; ) ;
UF_long klu_l_extract (klu_l_numeric *, klu_l_symbolic *, int klu_l_extract (klu_l_numeric *, klu_l_symbolic *,
UF_long *, UF_long *, double *, int64_t *, int64_t *, double *,
UF_long *, UF_long *, double *, int64_t *, int64_t *, double *,
UF_long *, UF_long *, double *, int64_t *, int64_t *, double *,
UF_long *, UF_long *, double *, UF_long *, klu_l_common *) ; int64_t *, int64_t *, double *,
int64_t *, klu_l_common *) ;
UF_long klu_zl_extract (klu_l_numeric *, klu_l_symbolic *, int klu_zl_extract (klu_l_numeric *, klu_l_symbolic *,
UF_long *, UF_long *, double *, double *, int64_t *, int64_t *, double *, double *,
UF_long *, UF_long *, double *, double *, int64_t *, int64_t *, double *, double *,
UF_long *, UF_long *, double *, double *, int64_t *, int64_t *, double *, double *,
UF_long *, UF_long *, double *, UF_long *, klu_l_common *) ; int64_t *, int64_t *, double *,
int64_t *, klu_l_common *) ;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -837,7 +829,9 @@ void *klu_realloc /* returns pointer to reallocated block */
) ; ) ;
void *klu_l_malloc (size_t, size_t, klu_l_common *) ; void *klu_l_malloc (size_t, size_t, klu_l_common *) ;
void *klu_l_free (void *, size_t, size_t, klu_l_common *) ; void *klu_l_free (void *, size_t, size_t, klu_l_common *) ;
void *klu_l_realloc (size_t, size_t, size_t, void *, klu_l_common *) ; void *klu_l_realloc (size_t, size_t, size_t, void *, klu_l_common *) ;
int klu_print int klu_print
@ -860,81 +854,6 @@ int klu_z_print
int *IntToExtColMap int *IntToExtColMap
) ; ) ;
int klu_constant_multiply
(
int *Ap,
double *Ax,
int n,
klu_common *Common,
double constant
) ;
int klu_z_constant_multiply
(
int *Ap,
double *Ax,
int n,
klu_common *Common,
double constant
) ;
int klu_matrix_vector_multiply
(
int *Ap, /* CSR */
int *Ai, /* CSR */
double *Ax, /* CSR */
double *RHS,
double *Solution,
int *IntToExtRowMap,
int *IntToExtColMap,
int n,
klu_common *Common
) ;
int klu_z_matrix_vector_multiply
(
int *Ap, /* CSR */
int *Ai, /* CSR */
double *Ax, /* CSR */
double *RHS,
double *Solution,
double *iRHS,
double *iSolution,
int *IntToExtRowMap,
int *IntToExtColMap,
int n,
klu_common *Common
) ;
int klu_convert_matrix_in_CSR
(
int *Ap_CSC, /* CSC */
int *Ai_CSC, /* CSC */
double *Ax_CSC, /* CSC */
int *Ap_CSR, /* CSR */
int *Ai_CSR, /* CSR */
double *Ax_CSR, /* CSR */
int n,
int nz,
klu_common *Common
) ;
int klu_z_convert_matrix_in_CSR
(
int *Ap_CSC, /* CSC */
int *Ai_CSC, /* CSC */
double *Ax_CSC, /* CSC */
int *Ap_CSR, /* CSR */
int *Ai_CSR, /* CSR */
double *Ax_CSR, /* CSR */
int n,
int nz,
klu_common *Common
) ;
typedef struct sBindElement { typedef struct sBindElement {
double *COO ; double *COO ;
double *CSC ; double *CSC ;
@ -996,6 +915,16 @@ typedef struct sKLUmatrix {
} KLUmatrix ; } KLUmatrix ;
//------------------------------------------------------------------------------
// klu_version: return KLU version
//------------------------------------------------------------------------------
void klu_version (int version [3]) ;
#ifdef __cplusplus
}
#endif
/* ========================================================================== */ /* ========================================================================== */
/* === KLU version ========================================================== */ /* === KLU version ========================================================== */
/* ========================================================================== */ /* ========================================================================== */
@ -1014,14 +943,34 @@ typedef struct sKLUmatrix {
* #endif * #endif
*/ */
#define KLU_DATE "Dec 7, 2011" #define KLU_DATE "Oct 10, 2024"
#define KLU_VERSION_CODE(main,sub) ((main) * 1000 + (sub)) #define KLU_MAIN_VERSION 2
#define KLU_MAIN_VERSION 1 #define KLU_SUB_VERSION 3
#define KLU_SUB_VERSION 1 #define KLU_SUBSUB_VERSION 5
#define KLU_SUBSUB_VERSION 3
#define KLU_VERSION KLU_VERSION_CODE(KLU_MAIN_VERSION,KLU_SUB_VERSION)
#ifdef __cplusplus #define KLU_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub)
} #define KLU_VERSION KLU_VERSION_CODE(2,3)
#define KLU__VERSION SUITESPARSE__VERCODE(2,3,5)
#if !defined (SUITESPARSE__VERSION) || \
(SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,3))
#error "KLU 2.3.5 requires SuiteSparse_config 7.8.3 or later"
#endif #endif
#if !defined (AMD__VERSION) || \
(AMD__VERSION < SUITESPARSE__VERCODE(3,3,3))
#error "KLU 2.3.5 requires AMD 3.3.3 or later"
#endif #endif
#if !defined (COLAMD__VERSION) || \
(COLAMD__VERSION < SUITESPARSE__VERCODE(3,3,4))
#error "KLU 2.3.5 requires COLAMD 3.3.4 or later"
#endif
#if !defined (BTF__VERSION) || \
(BTF__VERSION < SUITESPARSE__VERCODE(2,3,2))
#error "KLU 2.3.5 requires BTF 2.3.2 or later"
#endif
#endif

View File

@ -75,7 +75,8 @@ libKLU_la_SOURCES = \
klu_defaults.c \ klu_defaults.c \
klu_free_symbolic.c \ klu_free_symbolic.c \
klu_memory.c \ klu_memory.c \
klusmp.c klusmp.c \
SuiteSparse_config.c
libKLU_la_LIBADD = \ libKLU_la_LIBADD = \
libKLU_real.la \ libKLU_real.la \

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_1 =============================================================== */ // AMD/Source/amd_1: construct input matrix and then order with amd_2
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* AMD_1: Construct A+A' for a sparse matrix A and perform the AMD ordering. /* AMD_1: Construct A+A' for a sparse matrix A and perform the AMD ordering.
* *
@ -27,7 +26,7 @@
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL void AMD_1 void AMD_1
( (
Int n, /* n > 0 */ Int n, /* n > 0 */
const Int Ap [ ], /* input of size n+1, not modified */ const Int Ap [ ], /* input of size n+1, not modified */

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_2 =============================================================== */ // AMD/Source/amd_2: AMD ordering
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* AMD_2: performs the AMD ordering on a symmetric sparse matrix A, followed /* AMD_2: performs the AMD ordering on a symmetric sparse matrix A, followed
* by a postordering (via depth-first search) of the assembly tree using the * by a postordering (via depth-first search) of the assembly tree using the
@ -40,7 +39,7 @@ static Int clear_flag (Int wflg, Int wbig, Int W [ ], Int n)
/* === AMD_2 =============================================================== */ /* === AMD_2 =============================================================== */
/* ========================================================================= */ /* ========================================================================= */
GLOBAL void AMD_2 void AMD_2
( (
Int n, /* A is n-by-n, where n > 0 */ Int n, /* A is n-by-n, where n > 0 */
Int Pe [ ], /* Pe [0..n-1]: index in Iw of row i on input */ Int Pe [ ], /* Pe [0..n-1]: index in Iw of row i on input */
@ -120,9 +119,9 @@ GLOBAL void AMD_2
* ouput. Many of these functions are also provided by the Fortran * ouput. Many of these functions are also provided by the Fortran
* Harwell Subroutine Library routine MC47A. * Harwell Subroutine Library routine MC47A.
* *
* (6) both int and UF_long versions are provided. In the descriptions below * (6) both int32_t and int64_t versions are provided. In the
* and integer is and int or UF_long depending on which version is * descriptions below an integer is int32_t or int64_t depending
* being used. * on which version is being used.
********************************************************************** **********************************************************************
***** CAUTION: ARGUMENTS ARE NOT CHECKED FOR ERRORS ON INPUT. ****** ***** CAUTION: ARGUMENTS ARE NOT CHECKED FOR ERRORS ON INPUT. ******
@ -463,7 +462,7 @@ GLOBAL void AMD_2
nvi, nvj, nvpiv, slenme, wbig, we, wflg, wnvi, ok, ndense, ncmpa, nvi, nvj, nvpiv, slenme, wbig, we, wflg, wnvi, ok, ndense, ncmpa,
dense, aggressive ; dense, aggressive ;
unsigned Int hash ; /* unsigned, so that hash % n is well defined.*/ UInt hash ; /* unsigned, so that hash % n is well defined.*/
/* /*
* deg: the degree of a variable or element * deg: the degree of a variable or element
@ -495,8 +494,9 @@ GLOBAL void AMD_2
* nvj: the number of variables in a supervariable j (= Nv [j]) * nvj: the number of variables in a supervariable j (= Nv [j])
* nvpiv: number of pivots in current element * nvpiv: number of pivots in current element
* slenme: number of variables in variable list of pivotal variable * slenme: number of variables in variable list of pivotal variable
* wbig: = INT_MAX - n for the int version, UF_long_max - n for the * wbig: = (INT32_MAX - n) for the int32_t version, (INT64_MAX - n)
* UF_long version. wflg is not allowed to be >= wbig. * for the int64_t version. wflg is not allowed to
* be >= wbig.
* we: W [e] * we: W [e]
* wflg: used for flagging the W array. See description of Iw. * wflg: used for flagging the W array. See description of Iw.
* wnvi: wflg - Nv [i] * wnvi: wflg - Nv [i]

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_aat ============================================================= */ // AMD/Source/amd_aat: compute symmetry of A and nnz in each column of A+A'
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* AMD_aat: compute the symmetry of the pattern of A, and count the number of /* AMD_aat: compute the symmetry of the pattern of A, and count the number of
* nonzeros each column of A+A' (excluding the diagonal). Assumes the input * nonzeros each column of A+A' (excluding the diagonal). Assumes the input
@ -18,7 +17,7 @@
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL size_t AMD_aat /* returns nz in A+A' */ size_t AMD_aat /* returns nz in A+A' */
( (
Int n, Int n,
const Int Ap [ ], const Int Ap [ ],

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_control ========================================================= */ // AMD/Source/amd_control: print control parameters for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* User-callable. Prints the control parameters for AMD. See amd.h /* User-callable. Prints the control parameters for AMD. See amd.h
* for details. If the Control array is not present, the defaults are * for details. If the Control array is not present, the defaults are
@ -16,7 +15,7 @@
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL void AMD_control void AMD_control
( (
double Control [ ] double Control [ ]
) )
@ -35,17 +34,18 @@ GLOBAL void AMD_control
aggressive = AMD_DEFAULT_AGGRESSIVE ; aggressive = AMD_DEFAULT_AGGRESSIVE ;
} }
PRINTF (("\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n" SUITESPARSE_PRINTF ((
"\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n"
" dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION, " dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION,
AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ; AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ;
if (alpha < 0) if (alpha < 0)
{ {
PRINTF ((" no rows treated as dense\n")) ; SUITESPARSE_PRINTF ((" no rows treated as dense\n")) ;
} }
else else
{ {
PRINTF (( SUITESPARSE_PRINTF ((
" (rows with more than max (%g * sqrt (n), 16) entries are\n" " (rows with more than max (%g * sqrt (n), 16) entries are\n"
" considered \"dense\", and placed last in output permutation)\n", " considered \"dense\", and placed last in output permutation)\n",
alpha)) ; alpha)) ;
@ -53,12 +53,12 @@ GLOBAL void AMD_control
if (aggressive) if (aggressive)
{ {
PRINTF ((" aggressive absorption: yes\n")) ; SUITESPARSE_PRINTF ((" aggressive absorption: yes\n")) ;
} }
else else
{ {
PRINTF ((" aggressive absorption: no\n")) ; SUITESPARSE_PRINTF ((" aggressive absorption: no\n")) ;
} }
PRINTF ((" size of AMD integer: %d\n\n", sizeof (Int))) ; SUITESPARSE_PRINTF ((" size of AMD integer: %d\n\n", sizeof (Int))) ;
} }

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_defaults ======================================================== */ // AMD/Source/amd_defaults: set defaults for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* User-callable. Sets default control parameters for AMD. See amd.h /* User-callable. Sets default control parameters for AMD. See amd.h
* for details. * for details.
@ -19,7 +18,7 @@
/* === AMD defaults ======================================================== */ /* === AMD defaults ======================================================== */
/* ========================================================================= */ /* ========================================================================= */
GLOBAL void AMD_defaults void AMD_defaults
( (
double Control [ ] double Control [ ]
) )

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_dump ============================================================ */ // AMD/Source/amd_dump: debug routines for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* Debugging routines for AMD. Not used if NDEBUG is not defined at compile- /* Debugging routines for AMD. Not used if NDEBUG is not defined at compile-
* time (the default). See comments in amd_internal.h on how to enable * time (the default). See comments in amd_internal.h on how to enable
@ -19,7 +18,7 @@
#ifndef NDEBUG #ifndef NDEBUG
/* This global variable is present only when debugging */ /* This global variable is present only when debugging */
GLOBAL Int AMD_debug = -999 ; /* default is no debug printing */ Int AMD_debug = -999 ; /* default is no debug printing */
/* ========================================================================= */ /* ========================================================================= */
/* === AMD_debug_init ====================================================== */ /* === AMD_debug_init ====================================================== */
@ -27,7 +26,7 @@ GLOBAL Int AMD_debug = -999 ; /* default is no debug printing */
/* Sets the debug print level, by reading the file debug.amd (if it exists) */ /* Sets the debug print level, by reading the file debug.amd (if it exists) */
GLOBAL void AMD_debug_init ( char *s ) void AMD_debug_init ( char *s )
{ {
FILE *f ; FILE *f ;
f = fopen ("debug.amd", "r") ; f = fopen ("debug.amd", "r") ;
@ -54,7 +53,7 @@ GLOBAL void AMD_debug_init ( char *s )
* cannot be called when the hash buckets are non-empty. * cannot be called when the hash buckets are non-empty.
*/ */
GLOBAL void AMD_dump ( void AMD_dump (
Int n, /* A is n-by-n */ Int n, /* A is n-by-n */
Int Pe [ ], /* pe [0..n-1]: index in iw of start of row i */ Int Pe [ ], /* pe [0..n-1]: index in iw of start of row i */
Int Iw [ ], /* workspace of size iwlen, iwlen [0..pfree-1] Int Iw [ ], /* workspace of size iwlen, iwlen [0..pfree-1]

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_info ============================================================ */ // AMD/Source/amd_info: print output statistics for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* User-callable. Prints the output statistics for AMD. See amd.h /* User-callable. Prints the output statistics for AMD. See amd.h
* for details. If the Info array is not present, nothing is printed. * for details. If the Info array is not present, nothing is printed.
@ -15,16 +14,16 @@
#include "amd_internal.h" #include "amd_internal.h"
#define PRI(format,x) { if (x >= 0) { PRINTF ((format, x)) ; }} #define PRI(format,x) { if (x >= 0) { SUITESPARSE_PRINTF ((format, x)) ; }}
GLOBAL void AMD_info void AMD_info
( (
double Info [ ] double Info [ ]
) )
{ {
double n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ; double n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ;
PRINTF (("\nAMD version %d.%d.%d, %s, results:\n", SUITESPARSE_PRINTF (("\nAMD version %d.%d.%d, %s, results:\n",
AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ; AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ;
if (!Info) if (!Info)
@ -40,26 +39,26 @@ GLOBAL void AMD_info
lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ; lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ;
/* AMD return status */ /* AMD return status */
PRINTF ((" status: ")) ; SUITESPARSE_PRINTF ((" status: ")) ;
if (Info [AMD_STATUS] == AMD_OK) if (Info [AMD_STATUS] == AMD_OK)
{ {
PRINTF (("OK\n")) ; SUITESPARSE_PRINTF (("OK\n")) ;
} }
else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY) else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY)
{ {
PRINTF (("out of memory\n")) ; SUITESPARSE_PRINTF (("out of memory\n")) ;
} }
else if (Info [AMD_STATUS] == AMD_INVALID) else if (Info [AMD_STATUS] == AMD_INVALID)
{ {
PRINTF (("invalid matrix\n")) ; SUITESPARSE_PRINTF (("invalid matrix\n")) ;
} }
else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED) else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED)
{ {
PRINTF (("OK, but jumbled\n")) ; SUITESPARSE_PRINTF (("OK, but jumbled\n")) ;
} }
else else
{ {
PRINTF (("unknown\n")) ; SUITESPARSE_PRINTF (("unknown\n")) ;
} }
/* statistics about the input matrix */ /* statistics about the input matrix */
@ -82,7 +81,7 @@ GLOBAL void AMD_info
Info [AMD_NCMPA]) ; Info [AMD_NCMPA]) ;
/* statistics about the ordering quality */ /* statistics about the ordering quality */
PRINTF (("\n" SUITESPARSE_PRINTF (("\n"
" The following approximate statistics are for a subsequent\n" " The following approximate statistics are for a subsequent\n"
" factorization of A(P,P) + A(P,P)'. They are slight upper\n" " factorization of A(P,P) + A(P,P)'. They are slight upper\n"
" bounds if there are no dense rows/columns in A+A', and become\n" " bounds if there are no dense rows/columns in A+A', and become\n"
@ -105,7 +104,7 @@ GLOBAL void AMD_info
if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0) if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0)
{ {
PRINTF (("\n" SUITESPARSE_PRINTF (("\n"
" chol flop count for real A, sqrt counted as 1 flop: %.20g\n" " chol flop count for real A, sqrt counted as 1 flop: %.20g\n"
" LDL' flop count for real A: %.20g\n" " LDL' flop count for real A: %.20g\n"
" LDL' flop count for complex A: %.20g\n" " LDL' flop count for complex A: %.20g\n"

View File

@ -1,31 +1,16 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === amd_internal.h ====================================================== */ // AMD/Include/amd_internal.h: internal definitions for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2023, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* This file is for internal use in AMD itself, and does not normally need to /* This file is for internal use in AMD itself, and does not normally need to
* be included in user code (it is included in UMFPACK, however). All others * be included in user code (it is included in UMFPACK, however). All others
* should use amd.h instead. * should use amd.h instead.
*
* The following compile-time definitions affect how AMD is compiled.
*
* -DNPRINT
*
* Disable all printing. stdio.h will not be included. Printing can
* be re-enabled at run-time by setting the global pointer amd_printf
* to printf (or mexPrintf for a MATLAB mexFunction).
*
* -DNMALLOC
*
* No memory manager is defined at compile-time. You MUST define the
* function pointers amd_malloc, amd_free, amd_realloc, and
* amd_calloc at run-time for AMD to work properly.
*/ */
/* ========================================================================= */ /* ========================================================================= */
@ -52,38 +37,10 @@
#define NDEBUG #define NDEBUG
#endif #endif
/* // To enable debugging, uncomment the following line:
To enable debugging, uncomment the following line: // #undef NDEBUG
#undef NDEBUG
*/
/* ------------------------------------------------------------------------- */ #include "ngspice/amd.h"
/* ANSI include files */
/* ------------------------------------------------------------------------- */
/* from stdlib.h: size_t, malloc, free, realloc, and calloc */
#include <stdlib.h>
#if !defined(NPRINT) || !defined(NDEBUG)
/* from stdio.h: printf. Not included if NPRINT is defined at compile time.
* fopen and fscanf are used when debugging. */
#include <stdio.h>
#endif
/* from limits.h: INT_MAX and LONG_MAX */
#include <limits.h>
/* from math.h: sqrt */
#include <math.h>
/* ------------------------------------------------------------------------- */
/* MATLAB include files (only if being used in or via MATLAB) */
/* ------------------------------------------------------------------------- */
#ifdef MATLAB_MEX_FILE
#include "matrix.h"
#include "mex.h"
#endif
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* basic definitions */ /* basic definitions */
@ -105,13 +62,7 @@
#undef EMPTY #undef EMPTY
#endif #endif
#ifdef GLOBAL #define PRIVATE static
#undef GLOBAL
#endif
#ifdef PRIVATE
#undef PRIVATE
#endif
/* FLIP is a "negation about -1", and is used to mark an integer i that is /* FLIP is a "negation about -1", and is used to mark an integer i that is
* normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY
@ -139,36 +90,28 @@
#define TRUE (1) #define TRUE (1)
#define FALSE (0) #define FALSE (0)
#define PRIVATE static
#define GLOBAL
#define EMPTY (-1) #define EMPTY (-1)
/* Note that Linux's gcc 2.96 defines NULL as ((void *) 0), but other */
/* compilers (even gcc 2.95.2 on Solaris) define NULL as 0 or (0). We */
/* need to use the ANSI standard value of 0. */
#ifdef NULL
#undef NULL
#endif
#define NULL 0
/* largest value of size_t */ /* largest value of size_t */
#ifndef SIZE_T_MAX #ifndef SIZE_T_MAX
#ifdef SIZE_MAX
/* C99 only */
#define SIZE_T_MAX SIZE_MAX
#else
#define SIZE_T_MAX ((size_t) (-1)) #define SIZE_T_MAX ((size_t) (-1))
#endif #endif
#endif
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* integer type for AMD: int or UF_long */ /* integer type for AMD: int32_t or int64_t */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* define UF_long */
#include "ngspice/UFconfig.h"
#if defined (DLONG) || defined (ZLONG) #if defined (DLONG) || defined (ZLONG)
#define Int UF_long #define Int int64_t
#define ID UF_long_id #define UInt uint64_t
#define Int_MAX UF_long_max #define ID "%" PRId64
#define Int_MAX INT64_MAX
#define AMD_order amd_l_order #define AMD_order amd_l_order
#define AMD_defaults amd_l_defaults #define AMD_defaults amd_l_defaults
@ -187,9 +130,10 @@
#else #else
#define Int int #define Int int32_t
#define UInt uint32_t
#define ID "%d" #define ID "%d"
#define Int_MAX INT_MAX #define Int_MAX INT32_MAX
#define AMD_order amd_order #define AMD_order amd_order
#define AMD_defaults amd_defaults #define AMD_defaults amd_defaults
@ -208,24 +152,11 @@
#endif #endif
/* ========================================================================= */
/* === PRINTF macro ======================================================== */
/* ========================================================================= */
/* All output goes through the PRINTF macro. */
#define PRINTF(params) { if (amd_printf != NULL) (void) amd_printf params ; }
/* ------------------------------------------------------------------------- */
/* AMD routine definitions (user-callable) */
/* ------------------------------------------------------------------------- */
#include "ngspice/amd.h"
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* AMD routine definitions (not user-callable) */ /* AMD routine definitions (not user-callable) */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
GLOBAL size_t AMD_aat size_t AMD_aat
( (
Int n, Int n,
const Int Ap [ ], const Int Ap [ ],
@ -235,7 +166,7 @@ GLOBAL size_t AMD_aat
double Info [ ] double Info [ ]
) ; ) ;
GLOBAL void AMD_1 void AMD_1
( (
Int n, Int n,
const Int Ap [ ], const Int Ap [ ],
@ -249,7 +180,7 @@ GLOBAL void AMD_1
double Info [ ] double Info [ ]
) ; ) ;
GLOBAL void AMD_postorder void AMD_postorder
( (
Int nn, Int nn,
Int Parent [ ], Int Parent [ ],
@ -261,7 +192,7 @@ GLOBAL void AMD_postorder
Int Stack [ ] Int Stack [ ]
) ; ) ;
GLOBAL Int AMD_post_tree Int AMD_post_tree
( (
Int root, Int root,
Int k, Int k,
@ -274,7 +205,7 @@ GLOBAL Int AMD_post_tree
#endif #endif
) ; ) ;
GLOBAL void AMD_preprocess void AMD_preprocess
( (
Int n, Int n,
const Int Ap [ ], const Int Ap [ ],
@ -294,15 +225,11 @@ GLOBAL void AMD_preprocess
/* from assert.h: assert macro */ /* from assert.h: assert macro */
#include <assert.h> #include <assert.h>
#ifndef EXTERN extern Int AMD_debug ;
#define EXTERN extern
#endif
EXTERN Int AMD_debug ; void AMD_debug_init ( char *s ) ;
GLOBAL void AMD_debug_init ( char *s ) ; void AMD_dump
GLOBAL void AMD_dump
( (
Int n, Int n,
Int Pe [ ], Int Pe [ ],
@ -331,11 +258,11 @@ GLOBAL void AMD_dump
#define ASSERT(expression) (assert (expression)) #define ASSERT(expression) (assert (expression))
#endif #endif
#define AMD_DEBUG0(params) { PRINTF (params) ; } #define AMD_DEBUG0(params) { SUITESPARSE_PRINTF (params) ; }
#define AMD_DEBUG1(params) { if (AMD_debug >= 1) PRINTF (params) ; } #define AMD_DEBUG1(params) { if (AMD_debug >= 1) SUITESPARSE_PRINTF (params) ; }
#define AMD_DEBUG2(params) { if (AMD_debug >= 2) PRINTF (params) ; } #define AMD_DEBUG2(params) { if (AMD_debug >= 2) SUITESPARSE_PRINTF (params) ; }
#define AMD_DEBUG3(params) { if (AMD_debug >= 3) PRINTF (params) ; } #define AMD_DEBUG3(params) { if (AMD_debug >= 3) SUITESPARSE_PRINTF (params) ; }
#define AMD_DEBUG4(params) { if (AMD_debug >= 4) PRINTF (params) ; } #define AMD_DEBUG4(params) { if (AMD_debug >= 4) SUITESPARSE_PRINTF (params) ; }
#else #else

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_order =========================================================== */ // AMD/Source/amd_order: user-callable AMD ordering method
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* User-callable AMD minimum degree ordering routine. See amd.h for /* User-callable AMD minimum degree ordering routine. See amd.h for
* documentation. * documentation.
@ -19,7 +18,7 @@
/* === AMD_order =========================================================== */ /* === AMD_order =========================================================== */
/* ========================================================================= */ /* ========================================================================= */
GLOBAL Int AMD_order int AMD_order
( (
Int n, Int n,
const Int Ap [ ], const Int Ap [ ],
@ -72,9 +71,9 @@ GLOBAL Int AMD_order
return (AMD_INVALID) ; return (AMD_INVALID) ;
} }
/* check if n or nz will cause size_t overflow */ /* check if n or nz will cause integer overflow */
if (((size_t) n) >= SIZE_T_MAX / sizeof (Int) if (((size_t) n) >= Int_MAX / sizeof (Int)
|| ((size_t) nz) >= SIZE_T_MAX / sizeof (Int)) || ((size_t) nz) >= Int_MAX / sizeof (Int))
{ {
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
return (AMD_OUT_OF_MEMORY) ; /* problem too large */ return (AMD_OUT_OF_MEMORY) ; /* problem too large */
@ -90,15 +89,16 @@ GLOBAL Int AMD_order
} }
/* allocate two size-n integer workspaces */ /* allocate two size-n integer workspaces */
Len = amd_malloc (n * sizeof (Int)) ; size_t nn = (size_t) n ;
Pinv = amd_malloc (n * sizeof (Int)) ; Len = SuiteSparse_malloc (nn, sizeof (Int)) ;
Pinv = SuiteSparse_malloc (nn, sizeof (Int)) ;
mem += n ; mem += n ;
mem += n ; mem += n ;
if (!Len || !Pinv) if (!Len || !Pinv)
{ {
/* :: out of memory :: */ /* :: out of memory :: */
amd_free (Len) ; SuiteSparse_free (Len) ;
amd_free (Pinv) ; SuiteSparse_free (Pinv) ;
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
return (AMD_OUT_OF_MEMORY) ; return (AMD_OUT_OF_MEMORY) ;
} }
@ -107,17 +107,17 @@ GLOBAL Int AMD_order
{ {
/* sort the input matrix and remove duplicate entries */ /* sort the input matrix and remove duplicate entries */
AMD_DEBUG1 (("Matrix is jumbled\n")) ; AMD_DEBUG1 (("Matrix is jumbled\n")) ;
Rp = amd_malloc ((n+1) * sizeof (Int)) ; Rp = SuiteSparse_malloc (nn+1, sizeof (Int)) ;
Ri = amd_malloc (MAX (nz,1) * sizeof (Int)) ; Ri = SuiteSparse_malloc (nz, sizeof (Int)) ;
mem += (n+1) ; mem += (n+1) ;
mem += MAX (nz,1) ; mem += MAX (nz,1) ;
if (!Rp || !Ri) if (!Rp || !Ri)
{ {
/* :: out of memory :: */ /* :: out of memory :: */
amd_free (Rp) ; SuiteSparse_free (Rp) ;
amd_free (Ri) ; SuiteSparse_free (Ri) ;
amd_free (Len) ; SuiteSparse_free (Len) ;
amd_free (Pinv) ; SuiteSparse_free (Pinv) ;
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
return (AMD_OUT_OF_MEMORY) ; return (AMD_OUT_OF_MEMORY) ;
} }
@ -153,24 +153,23 @@ GLOBAL Int AMD_order
slen += nzaat/5 ; /* add elbow room */ slen += nzaat/5 ; /* add elbow room */
for (i = 0 ; ok && i < 7 ; i++) for (i = 0 ; ok && i < 7 ; i++)
{ {
ok = ((slen + n) > slen) ; /* check for size_t overflow */ ok = ((slen + nn) > slen) ; /* check for size_t overflow */
slen += n ; /* size-n elbow room, 6 size-n work */ slen += nn ; /* size-n elbow room, 6 size-n work */
} }
mem += slen ; mem += slen ;
ok = ok && (slen < SIZE_T_MAX / sizeof (Int)) ; /* check for overflow */ ok = ok && (slen < SIZE_T_MAX / sizeof (Int)) ; /* check for overflow */
ok = ok && (slen < Int_MAX) ; /* S[i] for Int i must be OK */
if (ok) if (ok)
{ {
S = amd_malloc (slen * sizeof (Int)) ; S = SuiteSparse_malloc (slen, sizeof (Int)) ;
} }
AMD_DEBUG1 (("slen %g\n", (double) slen)) ; AMD_DEBUG1 (("slen %g\n", (double) slen)) ;
if (!S) if (!S)
{ {
/* :: out of memory :: (or problem too large) */ /* :: out of memory :: (or problem too large) */
amd_free (Rp) ; SuiteSparse_free (Rp) ;
amd_free (Ri) ; SuiteSparse_free (Ri) ;
amd_free (Len) ; SuiteSparse_free (Len) ;
amd_free (Pinv) ; SuiteSparse_free (Pinv) ;
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
return (AMD_OUT_OF_MEMORY) ; return (AMD_OUT_OF_MEMORY) ;
} }
@ -190,11 +189,11 @@ GLOBAL Int AMD_order
/* free the workspace */ /* free the workspace */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
amd_free (Rp) ; SuiteSparse_free (Rp) ;
amd_free (Ri) ; SuiteSparse_free (Ri) ;
amd_free (Len) ; SuiteSparse_free (Len) ;
amd_free (Pinv) ; SuiteSparse_free (Pinv) ;
amd_free (S) ; SuiteSparse_free (S) ;
if (info) Info [AMD_STATUS] = status ; if (info) Info [AMD_STATUS] = status ;
return (status) ; /* successful ordering */ return (status) ; /* successful ordering */
} }

View File

@ -1,19 +1,18 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_post_tree ======================================================= */ // AMD/Source/amd_post_tree: post-ordering of a single etree
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* Post-ordering of a supernodal elimination tree. */ /* Post-ordering of a supernodal elimination tree. */
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL Int AMD_post_tree Int AMD_post_tree
( (
Int root, /* root of the tree */ Int root, /* root of the tree */
Int k, /* start numbering at k */ Int k, /* start numbering at k */
@ -42,7 +41,7 @@ GLOBAL Int AMD_post_tree
/* recursive version (Stack [ ] is not used): */ /* recursive version (Stack [ ] is not used): */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* this is simple, but can caouse stack overflow if nn is large */ /* this is simple, but can cause stack overflow if nn is large */
i = root ; i = root ;
for (f = Child [i] ; f != EMPTY ; f = Sibling [f]) for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
{ {

View File

@ -1,19 +1,18 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_postorder ======================================================= */ // AMD/Source/amd_postorder: post-order the assembly tree from AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* Perform a postordering (via depth-first search) of an assembly tree. */ /* Perform a postordering (via depth-first search) of an assembly tree. */
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL void AMD_postorder void AMD_postorder
( (
/* inputs, not modified on output: */ /* inputs, not modified on output: */
Int nn, /* nodes are in the range 0..nn-1 */ Int nn, /* nodes are in the range 0..nn-1 */

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_preprocess ====================================================== */ // AMD/Source/amd_preprocess: sort, remove duplicates, transpose a matrix
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* Sorts, removes duplicate entries, and transposes from the nonzero pattern of /* Sorts, removes duplicate entries, and transposes from the nonzero pattern of
* a column-form matrix A, to obtain the matrix R. The input matrix can have * a column-form matrix A, to obtain the matrix R. The input matrix can have
@ -19,15 +18,11 @@
#include "amd_internal.h" #include "amd_internal.h"
/* ========================================================================= */
/* === AMD_preprocess ====================================================== */
/* ========================================================================= */
/* AMD_preprocess does not check its input for errors or allocate workspace. /* AMD_preprocess does not check its input for errors or allocate workspace.
* On input, the condition (AMD_valid (n,n,Ap,Ai) != AMD_INVALID) must hold. * On input, the condition (AMD_valid (n,n,Ap,Ai) != AMD_INVALID) must hold.
*/ */
GLOBAL void AMD_preprocess void AMD_preprocess
( (
Int n, /* input matrix: A is n-by-n */ Int n, /* input matrix: A is n-by-n */
const Int Ap [ ], /* size n+1 */ const Int Ap [ ], /* size n+1 */

View File

@ -1,13 +1,12 @@
/* ========================================================================= */ //------------------------------------------------------------------------------
/* === AMD_valid =========================================================== */ // AMD/Source/amd_valid: check if a matrix is valid for AMD
/* ========================================================================= */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */ // AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, and
/* AMD, Copyright (c) Timothy A. Davis, */ // Iain S. Duff. All Rights Reserved.
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ // SPDX-License-Identifier: BSD-3-clause
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
/* web: http://www.cise.ufl.edu/research/sparse/amd */ //------------------------------------------------------------------------------
/* ------------------------------------------------------------------------- */
/* Check if a column-form matrix is valid or not. The matrix A is /* Check if a column-form matrix is valid or not. The matrix A is
* n_row-by-n_col. The row indices of entries in column j are in * n_row-by-n_col. The row indices of entries in column j are in
@ -36,7 +35,7 @@
#include "amd_internal.h" #include "amd_internal.h"
GLOBAL Int AMD_valid int AMD_valid
( (
/* inputs, not modified on output: */ /* inputs, not modified on output: */
Int n_row, /* A is n_row-by-n_col */ Int n_row, /* A is n_row-by-n_col */
@ -45,7 +44,8 @@ GLOBAL Int AMD_valid
const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */ const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */
) )
{ {
Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ; Int nz, j, p1, p2, ilast, i, p ;
int result = AMD_OK ;
if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL) if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
{ {

View File

@ -1,23 +1,24 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === btf_internal include file ============================================ */ // BTF/Include/btf_internsl.h: internal include file for BTF
/* ========================================================================== */ //------------------------------------------------------------------------------
// BTF, Copyright (c) 2004-2023, University of Florida. All Rights Reserved.
// Author: Timothy A. Davis.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
#ifndef _BTF_INTERNAL_H #ifndef _BTF_INTERNAL_H
#define _BTF_INTERNAL_H #define _BTF_INTERNAL_H
/*
* Copyright (c) 2004-2007. Tim Davis, University of Florida,
* with support from Sandia National Laboratories. All Rights Reserved.
*/
/* Not to be included in any user program. */ /* Not to be included in any user program. */
#ifdef DLONG #ifdef DLONG
#define Int UF_long #define Int int64_t
#define Int_id UF_long_id #define Int_id "%" PRId64
#define BTF(name) btf_l_ ## name #define BTF(name) btf_l_ ## name
#else #else
#define Int int #define Int int32_t
#define Int_id "%d" #define Int_id "%d"
#define BTF(name) btf_ ## name #define BTF(name) btf_ ## name
#endif #endif

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === BTF_ORDER ============================================================ */ // BTF/Source/btf_order: permute a matrix to block triangular form
/* ========================================================================== */ //------------------------------------------------------------------------------
// BTF, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Author: Timothy A. Davis.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Find a permutation P and Q to permute a square sparse matrix into upper block /* Find a permutation P and Q to permute a square sparse matrix into upper block
* triangular form. A(P,Q) will contain a zero-free diagonal if A has * triangular form. A(P,Q) will contain a zero-free diagonal if A has
@ -21,9 +27,6 @@
* might not be equal to the structural rank. * might not be equal to the structural rank.
* *
* See btf.h for more details. * See btf.h for more details.
*
* Copyright (c) 2004-2007. Tim Davis, University of Florida,
* with support from Sandia National Laboratories. All Rights Reserved.
*/ */
#include "ngspice/btf.h" #include "ngspice/btf.h"

View File

@ -1,13 +1,16 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === BTF_STRONGCOMP ======================================================= */ // BTF/Source/btf_strongcomp: strongly connected components
/* ========================================================================== */ //------------------------------------------------------------------------------
// BTF, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Author: Timothy A. Davis.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Finds the strongly connected components of a graph, or equivalently, permutes /* Finds the strongly connected components of a graph, or equivalently, permutes
* the matrix into upper block triangular form. See btf.h for more details. * the matrix into upper block triangular form. See btf.h for more details.
* Input matrix and Q are not checked on input. * Input matrix and Q are not checked on input.
*
* Copyright (c) 2004-2007. Tim Davis, University of Florida,
* with support from Sandia National Laboratories. All Rights Reserved.
*/ */
#include "ngspice/btf.h" #include "ngspice/btf.h"

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === colamd/symamd - a sparse matrix column ordering algorithm ============ */ // COLAMD/Source/colamd.c: column approximate minimum degree ordering
/* ========================================================================== */ //------------------------------------------------------------------------------
// COLAMD, Copyright (c) 1998-2022, Timothy A. Davis and Stefan Larimore,
// All Rights Reserved.
// SPDX-License-Identifier: BSD-3-clause
//------------------------------------------------------------------------------
/* COLAMD / SYMAMD /* COLAMD / SYMAMD
@ -35,7 +41,7 @@
Authors: Authors:
The authors of the code itself are Stefan I. Larimore and Timothy A. The authors of the code itself are Stefan I. Larimore and Timothy A.
Davis (davis at cise.ufl.edu), University of Florida. The algorithm was Davis (DrTimothyAldenDavis@gmail.com). The algorithm was
developed in collaboration with John Gilbert, Xerox PARC, and Esmond developed in collaboration with John Gilbert, Xerox PARC, and Esmond
Ng, Oak Ridge National Laboratory. Ng, Oak Ridge National Laboratory.
@ -46,44 +52,15 @@
Copyright and License: Copyright and License:
Copyright (c) 1998-2007, Timothy A. Davis, All Rights Reserved. Copyright (c) 1998-2022, Timothy A. Davis, All Rights Reserved.
COLAMD is also available under alternate licenses, contact T. Davis COLAMD is also available under alternate licenses, contact T. Davis
for details. for details.
This library is free software; you can redistribute it and/or See COLAMD/Doc/License.txt for the license.
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
Permission is hereby granted to use or copy this program under the
terms of the GNU LGPL, provided that the Copyright, this License,
and the Availability of the original version is retained on all copies.
User documentation of any code that uses this code or any modified
version of this code must cite the Copyright, this License, the
Availability note, and "Used by permission." Permission to modify
the code and to distribute modified code is granted, provided the
Copyright, this License, and the Availability note are retained,
and a notice that the code was modified is included.
Availability: Availability:
The colamd/symamd library is available at The colamd/symamd library is available at http://www.suitesparse.com
http://www.cise.ufl.edu/research/sparse/colamd/
This is the http://www.cise.ufl.edu/research/sparse/colamd/colamd.c
file. It requires the colamd.h file. It is required by the colamdmex.c
and symamdmex.c files, for the MATLAB interface to colamd and symamd.
Appears as ACM Algorithm 836. Appears as ACM Algorithm 836.
See the ChangeLog file for changes since Version 1.0. See the ChangeLog file for changes since Version 1.0.
@ -105,9 +82,9 @@
/* === Description of user-callable routines ================================ */ /* === Description of user-callable routines ================================ */
/* ========================================================================== */ /* ========================================================================== */
/* COLAMD includes both int and UF_long versions of all its routines. The /* COLAMD includes both int32_t and int64_t versions of all its routines.
* description below is for the int version. For UF_long, all int arguments The description below is for the int32_t version. For int64_t, all
* become UF_long. UF_long is normally defined as long, except for WIN64. int32_t arguments become int64_t.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
colamd_recommended: colamd_recommended:
@ -116,9 +93,9 @@
C syntax: C syntax:
#include "colamd.h" #include "colamd.h"
size_t colamd_recommended (int nnz, int n_row, int n_col) ; size_t colamd_recommended (int32_t nnz, int32_t n_row, int32_t n_col) ;
size_t colamd_l_recommended (UF_long nnz, UF_long n_row, size_t colamd_l_recommended (int64_t nnz,
UF_long n_col) ; int64_t n_row, int64_t n_col) ;
Purpose: Purpose:
@ -127,19 +104,16 @@
is optional. Not needed for symamd, which dynamically allocates is optional. Not needed for symamd, which dynamically allocates
its own memory. its own memory.
Note that in v2.4 and earlier, these routines returned int or long.
They now return a value of type size_t.
Arguments (all input arguments): Arguments (all input arguments):
int nnz ; Number of nonzeros in the matrix A. This must int32_t nnz ; Number of nonzeros in the matrix A. This must
be the same value as p [n_col] in the call to be the same value as p [n_col] in the call to
colamd - otherwise you will get a wrong value colamd - otherwise you will get a wrong value
of the recommended memory to use. of the recommended memory to use.
int n_row ; Number of rows in the matrix A. int32_t n_row ; Number of rows in the matrix A.
int n_col ; Number of columns in the matrix A. int32_t n_col ; Number of columns in the matrix A.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
colamd_set_defaults: colamd_set_defaults:
@ -199,11 +173,12 @@
C syntax: C syntax:
#include "colamd.h" #include "colamd.h"
int colamd (int n_row, int n_col, int Alen, int *A, int *p, int colamd (int32_t n_row, int32_t n_col, int32_t Alen, int32_t *A, int32_t *p,
double knobs [COLAMD_KNOBS], int stats [COLAMD_STATS]) ; double knobs [COLAMD_KNOBS], int32_t stats [COLAMD_STATS]) ;
UF_long colamd_l (UF_long n_row, UF_long n_col, UF_long Alen, int colamd_l (int64_t n_row,
UF_long *A, UF_long *p, double knobs [COLAMD_KNOBS], int64_t n_col, int64_t Alen,
UF_long stats [COLAMD_STATS]) ; int64_t *A, int64_t *p, double knobs
[COLAMD_KNOBS], int64_t stats [COLAMD_STATS]) ;
Purpose: Purpose:
@ -218,19 +193,19 @@
Arguments: Arguments:
int n_row ; Input argument. int32_t n_row ; Input argument.
Number of rows in the matrix A. Number of rows in the matrix A.
Restriction: n_row >= 0. Restriction: n_row >= 0.
Colamd returns FALSE if n_row is negative. Colamd returns FALSE if n_row is negative.
int n_col ; Input argument. int32_t n_col ; Input argument.
Number of columns in the matrix A. Number of columns in the matrix A.
Restriction: n_col >= 0. Restriction: n_col >= 0.
Colamd returns FALSE if n_col is negative. Colamd returns FALSE if n_col is negative.
int Alen ; Input argument. int32_t Alen ; Input argument.
Restriction (see note): Restriction (see note):
Alen >= 2*nnz + 6*(n_col+1) + 4*(n_row+1) + n_col Alen >= 2*nnz + 6*(n_col+1) + 4*(n_row+1) + n_col
@ -246,7 +221,7 @@
for integer overflow, and thus is not recommended. Use for integer overflow, and thus is not recommended. Use
the colamd_recommended routine instead. the colamd_recommended routine instead.
int A [Alen] ; Input argument, undefined on output. int32_t A [Alen] ; Input argument, undefined on output.
A is an integer array of size Alen. Alen must be at least as A is an integer array of size Alen. Alen must be at least as
large as the bare minimum value given above, but this is very large as the bare minimum value given above, but this is very
@ -270,7 +245,7 @@
The contents of A are modified during ordering, and are The contents of A are modified during ordering, and are
undefined on output. undefined on output.
int p [n_col+1] ; Both input and output argument. int32_t p [n_col+1] ; Both input and output argument.
p is an integer array of size n_col+1. On input, it holds the p is an integer array of size n_col+1. On input, it holds the
"pointers" for the column form of the matrix A. Column c of "pointers" for the column form of the matrix A. Column c of
@ -294,7 +269,7 @@
See colamd_set_defaults for a description. See colamd_set_defaults for a description.
int stats [COLAMD_STATS] ; Output argument. int32_t stats [COLAMD_STATS] ; Output argument.
Statistics on the ordering, and error status. Statistics on the ordering, and error status.
See colamd.h for related definitions. See colamd.h for related definitions.
@ -379,8 +354,7 @@
Example: Example:
See http://www.cise.ufl.edu/research/sparse/colamd/example.c See colamd_example.c for a complete example.
for a complete example.
To order the columns of a 5-by-4 matrix with 11 nonzero entries in To order the columns of a 5-by-4 matrix with 11 nonzero entries in
the following nonzero pattern the following nonzero pattern
@ -395,9 +369,9 @@
#include "colamd.h" #include "colamd.h"
#define ALEN 100 #define ALEN 100
int A [ALEN] = {0, 1, 4, 2, 4, 0, 1, 2, 3, 1, 3} ; int32_t A [ALEN] = {0, 1, 4, 2, 4, 0, 1, 2, 3, 1, 3} ;
int p [ ] = {0, 3, 5, 9, 11} ; int32_t p [ ] = {0, 3, 5, 9, 11} ;
int stats [COLAMD_STATS] ; int32_t stats [COLAMD_STATS] ;
colamd (5, 4, ALEN, A, p, (double *) NULL, stats) ; colamd (5, 4, ALEN, A, p, (double *) NULL, stats) ;
The permutation is returned in the array p, and A is destroyed. The permutation is returned in the array p, and A is destroyed.
@ -409,12 +383,13 @@
C syntax: C syntax:
#include "colamd.h" #include "colamd.h"
int symamd (int n, int *A, int *p, int *perm, int symamd (int32_t n, int32_t *A, int32_t *p, int32_t *perm,
double knobs [COLAMD_KNOBS], int stats [COLAMD_STATS], double knobs [COLAMD_KNOBS], int32_t stats [COLAMD_STATS],
void (*allocate) (size_t, size_t), void (*release) (void *)) ;
UF_long symamd_l (UF_long n, UF_long *A, UF_long *p, UF_long *perm,
double knobs [COLAMD_KNOBS], UF_long stats [COLAMD_STATS],
void (*allocate) (size_t, size_t), void (*release) (void *)) ; void (*allocate) (size_t, size_t), void (*release) (void *)) ;
int symamd_l (int64_t n, int64_t *A,
int64_t *p, int64_t *perm, double knobs
[COLAMD_KNOBS], int64_t stats [COLAMD_STATS], void
(*allocate) (size_t, size_t), void (*release) (void *)) ;
Purpose: Purpose:
@ -433,13 +408,13 @@
Arguments: Arguments:
int n ; Input argument. int32_t n ; Input argument.
Number of rows and columns in the symmetrix matrix A. Number of rows and columns in the symmetrix matrix A.
Restriction: n >= 0. Restriction: n >= 0.
Symamd returns FALSE if n is negative. Symamd returns FALSE if n is negative.
int A [nnz] ; Input argument. int32_t A [nnz] ; Input argument.
A is an integer array of size nnz, where nnz = p [n]. A is an integer array of size nnz, where nnz = p [n].
@ -455,7 +430,7 @@
The contents of A are not modified. The contents of A are not modified.
int p [n+1] ; Input argument. int32_t p [n+1] ; Input argument.
p is an integer array of size n+1. On input, it holds the p is an integer array of size n+1. On input, it holds the
"pointers" for the column form of the matrix A. Column c of "pointers" for the column form of the matrix A. Column c of
@ -467,7 +442,7 @@
The contents of p are not modified. The contents of p are not modified.
int perm [n+1] ; Output argument. int32_t perm [n+1] ; Output argument.
On output, if symamd returns TRUE, the array perm holds the On output, if symamd returns TRUE, the array perm holds the
permutation P, where perm [0] is the first index in the new permutation P, where perm [0] is the first index in the new
@ -482,7 +457,7 @@
See colamd_set_defaults for a description. See colamd_set_defaults for a description.
int stats [COLAMD_STATS] ; Output argument. int32_t stats [COLAMD_STATS] ; Output argument.
Statistics on the ordering, and error status. Statistics on the ordering, and error status.
See colamd.h for related definitions. See colamd.h for related definitions.
@ -580,8 +555,8 @@
C syntax: C syntax:
#include "colamd.h" #include "colamd.h"
colamd_report (int stats [COLAMD_STATS]) ; colamd_report (int32_t stats [COLAMD_STATS]) ;
colamd_l_report (UF_long stats [COLAMD_STATS]) ; colamd_l_report (int64_t stats [COLAMD_STATS]) ;
Purpose: Purpose:
@ -591,7 +566,7 @@
Arguments: Arguments:
int stats [COLAMD_STATS] ; Input only. Statistics from colamd. int32_t stats [COLAMD_STATS] ; Input only. Statistics from colamd.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
@ -601,8 +576,8 @@
C syntax: C syntax:
#include "colamd.h" #include "colamd.h"
symamd_report (int stats [COLAMD_STATS]) ; symamd_report (int32_t stats [COLAMD_STATS]) ;
symamd_l_report (UF_long stats [COLAMD_STATS]) ; symamd_l_report (int64_t stats [COLAMD_STATS]) ;
Purpose: Purpose:
@ -612,7 +587,7 @@
Arguments: Arguments:
int stats [COLAMD_STATS] ; Input only. Statistics from symamd. int32_t stats [COLAMD_STATS] ; Input only. Statistics from symamd.
*/ */
@ -664,34 +639,21 @@
/* ========================================================================== */ /* ========================================================================== */
#include "ngspice/colamd.h" #include "ngspice/colamd.h"
#include <limits.h>
#include <math.h>
#ifdef MATLAB_MEX_FILE
#include "mex.h"
#include "matrix.h"
#endif /* MATLAB_MEX_FILE */
#if !defined (NPRINT) || !defined (NDEBUG)
#include <stdio.h>
#endif
#ifndef NULL #ifndef NULL
#define NULL ((void *) 0) #define NULL ((void *) 0)
#endif #endif
/* ========================================================================== */ /* ========================================================================== */
/* === int or UF_long ======================================================= */ /* === int32_t or int64_t ============================================== */
/* ========================================================================== */ /* ========================================================================== */
/* define UF_long */
#include "ngspice/UFconfig.h"
#ifdef DLONG #ifdef DLONG
#define Int UF_long #define Int int64_t
#define ID UF_long_id #define UInt uint64_t
#define Int_MAX UF_long_max #define ID "%" PRId64
#define Int_MAX INT64_MAX
#define COLAMD_recommended colamd_l_recommended #define COLAMD_recommended colamd_l_recommended
#define COLAMD_set_defaults colamd_l_set_defaults #define COLAMD_set_defaults colamd_l_set_defaults
@ -702,9 +664,10 @@
#else #else
#define Int int #define Int int32_t
#define UInt uint32_t
#define ID "%d" #define ID "%d"
#define Int_MAX INT_MAX #define Int_MAX INT32_MAX
#define COLAMD_recommended colamd_recommended #define COLAMD_recommended colamd_recommended
#define COLAMD_set_defaults colamd_set_defaults #define COLAMD_set_defaults colamd_set_defaults
@ -776,8 +739,7 @@ typedef struct Colamd_Row_struct
/* === Definitions ========================================================== */ /* === Definitions ========================================================== */
/* ========================================================================== */ /* ========================================================================== */
/* Routines are either PUBLIC (user-callable) or PRIVATE (not user-callable) */ /* Routines are either user-callable or PRIVATE (not user-callable) */
#define PUBLIC
#define PRIVATE static #define PRIVATE static
#define DENSE_DEGREE(alpha,n) \ #define DENSE_DEGREE(alpha,n) \
@ -835,9 +797,6 @@ typedef struct Colamd_Row_struct
#define INDEX(i) (i) #define INDEX(i) (i)
#endif #endif
/* All output goes through the PRINTF macro. */
#define PRINTF(params) { if (colamd_printf != NULL) (void) colamd_printf params ; }
/* ========================================================================== */ /* ========================================================================== */
/* === Prototypes of PRIVATE routines ======================================= */ /* === Prototypes of PRIVATE routines ======================================= */
/* ========================================================================== */ /* ========================================================================== */
@ -941,11 +900,11 @@ PRIVATE void print_report
PRIVATE Int colamd_debug = 0 ; /* debug print level */ PRIVATE Int colamd_debug = 0 ; /* debug print level */
#define DEBUG0(params) { PRINTF (params) ; } #define DEBUG0(params) { SUITESPARSE_PRINTF (params) ; }
#define DEBUG1(params) { if (colamd_debug >= 1) PRINTF (params) ; } #define DEBUG1(params) { if (colamd_debug >= 1) SUITESPARSE_PRINTF (params) ; }
#define DEBUG2(params) { if (colamd_debug >= 2) PRINTF (params) ; } #define DEBUG2(params) { if (colamd_debug >= 2) SUITESPARSE_PRINTF (params) ; }
#define DEBUG3(params) { if (colamd_debug >= 3) PRINTF (params) ; } #define DEBUG3(params) { if (colamd_debug >= 3) SUITESPARSE_PRINTF (params) ; }
#define DEBUG4(params) { if (colamd_debug >= 4) PRINTF (params) ; } #define DEBUG4(params) { if (colamd_debug >= 4) SUITESPARSE_PRINTF (params) ; }
#ifdef MATLAB_MEX_FILE #ifdef MATLAB_MEX_FILE
#define ASSERT(expression) (mxAssert ((expression), "")) #define ASSERT(expression) (mxAssert ((expression), ""))
@ -1062,7 +1021,7 @@ static size_t t_mult (size_t a, size_t k, int *ok)
((t_mult (t_add (n_row, 1, ok), sizeof (Colamd_Row), ok) / sizeof (Int))) ((t_mult (t_add (n_row, 1, ok), sizeof (Colamd_Row), ok) / sizeof (Int)))
PUBLIC size_t COLAMD_recommended /* returns recommended value of Alen. */ size_t COLAMD_recommended /* returns recommended value of Alen. */
( (
/* === Parameters ======================================================= */ /* === Parameters ======================================================= */
@ -1084,11 +1043,9 @@ PUBLIC size_t COLAMD_recommended /* returns recommended value of Alen. */
s = t_add (s, r, &ok) ; s = t_add (s, r, &ok) ;
s = t_add (s, n_col, &ok) ; /* elbow room */ s = t_add (s, n_col, &ok) ; /* elbow room */
s = t_add (s, nnz/5, &ok) ; /* elbow room */ s = t_add (s, nnz/5, &ok) ; /* elbow room */
ok = ok && (s < Int_MAX) ;
return (ok ? s : 0) ; return (ok ? s : 0) ;
} }
/* ========================================================================== */ /* ========================================================================== */
/* === colamd_set_defaults ================================================== */ /* === colamd_set_defaults ================================================== */
/* ========================================================================== */ /* ========================================================================== */
@ -1116,7 +1073,7 @@ PUBLIC size_t COLAMD_recommended /* returns recommended value of Alen. */
*/ */
PUBLIC void COLAMD_set_defaults void COLAMD_set_defaults
( (
/* === Parameters ======================================================= */ /* === Parameters ======================================================= */
@ -1145,7 +1102,7 @@ PUBLIC void COLAMD_set_defaults
/* === symamd =============================================================== */ /* === symamd =============================================================== */
/* ========================================================================== */ /* ========================================================================== */
PUBLIC Int SYMAMD_MAIN /* return TRUE if OK, FALSE otherwise */ int SYMAMD_MAIN /* return TRUE if OK, FALSE otherwise */
( (
/* === Parameters ======================================================= */ /* === Parameters ======================================================= */
@ -1465,7 +1422,7 @@ PUBLIC Int SYMAMD_MAIN /* return TRUE if OK, FALSE otherwise */
(AQ)'(AQ) = LL' remains sparse. (AQ)'(AQ) = LL' remains sparse.
*/ */
PUBLIC Int COLAMD_MAIN /* returns TRUE if successful, FALSE otherwise*/ int COLAMD_MAIN /* returns TRUE if successful, FALSE otherwise*/
( (
/* === Parameters ======================================================= */ /* === Parameters ======================================================= */
@ -1583,7 +1540,7 @@ PUBLIC Int COLAMD_MAIN /* returns TRUE if successful, FALSE otherwise*/
need = t_add (need, Col_size, &ok) ; need = t_add (need, Col_size, &ok) ;
need = t_add (need, Row_size, &ok) ; need = t_add (need, Row_size, &ok) ;
if (!ok || need > (size_t) Alen || need > Int_MAX) if (!ok || need > (size_t) Alen)
{ {
/* not enough space in array A to perform the ordering */ /* not enough space in array A to perform the ordering */
stats [COLAMD_STATUS] = COLAMD_ERROR_A_too_small ; stats [COLAMD_STATUS] = COLAMD_ERROR_A_too_small ;
@ -1634,7 +1591,7 @@ PUBLIC Int COLAMD_MAIN /* returns TRUE if successful, FALSE otherwise*/
/* === colamd_report ======================================================== */ /* === colamd_report ======================================================== */
/* ========================================================================== */ /* ========================================================================== */
PUBLIC void COLAMD_report void COLAMD_report
( (
Int stats [COLAMD_STATS] Int stats [COLAMD_STATS]
) )
@ -1647,7 +1604,7 @@ PUBLIC void COLAMD_report
/* === symamd_report ======================================================== */ /* === symamd_report ======================================================== */
/* ========================================================================== */ /* ========================================================================== */
PUBLIC void SYMAMD_report void SYMAMD_report
( (
Int stats [COLAMD_STATS] Int stats [COLAMD_STATS]
) )
@ -2226,7 +2183,7 @@ PRIVATE Int find_ordering /* return the number of garbage collections */
Int col ; /* a column index */ Int col ; /* a column index */
Int max_score ; /* maximum possible score */ Int max_score ; /* maximum possible score */
Int cur_score ; /* score of current column */ Int cur_score ; /* score of current column */
unsigned Int hash ; /* hash value for supernode detection */ UInt hash ; /* hash value for supernode detection */
Int head_column ; /* head of hash bucket */ Int head_column ; /* head of hash bucket */
Int first_col ; /* first column in hash bucket */ Int first_col ; /* first column in hash bucket */
Int tag_mark ; /* marker value for mark array */ Int tag_mark ; /* marker value for mark array */
@ -3188,12 +3145,13 @@ PRIVATE void print_report
Int i1, i2, i3 ; Int i1, i2, i3 ;
PRINTF (("\n%s version %d.%d, %s: ", method, SUITESPARSE_PRINTF (("\n%s version %d.%d.%d, %s: ", method,
COLAMD_MAIN_VERSION, COLAMD_SUB_VERSION, COLAMD_DATE)) ; COLAMD_MAIN_VERSION, COLAMD_SUB_VERSION, COLAMD_SUBSUB_VERSION,
COLAMD_DATE)) ;
if (!stats) if (!stats)
{ {
PRINTF (("No statistics available.\n")) ; SUITESPARSE_PRINTF (("No statistics available.\n")) ;
return ; return ;
} }
@ -3203,11 +3161,11 @@ PRIVATE void print_report
if (stats [COLAMD_STATUS] >= 0) if (stats [COLAMD_STATUS] >= 0)
{ {
PRINTF (("OK. ")) ; SUITESPARSE_PRINTF (("OK. ")) ;
} }
else else
{ {
PRINTF (("ERROR. ")) ; SUITESPARSE_PRINTF (("ERROR. ")) ;
} }
switch (stats [COLAMD_STATUS]) switch (stats [COLAMD_STATUS])
@ -3215,87 +3173,99 @@ PRIVATE void print_report
case COLAMD_OK_BUT_JUMBLED: case COLAMD_OK_BUT_JUMBLED:
PRINTF(("Matrix has unsorted or duplicate row indices.\n")) ; SUITESPARSE_PRINTF((
"Matrix has unsorted or duplicate row indices.\n")) ;
PRINTF(("%s: number of duplicate or out-of-order row indices: %d\n", SUITESPARSE_PRINTF((
method, i3)) ; "%s: number of duplicate or out-of-order row indices: %d\n",
method, i3)) ;
PRINTF(("%s: last seen duplicate or out-of-order row index: %d\n", SUITESPARSE_PRINTF((
method, INDEX (i2))) ; "%s: last seen duplicate or out-of-order row index: %d\n",
method, INDEX (i2))) ;
PRINTF(("%s: last seen in column: %d", SUITESPARSE_PRINTF((
method, INDEX (i1))) ; "%s: last seen in column: %d",
method, INDEX (i1))) ;
/* no break - fall through to next case instead */ /* no break - fall through to next case instead */
case COLAMD_OK: case COLAMD_OK:
PRINTF(("\n")) ; SUITESPARSE_PRINTF(("\n")) ;
PRINTF(("%s: number of dense or empty rows ignored: %d\n", SUITESPARSE_PRINTF((
method, stats [COLAMD_DENSE_ROW])) ; "%s: number of dense or empty rows ignored: %d\n",
method, stats [COLAMD_DENSE_ROW])) ;
PRINTF(("%s: number of dense or empty columns ignored: %d\n", SUITESPARSE_PRINTF((
method, stats [COLAMD_DENSE_COL])) ; "%s: number of dense or empty columns ignored: %d\n",
method, stats [COLAMD_DENSE_COL])) ;
PRINTF(("%s: number of garbage collections performed: %d\n", SUITESPARSE_PRINTF((
method, stats [COLAMD_DEFRAG_COUNT])) ; "%s: number of garbage collections performed: %d\n",
method, stats [COLAMD_DEFRAG_COUNT])) ;
break ; break ;
case COLAMD_ERROR_A_not_present: case COLAMD_ERROR_A_not_present:
PRINTF(("Array A (row indices of matrix) not present.\n")) ; SUITESPARSE_PRINTF((
"Array A (row indices of matrix) not present.\n")) ;
break ; break ;
case COLAMD_ERROR_p_not_present: case COLAMD_ERROR_p_not_present:
PRINTF(("Array p (column pointers for matrix) not present.\n")) ; SUITESPARSE_PRINTF((
"Array p (column pointers for matrix) not present.\n")) ;
break ; break ;
case COLAMD_ERROR_nrow_negative: case COLAMD_ERROR_nrow_negative:
PRINTF(("Invalid number of rows (%d).\n", i1)) ; SUITESPARSE_PRINTF(("Invalid number of rows (%d).\n", i1)) ;
break ; break ;
case COLAMD_ERROR_ncol_negative: case COLAMD_ERROR_ncol_negative:
PRINTF(("Invalid number of columns (%d).\n", i1)) ; SUITESPARSE_PRINTF(("Invalid number of columns (%d).\n", i1)) ;
break ; break ;
case COLAMD_ERROR_nnz_negative: case COLAMD_ERROR_nnz_negative:
PRINTF(("Invalid number of nonzero entries (%d).\n", i1)) ; SUITESPARSE_PRINTF((
"Invalid number of nonzero entries (%d).\n", i1)) ;
break ; break ;
case COLAMD_ERROR_p0_nonzero: case COLAMD_ERROR_p0_nonzero:
PRINTF(("Invalid column pointer, p [0] = %d, must be zero.\n", i1)); SUITESPARSE_PRINTF((
"Invalid column pointer, p [0] = %d, must be zero.\n", i1));
break ; break ;
case COLAMD_ERROR_A_too_small: case COLAMD_ERROR_A_too_small:
PRINTF(("Array A too small.\n")) ; SUITESPARSE_PRINTF(("Array A too small.\n")) ;
PRINTF((" Need Alen >= %d, but given only Alen = %d.\n", SUITESPARSE_PRINTF((
i1, i2)) ; " Need Alen >= %d, but given only Alen = %d.\n",
i1, i2)) ;
break ; break ;
case COLAMD_ERROR_col_length_negative: case COLAMD_ERROR_col_length_negative:
PRINTF SUITESPARSE_PRINTF
(("Column %d has a negative number of nonzero entries (%d).\n", (("Column %d has a negative number of nonzero entries (%d).\n",
INDEX (i1), i2)) ; INDEX (i1), i2)) ;
break ; break ;
case COLAMD_ERROR_row_index_out_of_bounds: case COLAMD_ERROR_row_index_out_of_bounds:
PRINTF SUITESPARSE_PRINTF
(("Row index (row %d) out of bounds (%d to %d) in column %d.\n", (("Row index (row %d) out of bounds (%d to %d) in column %d.\n",
INDEX (i2), INDEX (0), INDEX (i3-1), INDEX (i1))) ; INDEX (i2), INDEX (0), INDEX (i3-1), INDEX (i1))) ;
break ; break ;
case COLAMD_ERROR_out_of_memory: case COLAMD_ERROR_out_of_memory:
PRINTF(("Out of memory.\n")) ; SUITESPARSE_PRINTF(("Out of memory.\n")) ;
break ; break ;
/* v2.4: internal-error case deleted */ /* v2.4: internal-error case deleted */

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === klu ================================================================== */ // KLU/Source/klu: primary factorization and forward/backsolve kernels for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* KLU: factorizes P*A into L*U, using the Gilbert-Peierls algorithm [1], with /* KLU: factorizes P*A into L*U, using the Gilbert-Peierls algorithm [1], with
* optional symmetric pruning by Eisenstat and Liu [2]. The code is by Tim * optional symmetric pruning by Eisenstat and Liu [2]. The code is by Tim
@ -33,12 +39,6 @@
* Ai [Ap [j] ... Ap [j+1]-1] and the same range of indices in Ax holds the * Ai [Ap [j] ... Ap [j+1]-1] and the same range of indices in Ax holds the
* numerical values. No duplicate entries are allowed. * numerical values. No duplicate entries are allowed.
* *
* Copyright 2004-2009, Tim Davis. All rights reserved. See the README
* file for details on permitted use. Note that no code from The MathWorks,
* Inc, or from SuperLU, or from any other source appears here. The code is
* written from scratch, from the algorithmic description in Gilbert & Peierls'
* and Eisenstat & Liu's journal papers [1,2].
*
* If an input permutation Q is provided, the factorization L*U = A (P,Q) * If an input permutation Q is provided, the factorization L*U = A (P,Q)
* is computed, where P is determined by partial pivoting, and Q is the input * is computed, where P is determined by partial pivoting, and Q is the input
* ordering. If the pivot tolerance is less than 1, the "diagonal" entry that * ordering. If the pivot tolerance is less than 1, the "diagonal" entry that
@ -116,11 +116,11 @@ size_t KLU_kernel_factor /* 0 if failure, size of LU if OK */
{ {
Lsize = -Lsize ; Lsize = -Lsize ;
Lsize = MAX (Lsize, 1.0) ; Lsize = MAX (Lsize, 1.0) ;
lsize = Lsize * anz + n ; lsize = (int) Lsize * anz + n ;
} }
else else
{ {
lsize = Lsize ; lsize = (int) Lsize ;
} }
usize = lsize ; usize = lsize ;
@ -129,7 +129,7 @@ size_t KLU_kernel_factor /* 0 if failure, size of LU if OK */
usize = MAX (n+1, usize) ; usize = MAX (n+1, usize) ;
maxlnz = (((double) n) * ((double) n) + ((double) n)) / 2. ; maxlnz = (((double) n) * ((double) n) + ((double) n)) / 2. ;
maxlnz = MIN (maxlnz, ((double) INT_MAX)) ; maxlnz = MIN (maxlnz, ((double) Int_MAX)) ;
lsize = MIN ((int) maxlnz, lsize) ; lsize = MIN ((int) maxlnz, lsize) ;
usize = MIN ((int) maxlnz, usize) ; usize = MIN ((int) maxlnz, usize) ;

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === klu_analyze ========================================================== */ // KLU/Source/klu_analyze: symbolic analysis
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Order the matrix using BTF (or not), and then AMD, COLAMD, the natural /* Order the matrix using BTF (or not), and then AMD, COLAMD, the natural
* ordering, or the user-provided-function on the blocks. Does not support * ordering, or the user-provided-function on the blocks. Does not support
@ -306,12 +312,6 @@ static KLU_symbolic *order_and_analyze /* returns NULL if error, or a valid
return (NULL) ; return (NULL) ;
} }
/* AMD memory management routines */
amd_malloc = Common->malloc_memory ;
amd_free = Common->free_memory ;
amd_calloc = Common->calloc_memory ;
amd_realloc = Common->realloc_memory ;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* allocate workspace for BTF permutation */ /* allocate workspace for BTF permutation */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === klu_analyze_given ==================================================== */ // KLU/Source/klu_analyze_given: symbolic analysis with given permutation
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Given an input permutation P and Q, create the Symbolic object. BTF can /* Given an input permutation P and Q, create the Symbolic object. BTF can
* be done to modify the user's P and Q (does not perform the max transversal; * be done to modify the user's P and Q (does not perform the max transversal;
@ -41,12 +47,6 @@ KLU_symbolic *KLU_alloc_symbolic
if (n <= 0 || Ap == NULL || Ai == NULL) if (n <= 0 || Ap == NULL || Ai == NULL)
{ {
if (n == 0)
{
Common->status = KLU_EMPTY_MATRIX ;
return (NULL) ;
}
/* Ap and Ai must be present, and n must be > 0 */ /* Ap and Ai must be present, and n must be > 0 */
Common->status = KLU_INVALID ; Common->status = KLU_INVALID ;
return (NULL) ; return (NULL) ;

View File

@ -1,12 +1,18 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_defaults ========================================================= */ // KLU/Source/klu_defaults: default parameters for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Sets default parameters for KLU */ /* Sets default parameters for KLU */
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_defaults int KLU_defaults
( (
KLU_common *Common KLU_common *Common
) )
@ -18,8 +24,8 @@ Int KLU_defaults
/* parameters */ /* parameters */
Common->tol = 0.001 ; /* pivot tolerance for diagonal */ Common->tol = 0.001 ; /* pivot tolerance for diagonal */
Common->memgrow = 10; /* realloc size ratio increase for LU factors */ Common->memgrow = 1.2; /* realloc size ratio increase for LU factors */
Common->initmem_amd = 10 ; /* init. mem with AMD: c*nnz(L) + n */ Common->initmem_amd = 1.2 ; /* init. mem with AMD: c*nnz(L) + n */
Common->initmem = 10 ; /* init. mem otherwise: c*nnz(A) + n */ Common->initmem = 10 ; /* init. mem otherwise: c*nnz(A) + n */
Common->btf = TRUE ; /* use BTF pre-ordering, or not */ Common->btf = TRUE ; /* use BTF pre-ordering, or not */
Common->maxwork = 0 ; /* no limit to work done by btf_order */ Common->maxwork = 0 ; /* no limit to work done by btf_order */
@ -31,12 +37,6 @@ Int KLU_defaults
* 1: sum, 2: max */ * 1: sum, 2: max */
Common->halt_if_singular = TRUE ; /* quick halt if matrix is singular */ Common->halt_if_singular = TRUE ; /* quick halt if matrix is singular */
/* memory management routines */
Common->malloc_memory = malloc ;
Common->calloc_memory = calloc ;
Common->free_memory = free ;
Common->realloc_memory = realloc ;
/* user ordering function and optional argument */ /* user ordering function and optional argument */
Common->user_order = NULL ; Common->user_order = NULL ;
Common->user_data = NULL ; Common->user_data = NULL ;

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_diagnostics ====================================================== */ // KLU/Source/klu_diagnostics: linear algebraic diagnostics
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Linear algebraic diagnostics: /* Linear algebraic diagnostics:
* KLU_rgrowth: reciprocal pivot growth, takes O(|A|+|U|) time * KLU_rgrowth: reciprocal pivot growth, takes O(|A|+|U|) time
@ -22,7 +28,7 @@
* rgrowth = min (max (abs ((R \ A (p,q)) - F))) ./ max (abs (U))) * rgrowth = min (max (abs ((R \ A (p,q)) - F))) ./ max (abs (U)))
*/ */
Int KLU_rgrowth /* return TRUE if successful, FALSE otherwise */ int KLU_rgrowth /* return TRUE if successful, FALSE otherwise */
( (
Int *Ap, Int *Ap,
Int *Ai, Int *Ai,
@ -120,6 +126,8 @@ Int KLU_rgrowth /* return TRUE if successful, FALSE otherwise */
} }
} }
/* Ui is set but not used. This is OK, because otherwise the macro
would have to be redesigned. */
GET_POINTER (LU, Uip, Ulen, Ui, Ux, j, len) ; GET_POINTER (LU, Uip, Ulen, Ui, Ux, j, len) ;
for (k = 0 ; k < len ; k++) for (k = 0 ; k < len ; k++)
{ {
@ -167,7 +175,7 @@ Int KLU_rgrowth /* return TRUE if successful, FALSE otherwise */
* 1-norm pseudospectra, SIAM J. Matrix Anal. Appl., 21(4):1185-1201, 2000. * 1-norm pseudospectra, SIAM J. Matrix Anal. Appl., 21(4):1185-1201, 2000.
*/ */
Int KLU_condest /* return TRUE if successful, FALSE otherwise */ int KLU_condest /* return TRUE if successful, FALSE otherwise */
( (
Int Ap [ ], Int Ap [ ],
double Ax [ ], double Ax [ ],
@ -178,8 +186,7 @@ Int KLU_condest /* return TRUE if successful, FALSE otherwise */
{ {
double xj, Xmax, csum, anorm, ainv_norm, est_old, est_new, abs_value ; double xj, Xmax, csum, anorm, ainv_norm, est_old, est_new, abs_value ;
Entry *Udiag, *Aentry, *X, *S ; Entry *Udiag, *Aentry, *X, *S ;
Int *R ; Int i, j, jmax, jnew, pend, n ;
Int nblocks, i, j, jmax, jnew, pend, n ;
#ifndef COMPLEX #ifndef COMPLEX
Int unchanged ; Int unchanged ;
#endif #endif
@ -212,8 +219,6 @@ Int KLU_condest /* return TRUE if successful, FALSE otherwise */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
n = Symbolic->n ; n = Symbolic->n ;
nblocks = Symbolic->nblocks ;
R = Symbolic->R ;
Udiag = Numeric->Udiag ; Udiag = Numeric->Udiag ;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -411,7 +416,7 @@ Int KLU_condest /* return TRUE if successful, FALSE otherwise */
/* Compute the flop count for the LU factorization (in Common->flops) */ /* Compute the flop count for the LU factorization (in Common->flops) */
Int KLU_flops /* return TRUE if successful, FALSE otherwise */ int KLU_flops /* return TRUE if successful, FALSE otherwise */
( (
KLU_symbolic *Symbolic, KLU_symbolic *Symbolic,
KLU_numeric *Numeric, KLU_numeric *Numeric,
@ -422,7 +427,7 @@ Int KLU_flops /* return TRUE if successful, FALSE otherwise */
Int *R, *Ui, *Uip, *Llen, *Ulen ; Int *R, *Ui, *Uip, *Llen, *Ulen ;
Unit **LUbx ; Unit **LUbx ;
Unit *LU ; Unit *LU ;
Int k, ulen, p, n, nk, block, nblocks, k1 ; Int k, ulen, p, nk, block, nblocks, k1 ;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* check inputs */ /* check inputs */
@ -444,7 +449,6 @@ Int KLU_flops /* return TRUE if successful, FALSE otherwise */
/* get the contents of the Symbolic object */ /* get the contents of the Symbolic object */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
n = Symbolic->n ;
R = Symbolic->R ; R = Symbolic->R ;
nblocks = Symbolic->nblocks ; nblocks = Symbolic->nblocks ;
@ -496,7 +500,7 @@ Int KLU_flops /* return TRUE if successful, FALSE otherwise */
* pivot, or a NaN pivot, rcond will be zero. Takes O(n) time. * pivot, or a NaN pivot, rcond will be zero. Takes O(n) time.
*/ */
Int KLU_rcond /* return TRUE if successful, FALSE otherwise */ int KLU_rcond /* return TRUE if successful, FALSE otherwise */
( (
KLU_symbolic *Symbolic, /* input, not modified */ KLU_symbolic *Symbolic, /* input, not modified */
KLU_numeric *Numeric, /* input, not modified */ KLU_numeric *Numeric, /* input, not modified */

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_dump ============================================================= */ // KLU/Source/klu_dump: debug routines for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Debug routines for klu. Only used when NDEBUG is not defined at /* Debug routines for klu. Only used when NDEBUG is not defined at
* compile-time. * compile-time.
@ -110,14 +116,19 @@ Int KLU_valid_LU (Int n, Int flag_test_start_ptr, Int Xip [ ],
for (j = 0 ; j < n ; j++) for (j = 0 ; j < n ; j++)
{ {
p1 = Xip [j] ; p1 = Xip [j] ;
p2 = Xip [j+1] ; PRINTF (("\nColumn of factor: %d p1: %d ", j, p1)) ;
PRINTF (("\nColumn: %d p1: %d p2: %d\n", j, p1, p2)) ; if (j < n-1)
if (p1 > p2)
{ {
/* column pointers must be ascending */ p2 = Xip [j+1] ;
PRINTF (("column %d pointer bad\n", j)) ; PRINTF (("p2: %d ", p2)) ;
return (FALSE) ; if (p1 > p2)
{
/* column pointers must be ascending */
PRINTF (("column %d pointer bad\n", j)) ;
return (FALSE) ;
}
} }
PRINTF (("\n")) ;
GET_POINTER (LU, Xip, Xlen, Xi, Xx, j, len) ; GET_POINTER (LU, Xip, Xlen, Xi, Xx, j, len) ;
for (p = 0 ; p < len ; p++) for (p = 0 ; p < len ; p++)
{ {

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_extract ========================================================== */ // KLU/Source/klu_extract: extract the KLU factorization
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Extract KLU factorization into conventional compressed-column matrices. /* Extract KLU factorization into conventional compressed-column matrices.
* If any output array is NULL, that part of the LU factorization is not * If any output array is NULL, that part of the LU factorization is not
@ -11,7 +17,7 @@
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_extract /* returns TRUE if successful, FALSE otherwise */ int KLU_extract /* returns TRUE if successful, FALSE otherwise */
( (
/* inputs: */ /* inputs: */
KLU_numeric *Numeric, KLU_numeric *Numeric,

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_factor =========================================================== */ // KLU/Source/klu_factor: sparse LU factorization
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Factor the matrix, after ordering and analyzing it with KLU_analyze /* Factor the matrix, after ordering and analyzing it with KLU_analyze
* or KLU_analyze_given. * or KLU_analyze_given.
@ -341,14 +347,14 @@ static void factor2
#ifndef NDEBUG #ifndef NDEBUG
{ {
PRINTF (("\n ############# KLU_BTF_FACTOR done, nblocks %d\n",nblocks)); PRINTF (("\n ------------ KLU_BTF_FACTOR done, nblocks %d\n",nblocks));
Entry ss, *Udiag = Numeric->Udiag ; Entry ss, *Udiag = Numeric->Udiag ;
for (block = 0 ; block < nblocks && Common->status == KLU_OK ; block++) for (block = 0 ; block < nblocks && Common->status == KLU_OK ; block++)
{ {
k1 = R [block] ; k1 = R [block] ;
k2 = R [block+1] ; k2 = R [block+1] ;
nk = k2 - k1 ; nk = k2 - k1 ;
PRINTF (("\n======================KLU_factor output: k1 %d k2 %d nk %d\n",k1,k2,nk)) ; PRINTF (("\n== KLU_factor output: k1 %d k2 %d nk %d\n",k1,k2,nk)) ;
if (nk == 1) if (nk == 1)
{ {
PRINTF (("singleton ")) ; PRINTF (("singleton ")) ;
@ -394,7 +400,6 @@ KLU_numeric *KLU_factor /* returns NULL if error, or a valid
) )
{ {
Int n, nzoff, nblocks, maxblock, k, ok = TRUE ; Int n, nzoff, nblocks, maxblock, k, ok = TRUE ;
Int *R ;
KLU_numeric *Numeric ; KLU_numeric *Numeric ;
size_t n1, nzoff1, s, b6, n3 ; size_t n1, nzoff1, s, b6, n3 ;
@ -402,10 +407,6 @@ KLU_numeric *KLU_factor /* returns NULL if error, or a valid
{ {
return (NULL) ; return (NULL) ;
} }
if (Common->status == KLU_EMPTY_MATRIX)
{
return (NULL) ;
}
Common->status = KLU_OK ; Common->status = KLU_OK ;
Common->numerical_rank = EMPTY ; Common->numerical_rank = EMPTY ;
Common->singular_col = EMPTY ; Common->singular_col = EMPTY ;
@ -425,7 +426,6 @@ KLU_numeric *KLU_factor /* returns NULL if error, or a valid
nzoff = Symbolic->nzoff ; nzoff = Symbolic->nzoff ;
nblocks = Symbolic->nblocks ; nblocks = Symbolic->nblocks ;
maxblock = Symbolic->maxblock ; maxblock = Symbolic->maxblock ;
R = Symbolic->R ;
PRINTF (("KLU_factor: n %d nzoff %d nblocks %d maxblock %d\n", PRINTF (("KLU_factor: n %d nzoff %d nblocks %d maxblock %d\n",
n, nzoff, nblocks, maxblock)) ; n, nzoff, nblocks, maxblock)) ;

View File

@ -1,12 +1,18 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_free_numeric ===================================================== */ // KLU/Source/klu_free_numeric: free the KLU numeric factorization
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Free the KLU Numeric object. */ /* Free the KLU Numeric object. */
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_free_numeric int KLU_free_numeric
( (
KLU_numeric **NumericHandle, KLU_numeric **NumericHandle,
KLU_common *Common KLU_common *Common

View File

@ -1,12 +1,18 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_free_symbolic ==================================================== */ // KLU/Source/klu_free_symbolic: free the KLU symbolic analysis
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Free the KLU Symbolic object. */ /* Free the KLU Symbolic object. */
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_free_symbolic int KLU_free_symbolic
( (
KLU_symbolic **SymbolicHandle, KLU_symbolic **SymbolicHandle,
KLU_common *Common KLU_common *Common

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU/Include/klu_internal.h =========================================== */ // KLU/Include/klu_internal.h: internal include file for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2023, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* For internal use in KLU routines only, not for user programs */ /* For internal use in KLU routines only, not for user programs */
@ -31,11 +37,7 @@
/* ========================================================================== */ /* ========================================================================== */
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#undef ASSERT #undef ASSERT
#ifndef NDEBUG #ifndef NDEBUG
@ -47,7 +49,7 @@
#define SCALAR_IS_NAN(x) ((x) != (x)) #define SCALAR_IS_NAN(x) ((x) != (x))
/* true if an integer (stored in double x) would overflow (or if x is NaN) */ /* true if an integer (stored in double x) would overflow (or if x is NaN) */
#define INT_OVERFLOW(x) ((!((x) * (1.0+1e-8) <= (double) INT_MAX)) \ #define INT_OVERFLOW(x) ((!((x) * (1.0+1e-8) <= (double) Int_MAX)) \
|| SCALAR_IS_NAN (x)) || SCALAR_IS_NAN (x))
#undef TRUE #undef TRUE
@ -58,7 +60,7 @@
#undef FLIP #undef FLIP
#ifndef NPRINT #ifndef NPRINT
#define PRINTF(s) { printf s ; } ; #define PRINTF(s) SUITESPARSE_PRINTF (s)
#else #else
#define PRINTF(s) #define PRINTF(s)
#endif #endif

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_kernel =========================================================== */ // KLU/Source/klu_kernel: primary sparse LU factorization kernel
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Sparse left-looking LU factorization, with partial pivoting. Based on /* Sparse left-looking LU factorization, with partial pivoting. Based on
* Gilbert & Peierl's method, with a non-recursive DFS and with Eisenstat & * Gilbert & Peierl's method, with a non-recursive DFS and with Eisenstat &
@ -119,15 +125,7 @@ static Int dfs
/* Finds the pattern of x, for the solution of Lx=b */ /* Finds the pattern of x, for the solution of Lx=b */
/* ========================================================================== */ static Int lsolve_symbolic
/* === construct_column ===================================================== */
/* ========================================================================== */
/* Construct the kth column of A, and the off-diagonal part, if requested.
* Scatter the numerical values into the workspace X, and construct the
* corresponding column of the off-diagonal matrix. */
static Int lsolve_symbolic_and_construct_column
( (
/* input, not modified on output: */ /* input, not modified on output: */
Int n, /* L is n-by-n, where n >= 0 */ Int n, /* L is n-by-n, where n >= 0 */
@ -158,29 +156,11 @@ static Int lsolve_symbolic_and_construct_column
/* ---- the following are only used in the BTF case --- */ /* ---- the following are only used in the BTF case --- */
Int k1, /* the block of A is from k1 to k2-1 */ Int k1, /* the block of A is from k1 to k2-1 */
Int PSinv [ ], /* inverse of P from symbolic factorization */ Int PSinv [ ] /* inverse of P from symbolic factorization */
/* inputs, not modified on output */
Entry Ax [ ],
/* zero on input, modified on output */
Entry X [ ],
/* ---- the following are only used in the BTF case --- */
/* inputs, not modified on output */
double Rs [ ], /* scale factors for A */
Int scale, /* 0: no scaling, nonzero: scale the rows with Rs */
/* inputs, modified on output */
Int Offp [ ], /* off-diagonal matrix (modified by this routine) */
Int Offi [ ],
Entry Offx [ ]
) )
{ {
Entry aik ;
Int *Lik ; Int *Lik ;
Int i, p, pend, oldcol, kglobal, poff, oldrow, top, l_length ; Int i, p, pend, oldcol, kglobal, top, l_length ;
top = n ; top = n ;
l_length = 0 ; l_length = 0 ;
@ -191,24 +171,94 @@ static Int lsolve_symbolic_and_construct_column
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
kglobal = k + k1 ; /* column k of the block is col kglobal of A */ kglobal = k + k1 ; /* column k of the block is col kglobal of A */
poff = Offp [kglobal] ; /* start of off-diagonal column */
oldcol = Q [kglobal] ; /* Q must be present for BTF case */ oldcol = Q [kglobal] ; /* Q must be present for BTF case */
pend = Ap [oldcol+1] ; pend = Ap [oldcol+1] ;
for (p = Ap [oldcol] ; p < pend ; p++)
{
i = PSinv [Ai [p]] - k1 ;
if (i < 0) continue ; /* skip entry outside the block */
/* (i,k) is an entry in the block. start a DFS at node i */
PRINTF (("\n ===== DFS at node %d in b, inew: %d\n", i, Pinv [i])) ;
if (Flag [i] != k)
{
if (Pinv [i] >= 0)
{
top = dfs (i, k, Pinv, Llen, Lip, Stack, Flag,
Lpend, top, LU, Lik, &l_length, Ap_pos) ;
}
else
{
/* i is not pivotal, and not flagged. Flag and put in L */
Flag [i] = k ;
Lik [l_length] = i ;
l_length++;
}
}
}
/* If Llen [k] is zero, the matrix is structurally singular */
Llen [k] = l_length ;
return (top) ;
}
/* ========================================================================== */
/* === construct_column ===================================================== */
/* ========================================================================== */
/* Construct the kth column of A, and the off-diagonal part, if requested.
* Scatter the numerical values into the workspace X, and construct the
* corresponding column of the off-diagonal matrix. */
static void construct_column
(
/* inputs, not modified on output */
Int k, /* the column of A (or the column of the block) to get */
Int Ap [ ],
Int Ai [ ],
Entry Ax [ ],
Int Q [ ], /* column pre-ordering */
/* zero on input, modified on output */
Entry X [ ],
/* ---- the following are only used in the BTF case --- */
/* inputs, not modified on output */
Int k1, /* the block of A is from k1 to k2-1 */
Int PSinv [ ], /* inverse of P from symbolic factorization */
double Rs [ ], /* scale factors for A */
Int scale, /* 0: no scaling, nonzero: scale the rows with Rs */
/* inputs, modified on output */
Int Offp [ ], /* off-diagonal matrix (modified by this routine) */
Int Offi [ ],
Entry Offx [ ]
)
{
Entry aik ;
Int i, p, pend, oldcol, kglobal, poff, oldrow ;
/* ---------------------------------------------------------------------- */
/* Scale and scatter the column into X. */
/* ---------------------------------------------------------------------- */
kglobal = k + k1 ; /* column k of the block is col kglobal of A */
poff = Offp [kglobal] ; /* start of off-diagonal column */
oldcol = Q [kglobal] ;
pend = Ap [oldcol+1] ;
if (scale <= 0) if (scale <= 0)
{ {
/* no scaling */
for (p = Ap [oldcol] ; p < pend ; p++) for (p = Ap [oldcol] ; p < pend ; p++)
{ {
oldrow = Ai [p] ; oldrow = Ai [p] ;
i = PSinv [oldrow] - k1 ; i = PSinv [oldrow] - k1 ;
aik = Ax [p] ;
if (i < 0) if (i < 0)
{ {
/* ---------------------------------------------------------------------- */
/* Scatter the column into X. */
/* ---------------------------------------------------------------------- */
aik = Ax [p] ;
/* this is an entry in the off-diagonal part */ /* this is an entry in the off-diagonal part */
Offi [poff] = oldrow ; Offi [poff] = oldrow ;
Offx [poff] = aik ; Offx [poff] = aik ;
@ -216,31 +266,6 @@ static Int lsolve_symbolic_and_construct_column
} }
else else
{ {
/* (i,k) is an entry in the block. start a DFS at node i */
PRINTF (("\n ===== DFS at node %d in b, inew: %d\n", i, Pinv [i])) ;
if (Flag [i] != k)
{
if (Pinv [i] >= 0)
{
top = dfs (i, k, Pinv, Llen, Lip, Stack, Flag,
Lpend, top, LU, Lik, &l_length, Ap_pos) ;
}
else
{
/* i is not pivotal, and not flagged. Flag and put in L */
Flag [i] = k ;
Lik [l_length] = i ;
l_length++;
}
}
/* ---------------------------------------------------------------------- */
/* Scatter the column into X. */
/* ---------------------------------------------------------------------- */
/* no scaling */
aik = Ax [p] ;
/* (i,k) is an entry in the block. scatter into X */ /* (i,k) is an entry in the block. scatter into X */
X [i] = aik ; X [i] = aik ;
} }
@ -248,20 +273,15 @@ static Int lsolve_symbolic_and_construct_column
} }
else else
{ {
/* row scaling */
for (p = Ap [oldcol] ; p < pend ; p++) for (p = Ap [oldcol] ; p < pend ; p++)
{ {
oldrow = Ai [p] ; oldrow = Ai [p] ;
i = PSinv [oldrow] - k1 ; i = PSinv [oldrow] - k1 ;
aik = Ax [p] ;
SCALE_DIV (aik, Rs [oldrow]) ;
if (i < 0) if (i < 0)
{ {
/* ---------------------------------------------------------------------- */
/* Scale and scatter the column into X. */
/* ---------------------------------------------------------------------- */
/* row scaling */
aik = Ax [p] ;
SCALE_DIV (aik, Rs [oldrow]) ;
/* this is an entry in the off-diagonal part */ /* this is an entry in the off-diagonal part */
Offi [poff] = oldrow ; Offi [poff] = oldrow ;
Offx [poff] = aik ; Offx [poff] = aik ;
@ -269,32 +289,6 @@ static Int lsolve_symbolic_and_construct_column
} }
else else
{ {
/* (i,k) is an entry in the block. start a DFS at node i */
PRINTF (("\n ===== DFS at node %d in b, inew: %d\n", i, Pinv [i])) ;
if (Flag [i] != k)
{
if (Pinv [i] >= 0)
{
top = dfs (i, k, Pinv, Llen, Lip, Stack, Flag,
Lpend, top, LU, Lik, &l_length, Ap_pos) ;
}
else
{
/* i is not pivotal, and not flagged. Flag and put in L */
Flag [i] = k ;
Lik [l_length] = i ;
l_length++;
}
}
/* ---------------------------------------------------------------------- */
/* Scale and scatter the column into X. */
/* ---------------------------------------------------------------------- */
/* row scaling */
aik = Ax [p] ;
SCALE_DIV (aik, Rs [oldrow]) ;
/* (i,k) is an entry in the block. scatter into X */ /* (i,k) is an entry in the block. scatter into X */
X [i] = aik ; X [i] = aik ;
} }
@ -302,10 +296,6 @@ static Int lsolve_symbolic_and_construct_column
} }
Offp [kglobal+1] = poff ; /* start of the next col of off-diag part */ Offp [kglobal+1] = poff ; /* start of the next col of off-diag part */
/* If Llen [k] is zero, the matrix is structurally singular */
Llen [k] = l_length ;
return (top) ;
} }
@ -555,6 +545,7 @@ static void prune
Int p, i, j, p2, phead, ptail, llen, ulen ; Int p, i, j, p2, phead, ptail, llen, ulen ;
/* check to see if any column of L can be pruned */ /* check to see if any column of L can be pruned */
/* Ux is set but not used. This OK. */
GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ; GET_POINTER (LU, Uip, Ulen, Ui, Ux, k, ulen) ;
for (p = 0 ; p < ulen ; p++) for (p = 0 ; p < ulen ; p++)
{ {
@ -818,15 +809,9 @@ size_t KLU_kernel /* final size of LU on output */
} }
#endif #endif
/* Francesco - Compressed 'lsolve_symbolic' and 'cosntruct_column' in one routine */ top = lsolve_symbolic (n, k, Ap, Ai, Q, Pinv, Stack, Flag,
top = lsolve_symbolic_and_construct_column (n, k, Ap, Ai, Q, Pinv, Stack, Flag, Lpend, Lpend, Ap_pos, LU, lup, Llen, Lip, k1, PSinv) ;
Ap_pos, LU, lup, Llen, Lip, k1, PSinv, Ax, X, Rs, scale, Offp, Offi, Offx) ;
/* ------------------------------------------------------------------ */
/* get the column of the matrix to factorize and scatter into X */
/* ------------------------------------------------------------------ */
/*
#ifndef NDEBUG #ifndef NDEBUG
PRINTF (("--- in U:\n")) ; PRINTF (("--- in U:\n")) ;
for (p = top ; p < n ; p++) for (p = top ; p < n ; p++)
@ -850,7 +835,13 @@ size_t KLU_kernel /* final size of LU on output */
if (Flag [i] == k) p++ ; if (Flag [i] == k) p++ ;
} }
#endif #endif
*/
/* ------------------------------------------------------------------ */
/* get the column of the matrix to factorize and scatter into X */
/* ------------------------------------------------------------------ */
construct_column (k, Ap, Ai, Ax, Q, X,
k1, PSinv, Rs, scale, Offp, Offi, Offx) ;
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* compute the numerical values of the kth column (s = L \ A (:,k)) */ /* compute the numerical values of the kth column (s = L \ A (:,k)) */

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_memory =========================================================== */ // KLU/Source/klu_memory: memory management for KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* KLU memory management routines: /* KLU memory management routines:
* *
@ -67,8 +73,6 @@ void *KLU_malloc /* returns pointer to the newly malloc'd block */
) )
{ {
void *p ; void *p ;
size_t s ;
Int ok = TRUE ;
if (Common == NULL) if (Common == NULL)
{ {
@ -80,7 +84,7 @@ void *KLU_malloc /* returns pointer to the newly malloc'd block */
Common->status = KLU_INVALID ; Common->status = KLU_INVALID ;
p = NULL ; p = NULL ;
} }
else if (n >= INT_MAX) else if (sizeof (size_t) > sizeof (Int) && n >= Int_MAX)
{ {
/* object is too big to allocate; p[i] where i is an Int will not /* object is too big to allocate; p[i] where i is an Int will not
* be enough. */ * be enough. */
@ -90,8 +94,7 @@ void *KLU_malloc /* returns pointer to the newly malloc'd block */
else else
{ {
/* call malloc, or its equivalent */ /* call malloc, or its equivalent */
s = KLU_mult_size_t (MAX (1,n), size, &ok) ; p = SuiteSparse_malloc (n, size) ;
p = ok ? ((Common->malloc_memory) (s)) : NULL ;
if (p == NULL) if (p == NULL)
{ {
/* failure: out of memory */ /* failure: out of memory */
@ -99,7 +102,7 @@ void *KLU_malloc /* returns pointer to the newly malloc'd block */
} }
else else
{ {
Common->memusage += s ; Common->memusage += (MAX (1,n) * size) ;
Common->mempeak = MAX (Common->mempeak, Common->memusage) ; Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
} }
} }
@ -128,15 +131,12 @@ void *KLU_free /* always returns NULL */
KLU_common *Common KLU_common *Common
) )
{ {
size_t s ;
Int ok = TRUE ;
if (p != NULL && Common != NULL) if (p != NULL && Common != NULL)
{ {
/* only free the object if the pointer is not NULL */ /* only free the object if the pointer is not NULL */
/* call free, or its equivalent */ /* call free, or its equivalent */
(Common->free_memory) (p) ; SuiteSparse_free (p) ;
s = KLU_mult_size_t (MAX (1,n), size, &ok) ; Common->memusage -= (MAX (1,n) * size) ;
Common->memusage -= s ;
} }
/* return NULL, and the caller should assign this to p. This avoids /* return NULL, and the caller should assign this to p. This avoids
* freeing the same pointer twice. */ * freeing the same pointer twice. */
@ -178,8 +178,7 @@ void *KLU_realloc /* returns pointer to reallocated block */
) )
{ {
void *pnew ; void *pnew ;
size_t snew, sold ; int ok = TRUE ;
Int ok = TRUE ;
if (Common == NULL) if (Common == NULL)
{ {
@ -196,7 +195,7 @@ void *KLU_realloc /* returns pointer to reallocated block */
/* A fresh object is being allocated. */ /* A fresh object is being allocated. */
p = KLU_malloc (nnew, size, Common) ; p = KLU_malloc (nnew, size, Common) ;
} }
else if (nnew >= INT_MAX) else if (sizeof (size_t) > sizeof (Int) && nnew >= Int_MAX)
{ {
/* failure: nnew is too big. Do not change p */ /* failure: nnew is too big. Do not change p */
Common->status = KLU_TOO_LARGE ; Common->status = KLU_TOO_LARGE ;
@ -205,21 +204,19 @@ void *KLU_realloc /* returns pointer to reallocated block */
{ {
/* The object exists, and is changing to some other nonzero size. */ /* The object exists, and is changing to some other nonzero size. */
/* call realloc, or its equivalent */ /* call realloc, or its equivalent */
snew = KLU_mult_size_t (MAX (1,nnew), size, &ok) ; pnew = SuiteSparse_realloc (nnew, nold, size, p, &ok) ;
sold = KLU_mult_size_t (MAX (1,nold), size, &ok) ; if (ok)
pnew = ok ? ((Common->realloc_memory) (p, snew)) : NULL ; {
if (pnew == NULL) /* success: return the new p and change the size of the block */
Common->memusage += ((nnew-nold) * size) ;
Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
p = pnew ;
}
else
{ {
/* Do not change p, since it still points to allocated memory */ /* Do not change p, since it still points to allocated memory */
Common->status = KLU_OUT_OF_MEMORY ; Common->status = KLU_OUT_OF_MEMORY ;
} }
else
{
/* success: return the new p and change the size of the block */
Common->memusage += (snew - sold) ;
Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
p = pnew ;
}
} }
return (p) ; return (p) ;
} }

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_refactor ========================================================= */ // KLU/Source/klu_refactor: factor another matrix (no pivoting)
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Factor the matrix, after ordering and analyzing it with KLU_analyze, and /* Factor the matrix, after ordering and analyzing it with KLU_analyze, and
* factoring it once with KLU_factor. This routine cannot do any numerical * factoring it once with KLU_factor. This routine cannot do any numerical
@ -15,7 +21,7 @@
/* === KLU_refactor ========================================================= */ /* === KLU_refactor ========================================================= */
/* ========================================================================== */ /* ========================================================================== */
Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */ int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
Int Ap [ ], /* size n+1, column pointers */ Int Ap [ ], /* size n+1, column pointers */
@ -31,8 +37,7 @@ Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
Entry ukk, ujk, s ; Entry ukk, ujk, s ;
Entry *Offx, *Lx, *Ux, *X, *Az, *Udiag ; Entry *Offx, *Lx, *Ux, *X, *Az, *Udiag ;
double *Rs ; double *Rs ;
Int *P, *Q, *R, *Pnum, *Offp, *Offi, *Ui, *Li, *Pinv, *Lip, *Uip, *Llen, Int *Q, *R, *Pnum, *Ui, *Li, *Pinv, *Lip, *Uip, *Llen, *Ulen ;
*Ulen ;
Unit **LUbx ; Unit **LUbx ;
Unit *LU ; Unit *LU ;
Int k1, k2, nk, k, block, oldcol, pend, oldrow, n, p, newrow, scale, Int k1, k2, nk, k, block, oldcol, pend, oldrow, n, p, newrow, scale,
@ -46,10 +51,6 @@ Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
{ {
return (FALSE) ; return (FALSE) ;
} }
if (Common->status == KLU_EMPTY_MATRIX)
{
return (FALSE) ;
}
Common->status = KLU_OK ; Common->status = KLU_OK ;
if (Numeric == NULL) if (Numeric == NULL)
@ -69,7 +70,6 @@ Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
n = Symbolic->n ; n = Symbolic->n ;
P = Symbolic->P ;
Q = Symbolic->Q ; Q = Symbolic->Q ;
R = Symbolic->R ; R = Symbolic->R ;
nblocks = Symbolic->nblocks ; nblocks = Symbolic->nblocks ;
@ -80,8 +80,6 @@ Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
Pnum = Numeric->Pnum ; Pnum = Numeric->Pnum ;
Offp = Numeric->Offp ;
Offi = Numeric->Offi ;
Offx = (Entry *) Numeric->Offx ; Offx = (Entry *) Numeric->Offx ;
LUbx = (Unit **) Numeric->LUbx ; LUbx = (Unit **) Numeric->LUbx ;
@ -442,20 +440,20 @@ Int KLU_refactor /* returns TRUE if successful, FALSE otherwise */
} }
#ifndef NDEBUG #ifndef NDEBUG
ASSERT (Offp [n] == poff) ; ASSERT (Numeric->Offp [n] == poff) ;
ASSERT (Symbolic->nzoff == poff) ; ASSERT (Symbolic->nzoff == poff) ;
PRINTF (("\n------------------- Off diagonal entries, new:\n")) ; PRINTF (("\n------------------- Off diagonal entries, new:\n")) ;
ASSERT (KLU_valid (n, Offp, Offi, Offx)) ; ASSERT (KLU_valid (n, Numeric->Offp, Numeric->Offi, Offx)) ;
if (Common->status == KLU_OK) if (Common->status == KLU_OK)
{ {
PRINTF (("\n ########### KLU_BTF_REFACTOR done, nblocks %d\n",nblocks)); PRINTF (("\n ----------- KLU_BTF_REFACTOR done, nblocks %d\n",nblocks));
for (block = 0 ; block < nblocks ; block++) for (block = 0 ; block < nblocks ; block++)
{ {
k1 = R [block] ; k1 = R [block] ;
k2 = R [block+1] ; k2 = R [block+1] ;
nk = k2 - k1 ; nk = k2 - k1 ;
PRINTF (( PRINTF ((
"\n================KLU_refactor output: k1 %d k2 %d nk %d\n", "\n--------------- KLU_refactor output: k1 %d k2 %d nk %d\n",
k1, k2, nk)) ; k1, k2, nk)) ;
if (nk == 1) if (nk == 1)
{ {

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_scale ============================================================ */ // KLU/Source/klu_scale: scale a sparse matrix
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Scale a matrix and check to see if it is valid. Can be called by the user. /* Scale a matrix and check to see if it is valid. Can be called by the user.
* This is called by KLU_factor and KLU_refactor. Returns TRUE if the input * This is called by KLU_factor and KLU_refactor. Returns TRUE if the input
@ -16,10 +22,10 @@
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_scale /* return TRUE if successful, FALSE otherwise */ int KLU_scale /* return TRUE if successful, FALSE otherwise */
( (
/* inputs, not modified */ /* inputs, not modified */
Int scale, /* 0: none, 1: sum, 2: max */ int scale, /* 0: none, 1: sum, 2: max */
Int n, Int n,
Int Ap [ ], /* size n+1, column pointers */ Int Ap [ ], /* size n+1, column pointers */
Int Ai [ ], /* size nz, row indices */ Int Ai [ ], /* size nz, row indices */

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_solve ============================================================ */ // KLU/Source/klu_solve: solve x=A\b using the KLU factorization
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Solve Ax=b using the symbolic and numeric objects from KLU_analyze /* Solve Ax=b using the symbolic and numeric objects from KLU_analyze
* (or KLU_analyze_given) and KLU_factor. Note that no iterative refinement is * (or KLU_analyze_given) and KLU_factor. Note that no iterative refinement is
@ -11,7 +17,7 @@
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_solve int KLU_solve
( (
/* inputs, not modified */ /* inputs, not modified */
KLU_symbolic *Symbolic, KLU_symbolic *Symbolic,
@ -41,10 +47,6 @@ Int KLU_solve
{ {
return (FALSE) ; return (FALSE) ;
} }
if (Common->status == KLU_EMPTY_MATRIX)
{
return (FALSE) ;
}
if (Numeric == NULL || Symbolic == NULL || d < Symbolic->n || nrhs < 0 || if (Numeric == NULL || Symbolic == NULL || d < Symbolic->n || nrhs < 0 ||
B == NULL) B == NULL)
{ {

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_sort ============================================================= */ // KLU/Source/klu_sort: sorts the L and U factors of KLU
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* sorts the columns of L and U so that the row indices appear in strictly /* sorts the columns of L and U so that the row indices appear in strictly
* increasing order. * increasing order.
@ -88,7 +94,7 @@ static void sort (Int n, Int *Xip, Int *Xlen, Unit *LU, Int *Tp, Int *Tj,
/* === KLU_sort ============================================================= */ /* === KLU_sort ============================================================= */
/* ========================================================================== */ /* ========================================================================== */
Int KLU_sort int KLU_sort
( (
KLU_symbolic *Symbolic, KLU_symbolic *Symbolic,
KLU_numeric *Numeric, KLU_numeric *Numeric,

View File

@ -1,6 +1,12 @@
/* ========================================================================== */ //------------------------------------------------------------------------------
/* === KLU_tsolve =========================================================== */ // KLU/Source/klu_tsolve: solve x=A'\b using the KLU factorization
/* ========================================================================== */ //------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2022, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
/* Solve A'x=b using the symbolic and numeric objects from KLU_analyze /* Solve A'x=b using the symbolic and numeric objects from KLU_analyze
* (or KLU_analyze_given) and KLU_factor. Note that no iterative refinement is * (or KLU_analyze_given) and KLU_factor. Note that no iterative refinement is
@ -11,7 +17,7 @@
#include "klu_internal.h" #include "klu_internal.h"
Int KLU_tsolve int KLU_tsolve
( (
/* inputs, not modified */ /* inputs, not modified */
KLU_symbolic *Symbolic, KLU_symbolic *Symbolic,
@ -23,7 +29,7 @@ Int KLU_tsolve
double B [ ], /* size n*nrhs, in column-oriented form, with double B [ ], /* size n*nrhs, in column-oriented form, with
* leading dimension d. */ * leading dimension d. */
#ifdef COMPLEX #ifdef COMPLEX
Int conj_solve, /* TRUE for conjugate transpose solve, FALSE for int conj_solve, /* TRUE for conjugate transpose solve, FALSE for
* array transpose solve. Used for the complex * array transpose solve. Used for the complex
* case only. */ * case only. */
#endif #endif
@ -46,10 +52,6 @@ Int KLU_tsolve
{ {
return (FALSE) ; return (FALSE) ;
} }
if (Common->status == KLU_EMPTY_MATRIX)
{
return (FALSE) ;
}
if (Numeric == NULL || Symbolic == NULL || d < Symbolic->n || nrhs < 0 || if (Numeric == NULL || Symbolic == NULL || d < Symbolic->n || nrhs < 0 ||
B == NULL) B == NULL)
{ {

View File

@ -1,14 +1,24 @@
//------------------------------------------------------------------------------
// KLU/Include/klu_version.h: internal include file for KLU
//------------------------------------------------------------------------------
// KLU, Copyright (c) 2004-2023, University of Florida. All Rights Reserved.
// Authors: Timothy A. Davis and Ekanathan Palamadai.
// SPDX-License-Identifier: LGPL-2.1+
//------------------------------------------------------------------------------
#ifndef _KLU_VERSION_H #ifndef _KLU_VERSION_H
#define _KLU_VERSION_H #define _KLU_VERSION_H
#ifdef DLONG #ifdef DLONG
#define Int UF_long #define Int int64_t
#define Int_id UF_long_id #define Int_id "%" PRId64
#define Int_MAX UF_long_max #define Int_MAX INT64_MAX
#else #else
#define Int int #define Int int32_t
#define Int_id "%d" #define Int_id "%d"
#define Int_MAX INT_MAX #define Int_MAX INT32_MAX
#endif #endif
#define NPRINT #define NPRINT
@ -41,6 +51,7 @@
#ifdef DLONG #ifdef DLONG
// zl: complex int64_t
#define KLU_scale klu_zl_scale #define KLU_scale klu_zl_scale
#define KLU_solve klu_zl_solve #define KLU_solve klu_zl_solve
#define KLU_tsolve klu_zl_tsolve #define KLU_tsolve klu_zl_tsolve
@ -64,6 +75,7 @@
#else #else
// z: complex int32_t
#define KLU_scale klu_z_scale #define KLU_scale klu_z_scale
#define KLU_solve klu_z_solve #define KLU_solve klu_z_solve
#define KLU_tsolve klu_z_tsolve #define KLU_tsolve klu_z_tsolve
@ -96,6 +108,7 @@
#ifdef DLONG #ifdef DLONG
// l: int64_t
#define KLU_scale klu_l_scale #define KLU_scale klu_l_scale
#define KLU_solve klu_l_solve #define KLU_solve klu_l_solve
#define KLU_tsolve klu_l_tsolve #define KLU_tsolve klu_l_tsolve
@ -119,6 +132,7 @@
#else #else
// no prefix: int32_t
#define KLU_scale klu_scale #define KLU_scale klu_scale
#define KLU_solve klu_solve #define KLU_solve klu_solve
#define KLU_tsolve klu_tsolve #define KLU_tsolve klu_tsolve
@ -152,6 +166,7 @@
#ifdef DLONG #ifdef DLONG
// l: int64_t
#define KLU_analyze klu_l_analyze #define KLU_analyze klu_l_analyze
#define KLU_analyze_given klu_l_analyze_given #define KLU_analyze_given klu_l_analyze_given
#define KLU_alloc_symbolic klu_l_alloc_symbolic #define KLU_alloc_symbolic klu_l_alloc_symbolic
@ -176,6 +191,7 @@
#else #else
// no prefiex: int64_t
#define KLU_analyze klu_analyze #define KLU_analyze klu_analyze
#define KLU_analyze_given klu_analyze_given #define KLU_analyze_given klu_analyze_given
#define KLU_alloc_symbolic klu_alloc_symbolic #define KLU_alloc_symbolic klu_alloc_symbolic
@ -315,10 +331,10 @@ typedef double Unit ;
that possibility. ANSI C *does* guarantee that an array of structs has that possibility. ANSI C *does* guarantee that an array of structs has
the same size as n times the size of one struct. the same size as n times the size of one struct.
The ANSI C99 version of the C language includes a "double _Complex" type. The ANSI C11 version of the C language includes a "double complex" type.
It should be possible in that case to do the following: It should be possible in that case to do the following:
#define Entry double _Complex #define Entry double complex
and remove the Double_Complex struct. The macros, below, could then be and remove the Double_Complex struct. The macros, below, could then be
replaced with instrinsic operators. Note that the #define Real and replaced with instrinsic operators. Note that the #define Real and
@ -365,7 +381,7 @@ typedef Double_Complex Unit ;
#define SPLIT(sz) ((sz) != (double *) NULL) #define SPLIT(sz) ((sz) != (double *) NULL)
/* c = (s1) + (s2)*i, if s2 is null, then X is in "packed" format (compatible /* c = (s1) + (s2)*i, if s2 is null, then X is in "packed" format (compatible
* with Entry and ANSI C99 double _Complex type). */ * with Entry and ANSI C11 double complex type). */
/*#define ASSIGN(c,s1,s2,p,split) \ /*#define ASSIGN(c,s1,s2,p,split) \
{ \ { \
if (split) \ if (split) \