Skip to content

Commit abb6041

Browse files
cmake for CSparse
1 parent 67e5a2a commit abb6041

File tree

17 files changed

+461
-182
lines changed

17 files changed

+461
-182
lines changed

CSparse/CMakeLists.txt

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#-------------------------------------------------------------------------------
2+
# CSparse/CMakeLists.txt: cmake for CSparse
3+
#-------------------------------------------------------------------------------
4+
5+
# Copyright (c) 2022, Timothy A. Davis. All Rights Reserved.
6+
# SPDX-License-Identifier: LGPL-2.1+
7+
8+
#-------------------------------------------------------------------------------
9+
# get the version
10+
#-------------------------------------------------------------------------------
11+
12+
# cmake 3.17 is required
13+
cmake_minimum_required ( VERSION 3.17 )
14+
15+
cmake_policy ( SET CMP0042 NEW )
16+
cmake_policy ( SET CMP0048 NEW )
17+
set ( CMAKE_MACOSX_RPATH TRUE )
18+
19+
set ( CSPARSE_DATE "Sept FIXME, 2022" )
20+
set ( CSPARSE_VERSION_MAJOR 4 )
21+
set ( CSPARSE_VERSION_MINOR 0 )
22+
set ( CSPARSE_VERSION_SUB 0 )
23+
24+
message ( STATUS "Building CSparse version: v"
25+
${CSPARSE_VERSION_MAJOR}.
26+
${CSPARSE_VERSION_MINOR}.
27+
${CSPARSE_VERSION_SUB} " (" ${CSPARSE_DATE} ")" )
28+
29+
project ( csparse
30+
VERSION "${CSPARSE_VERSION_MAJOR}.${CSPARSE_VERSION_MINOR}.${CSPARSE_VERSION_SUB}"
31+
LANGUAGES C ) # <-- add CXX here for packages that use C++
32+
33+
message ( STATUS "CSparse project: " ${PROJECT_SOURCE_DIR} )
34+
message ( STATUS "CSparse build: " ${CMAKE_BINARY_DIR} )
35+
36+
#-------------------------------------------------------------------------------
37+
# determine build type
38+
#-------------------------------------------------------------------------------
39+
40+
if ( NOT CMAKE_BUILD_TYPE )
41+
set ( CMAKE_BUILD_TYPE Release )
42+
endif ( )
43+
44+
#-------------------------------------------------------------------------------
45+
# Configure cs.h with version number
46+
#-------------------------------------------------------------------------------
47+
48+
configure_file (
49+
"Config/cs.h.in"
50+
"${PROJECT_SOURCE_DIR}/Include/cs.h"
51+
)
52+
53+
#-------------------------------------------------------------------------------
54+
# report status and set compile flags
55+
#-------------------------------------------------------------------------------
56+
57+
message ( STATUS "CMAKE build type: " ${CMAKE_BUILD_TYPE} )
58+
59+
if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
60+
message ( STATUS "CMAKE C Flags debug: " ${CMAKE_C_FLAGS_DEBUG} )
61+
# message ( STATUS "CMAKE C++ Flags debug: " ${CMAKE_CXX_FLAGS_DEBUG} )
62+
else ( )
63+
message ( STATUS "CMAKE C Flags release: " ${CMAKE_C_FLAGS_RELEASE} )
64+
# message ( STATUS "CMAKE C++ Flags release: " ${CMAKE_CXX_FLAGS_RELEASE} )
65+
endif ( )
66+
67+
message ( STATUS "CMAKE C compiler: " ${CMAKE_C_COMPILER_ID} )
68+
69+
# message ( STATUS "CMAKE C++ compiler: " ${CMAKE_CXX_COMPILER_ID} )
70+
71+
#-------------------------------------------------------------------------------
72+
# include directories
73+
#-------------------------------------------------------------------------------
74+
75+
set ( CMAKE_INCLUDE_CURRENT_DIR ON )
76+
include_directories ( Source Include ${SUITESPARSE_CONFIG_INCLUDE_DIR} )
77+
78+
#-------------------------------------------------------------------------------
79+
# dynamic csparse library properties
80+
#-------------------------------------------------------------------------------
81+
82+
file ( GLOB CSPARSE_SOURCES "Source/*.c" )
83+
84+
add_library ( csparse SHARED ${CSPARSE_SOURCES} )
85+
86+
SET_TARGET_PROPERTIES ( csparse PROPERTIES
87+
VERSION ${CSPARSE_VERSION_MAJOR}.${CSPARSE_VERSION_MINOR}.${CSPARSE_VERSION_SUB}
88+
SOVERSION ${CSPARSE_VERSION_MAJOR}
89+
PUBLIC_HEADER "Include/cs.h" )
90+
91+
#-------------------------------------------------------------------------------
92+
# static csparse library properties
93+
#-------------------------------------------------------------------------------
94+
95+
add_library ( csparse_static STATIC ${CSPARSE_SOURCES} )
96+
97+
SET_TARGET_PROPERTIES ( csparse_static PROPERTIES
98+
VERSION ${CSPARSE_VERSION_MAJOR}.${CSPARSE_VERSION_MINOR}.${CSPARSE_VERSION_SUB}
99+
OUTPUT_NAME csparse
100+
SOVERSION ${CSPARSE_VERSION_MAJOR} )
101+
102+
#-------------------------------------------------------------------------------
103+
# add the library dependencies
104+
#-------------------------------------------------------------------------------
105+
106+
target_link_libraries ( csparse PUBLIC ${SUITESPARSE_CONFIG_LIBRARY} )
107+
target_link_libraries ( csparse_static PUBLIC ${SUITESPARSE_CONFIG_LIBRARY} )
108+
109+
# libm:
110+
if ( NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
111+
target_link_libraries ( csparse PUBLIC m )
112+
target_link_libraries ( csparse_static PUBLIC m )
113+
endif ( )
114+
115+
#-------------------------------------------------------------------------------
116+
# CSparse installation location
117+
#-------------------------------------------------------------------------------
118+
119+
# use "cmake -DLOCAL=1" to install only in SuiteSparse/lib and
120+
# SuiteSparse/include.
121+
122+
if ( NOT LOCAL )
123+
124+
# install in /usr/local/lib and /usr/local/include.
125+
# requires "sudo make install"
126+
message ( STATUS "Installation will be system-wide (requires 'sudo make install')" )
127+
include ( GNUInstallDirs )
128+
129+
install ( TARGETS csparse
130+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
131+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
132+
133+
install ( TARGETS csparse_static
134+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
135+
136+
else ( )
137+
138+
message ( STATUS "Installation in ../lib and ../include only," )
139+
message ( STATUS " with 'make install'. No 'sudo' required." )
140+
141+
endif ( )
142+
143+
if ( ( EXISTS ${CMAKE_SOURCE_DIR}/../lib ) AND
144+
( EXISTS ${CMAKE_SOURCE_DIR}/../include ))
145+
146+
# also install in SuiteSparse/lib and SuiteSparse/include;
147+
# does not require "sudo make install", just "make install"
148+
install ( TARGETS csparse
149+
LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/../lib
150+
PUBLIC_HEADER DESTINATION ${CMAKE_SOURCE_DIR}/../include )
151+
152+
install ( TARGETS csparse_static
153+
ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/../lib )
154+
155+
endif ( )
156+
157+
#-------------------------------------------------------------------------------
158+
# Demo library and programs
159+
#-------------------------------------------------------------------------------
160+
161+
if ( DEMO )
162+
163+
#---------------------------------------------------------------------------
164+
# demo library
165+
#---------------------------------------------------------------------------
166+
167+
message ( STATUS "Also compiling the demos in CSparse/Demo" )
168+
169+
#---------------------------------------------------------------------------
170+
# Demo programs
171+
#---------------------------------------------------------------------------
172+
173+
add_executable ( cs_demo1 "Demo/cs_demo1.c" "Demo/cs_demo.c" )
174+
add_executable ( cs_demo2 "Demo/cs_demo2.c" "Demo/cs_demo.c" )
175+
add_executable ( cs_demo3 "Demo/cs_demo3.c" "Demo/cs_demo.c" )
176+
177+
# Libraries required for Demo programs
178+
target_link_libraries ( cs_demo1 PUBLIC csparse )
179+
target_link_libraries ( cs_demo2 PUBLIC csparse )
180+
target_link_libraries ( cs_demo3 PUBLIC csparse )
181+
182+
else ( )
183+
184+
message ( STATUS "Skipping the demos in CSparse/Demo" )
185+
186+
endif ( )

CSparse/Config/cs.h.in

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#ifndef _CS_H
2+
#define _CS_H
3+
#include <stdlib.h>
4+
#include <limits.h>
5+
#include <math.h>
6+
#include <stdio.h>
7+
#include <stddef.h>
8+
#include <inttypes.h>
9+
#ifdef MATLAB_MEX_FILE
10+
#include "mex.h"
11+
#endif
12+
#define CS_VER @CSPARSE_VERSION_MAJOR@ /* CSparse Version */
13+
#define CS_SUBVER @CSPARSE_VERSION_MINOR@
14+
#define CS_SUBSUB @CSPARSE_VERSION_SUB@
15+
#define CS_DATE "@CSPARSE_DATE@" /* CSparse release date */
16+
#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2022"
17+
18+
#ifndef csi
19+
#define csi int64_t
20+
#endif
21+
22+
/* --- primary CSparse routines and data structures ------------------------- */
23+
typedef struct cs_sparse /* matrix in compressed-column or triplet form */
24+
{
25+
csi nzmax ; /* maximum number of entries */
26+
csi m ; /* number of rows */
27+
csi n ; /* number of columns */
28+
csi *p ; /* column pointers (size n+1) or col indices (size nzmax) */
29+
csi *i ; /* row indices, size nzmax */
30+
double *x ; /* numerical values, size nzmax */
31+
csi nz ; /* # of entries in triplet matrix, -1 for compressed-col */
32+
} cs ;
33+
34+
cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
35+
csi cs_cholsol (csi order, const cs *A, double *b) ;
36+
cs *cs_compress (const cs *T) ;
37+
csi cs_dupl (cs *A) ;
38+
csi cs_entry (cs *T, csi i, csi j, double x) ;
39+
csi cs_gaxpy (const cs *A, const double *x, double *y) ;
40+
cs *cs_load (FILE *f) ;
41+
csi cs_lusol (csi order, const cs *A, double *b, double tol) ;
42+
cs *cs_multiply (const cs *A, const cs *B) ;
43+
double cs_norm (const cs *A) ;
44+
csi cs_print (const cs *A, csi brief) ;
45+
csi cs_qrsol (csi order, const cs *A, double *b) ;
46+
cs *cs_transpose (const cs *A, csi values) ;
47+
/* utilities */
48+
void *cs_calloc (csi n, size_t size) ;
49+
void *cs_free (void *p) ;
50+
void *cs_realloc (void *p, csi n, size_t size, csi *ok) ;
51+
cs *cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet) ;
52+
cs *cs_spfree (cs *A) ;
53+
csi cs_sprealloc (cs *A, csi nzmax) ;
54+
void *cs_malloc (csi n, size_t size) ;
55+
56+
/* --- secondary CSparse routines and data structures ----------------------- */
57+
typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */
58+
{
59+
csi *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */
60+
csi *q ; /* fill-reducing column permutation for LU and QR */
61+
csi *parent ; /* elimination tree for Cholesky and QR */
62+
csi *cp ; /* column pointers for Cholesky, row counts for QR */
63+
csi *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */
64+
csi m2 ; /* # of rows for QR, after adding fictitious rows */
65+
double lnz ; /* # entries in L for LU or Cholesky; in V for QR */
66+
double unz ; /* # entries in U for LU; in R for QR */
67+
} css ;
68+
69+
typedef struct cs_numeric /* numeric Cholesky, LU, or QR factorization */
70+
{
71+
cs *L ; /* L for LU and Cholesky, V for QR */
72+
cs *U ; /* U for LU, R for QR, not used for Cholesky */
73+
csi *pinv ; /* partial pivoting for LU */
74+
double *B ; /* beta [0..n-1] for QR */
75+
} csn ;
76+
77+
typedef struct cs_dmperm_results /* cs_dmperm or cs_scc output */
78+
{
79+
csi *p ; /* size m, row permutation */
80+
csi *q ; /* size n, column permutation */
81+
csi *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */
82+
csi *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */
83+
csi nb ; /* # of blocks in fine dmperm decomposition */
84+
csi rr [5] ; /* coarse row decomposition */
85+
csi cc [5] ; /* coarse column decomposition */
86+
} csd ;
87+
88+
csi *cs_amd (csi order, const cs *A) ;
89+
csn *cs_chol (const cs *A, const css *S) ;
90+
csd *cs_dmperm (const cs *A, csi seed) ;
91+
csi cs_droptol (cs *A, double tol) ;
92+
csi cs_dropzeros (cs *A) ;
93+
csi cs_happly (const cs *V, csi i, double beta, double *x) ;
94+
csi cs_ipvec (const csi *p, const double *b, double *x, csi n) ;
95+
csi cs_lsolve (const cs *L, double *x) ;
96+
csi cs_ltsolve (const cs *L, double *x) ;
97+
csn *cs_lu (const cs *A, const css *S, double tol) ;
98+
cs *cs_permute (const cs *A, const csi *pinv, const csi *q, csi values) ;
99+
csi *cs_pinv (const csi *p, csi n) ;
100+
csi cs_pvec (const csi *p, const double *b, double *x, csi n) ;
101+
csn *cs_qr (const cs *A, const css *S) ;
102+
css *cs_schol (csi order, const cs *A) ;
103+
css *cs_sqr (csi order, const cs *A, csi qr) ;
104+
cs *cs_symperm (const cs *A, const csi *pinv, csi values) ;
105+
csi cs_updown (cs *L, csi sigma, const cs *C, const csi *parent) ;
106+
csi cs_usolve (const cs *U, double *x) ;
107+
csi cs_utsolve (const cs *U, double *x) ;
108+
/* utilities */
109+
css *cs_sfree (css *S) ;
110+
csn *cs_nfree (csn *N) ;
111+
csd *cs_dfree (csd *D) ;
112+
113+
/* --- tertiary CSparse routines -------------------------------------------- */
114+
csi *cs_counts (const cs *A, const csi *parent, const csi *post, csi ata) ;
115+
double cs_cumsum (csi *p, csi *c, csi n) ;
116+
csi cs_dfs (csi j, cs *G, csi top, csi *xi, csi *pstack, const csi *pinv) ;
117+
csi cs_ereach (const cs *A, csi k, const csi *parent, csi *s, csi *w) ;
118+
csi *cs_etree (const cs *A, csi ata) ;
119+
csi cs_fkeep (cs *A, csi (*fkeep) (csi, csi, double, void *), void *other) ;
120+
double cs_house (double *x, double *beta, csi n) ;
121+
csi cs_leaf (csi i, csi j, const csi *first, csi *maxfirst, csi *prevleaf,
122+
csi *ancestor, csi *jleaf) ;
123+
csi *cs_maxtrans (const cs *A, csi seed) ;
124+
csi *cs_post (const csi *parent, csi n) ;
125+
csi *cs_randperm (csi n, csi seed) ;
126+
csi cs_reach (cs *G, const cs *B, csi k, csi *xi, const csi *pinv) ;
127+
csi cs_scatter (const cs *A, csi j, double beta, csi *w, double *x, csi mark,
128+
cs *C, csi nz) ;
129+
csd *cs_scc (cs *A) ;
130+
csi cs_spsolve (cs *G, const cs *B, csi k, csi *xi, double *x,
131+
const csi *pinv, csi lo) ;
132+
csi cs_tdfs (csi j, csi k, csi *head, const csi *next, csi *post,
133+
csi *stack) ;
134+
/* utilities */
135+
csd *cs_dalloc (csi m, csi n) ;
136+
csd *cs_ddone (csd *D, cs *C, void *w, csi ok) ;
137+
cs *cs_done (cs *C, void *w, void *x, csi ok) ;
138+
csi *cs_idone (csi *p, cs *C, void *w, csi ok) ;
139+
csn *cs_ndone (csn *N, cs *C, void *w, void *x, csi ok) ;
140+
141+
#define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
142+
#define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
143+
#define CS_FLIP(i) (-(i)-2)
144+
#define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
145+
#define CS_MARKED(w,j) (w [j] < 0)
146+
#define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; }
147+
#define CS_CSC(A) (A && (A->nz == -1))
148+
#define CS_TRIPLET(A) (A && (A->nz >= 0))
149+
#endif

CSparse/Demo/Makefile

Lines changed: 0 additions & 38 deletions
This file was deleted.

CSparse/Demo/README.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CSparse/Demo: to compile a run the demos, just type "make" in this directory.
1+
CSparse/Demo: to compile a run the demos, just type "make demo" in the
2+
parent directory.
23
The printed residuals should all be small, except for the mbeacxc matrix
34
(which is numerically and structurally singular), and ash219 (which is a
45
least-squares problem). See cs_demo.out for the proper output of "make".

CSparse/Doc/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Sept FIXME, 2022: version 4.0.0
2+
3+
* using CMake to build CSparse instead of a Makefile
4+
* integer "csi": changed to int64_t. This can be overridded with
5+
-Dcsi=int (for example). This is a modest change to the API, so the
6+
major version number must increase from 3.x to 4.x.
7+
18
Sept 12, 2017: version 3.2.0
29

310
* replaced UFget with ssget

0 commit comments

Comments
 (0)