Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suitesparse-ldl: new recipe #23549

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/suitesparse-ldl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"3.3.2":
url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz"
sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3"
95 changes: 95 additions & 0 deletions recipes/suitesparse-ldl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import get, rm, rmdir, copy

required_conan_version = ">=1.53.0"


class SuiteSparseLdlConan(ConanFile):
name = "suitesparse-ldl"
description = "LDL: A sparse LDL' factorization and solve package in SuiteSparse"
license = "LGPL-2.1-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://people.engr.tamu.edu/davis/suitesparse.html"
topics = ("mathematics", "sparse-matrix", "linear-algebra", "ldl-factorization")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
# OpenBLAS and OpenMP are provided via suitesparse-config
self.requires("suitesparse-config/7.7.0", transitive_headers=True, transitive_libs=True)
self.requires("suitesparse-amd/3.3.2", transitive_headers=True, transitive_libs=True)

def build_requirements(self):
self.tool_requires("cmake/[>=3.22 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared
tc.variables["SUITESPARSE_USE_OPENMP"] = True
tc.variables["SUITESPARSE_USE_CUDA"] = False
tc.variables["SUITESPARSE_DEMOS"] = False
tc.variables["SUITESPARSE_USE_FORTRAN"] = False # Fortran sources are translated to C instead
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "LDL"))
cmake.build()

def package(self):
copy(self, "License.txt", os.path.join(self.source_folder, "LDL", "Doc"), os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "LDL")
self.cpp_info.set_property("cmake_target_name", "SuiteSparse::LDL")
if not self.options.shared:
self.cpp_info.set_property("cmake_target_aliases", ["SuiteSparse::LDL_static"])
self.cpp_info.set_property("pkg_config_name", "LDL")

self.cpp_info.libs = ["ldl"]
self.cpp_info.includedirs.append(os.path.join("include", "suitesparse"))

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
8 changes: 8 additions & 0 deletions recipes/suitesparse-ldl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(LDL REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE SuiteSparse::LDL)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_11)
26 changes: 26 additions & 0 deletions recipes/suitesparse-ldl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
79 changes: 79 additions & 0 deletions recipes/suitesparse-ldl/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/v7.7.0/LDL/Demo/ldlsimple.c

//------------------------------------------------------------------------------
// LDL/Demo/ldlsimple.c: a simple LDL main program (int32_t version)
//------------------------------------------------------------------------------

// LDL, Copyright (c) 2005-2022 by Timothy A. Davis. All Rights Reserved.
// SPDX-License-Identifier: LGPL-2.1+

//------------------------------------------------------------------------------

/* LDLSIMPLE: this is a very simple main program that illustrates the basic
* usage of the LDL routines. The output of this program is in ldlsimple.out.
* This program factorizes the matrix
*
* A =[ ...
* 1.7 0 0 0 0 0 0 0 .13 0
* 0 1. 0 0 .02 0 0 0 0 .01
* 0 0 1.5 0 0 0 0 0 0 0
* 0 0 0 1.1 0 0 0 0 0 0
* 0 .02 0 0 2.6 0 .16 .09 .52 .53
* 0 0 0 0 0 1.2 0 0 0 0
* 0 0 0 0 .16 0 1.3 0 0 .56
* 0 0 0 0 .09 0 0 1.6 .11 0
* .13 0 0 0 .52 0 0 .11 1.4 0
* 0 .01 0 0 .53 0 .56 0 0 3.1 ] ;
*
* and then solves a system Ax=b whose true solution is
* x = [.1 .2 .3 .4 .5 .6 .7 .8 .9 1]' ;
*
* Note that Li and Lx are statically allocated, with length 13. This is just
* enough to hold the factor L, but normally this size is not known until after
* ldl_symbolic has analyzed the matrix. The size of Li and Lx must be greater
* than or equal to lnz = Lp [N], which is 13 for this matrix L.
*/

#include <stdio.h>
#include "ldl.h"
#define N 10 /* A is 10-by-10 */
#define ANZ 19 /* # of nonzeros on diagonal and upper triangular part of A */
#define LNZ 13 /* # of nonzeros below the diagonal of L */

int main (void)
{
/* only the upper triangular part of A is required */
int32_t Ap [N+1] = {0, 1, 2, 3, 4, 6, 7, 9, 11, 15, ANZ},
Ai [ANZ] = {0, 1, 2, 3, 1,4, 5, 4,6, 4,7, 0,4,7,8, 1,4,6,9 } ;
double Ax [ANZ] = {1.7, 1., 1.5, 1.1, .02,2.6, 1.2, .16,1.3, .09,1.6,
.13,.52,.11,1.4, .01,.53,.56,3.1},
b [N] = {.287, .22, .45, .44, 2.486, .72, 1.55, 1.424, 1.621, 3.759};
double Lx [LNZ], D [N], Y [N] ;
int Li [LNZ], Lp [N+1], Parent [N], Lnz [N], Flag [N], Pattern [N], d, i ;

int version [3] ;
SuiteSparse_version (version) ;
printf ("LDL %d.%d.%d in SuiteSparse %d.%d.%d\n",
LDL_MAIN_VERSION, LDL_SUB_VERSION, LDL_SUBSUB_VERSION,
version [0], version [1], version [2]) ;

/* factorize A into LDL' (P and Pinv not used) */
ldl_symbolic (N, Ap, Ai, Lp, Parent, Lnz, Flag, NULL, NULL) ;
printf ("Nonzeros in L, excluding diagonal: %d\n", Lp [N]) ;
d = ldl_numeric (N, Ap, Ai, Ax, Lp, Parent, Lnz, Li, Lx, D, Y, Pattern,
Flag, NULL, NULL) ;

if (d == N)
{
/* solve Ax=b, overwriting b with the solution x */
ldl_lsolve (N, b, Lp, Li, Lx) ;
ldl_dsolve (N, b, D) ;
ldl_ltsolve (N, b, Lp, Li, Lx) ;
for (i = 0 ; i < N ; i++) printf ("x [%d] = %g\n", i, b [i]) ;
}
else
{
printf ("ldl_numeric failed, D (%d,%d) is zero\n", d, d) ;
}
return (0) ;
}
3 changes: 3 additions & 0 deletions recipes/suitesparse-ldl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.3.2":
folder: all
Loading