Skip to content
/ PyKLU Public
forked from kagami-c/PyKLU

Python binding for KLU solver

License

Notifications You must be signed in to change notification settings

mabrains/PyKLU

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyKLU

A Python binding for KLU solver in SuiteSparse(http://faculty.cse.tamu.edu/davis/suitesparse.html)

Copyright (C) 2015 kagami-c and licensed under LGPL-2.1

Introduction

This library provide a Python binding for KLU solver. At this time, we just implement a wrapper for solving linear system. Other solvers will be implemented in later version.

For better compatibility with scientific computing modules in Python community, this modules is designed for NumPy ndarray input. We strongly recommend to do the front-end computation in NumPy.

Dependencies

Installation

  1. Get SuiteSparse source code and extract it in temp/ subfolder. The final path is like PyKLU/temp/SuiteSparse-4.4.4/SuiteSparse/..

  2. Type make in root folder (in PyKLU/) and it will automatically build SuiteSparse library and PyKLU simple wrapper. There should be a shared library in root folder of this project.

  3. Delete all files in temp/ folder.

  4. Feel free to enjoy this wrapper.

Note: we need to add the following to the cmake targets in the file Makefile inside suitespare pacakge:

-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true

Usage

In this stage, we just provide a wrapper in local and have not install it in global paths. So feel free to put this script and shared library in any other location. When finishing building, all necessities are pyklu.py and libpyklu.so.

In your own project, you can use this binding like this.

import numpy
from pyklu import solve_linear_system
A = numpy.array([[2, 3, 0, 0, 0], [3, 0, 4, 0, 6],
                 [0, -1, -3, 2, 0], [0, 0, 1, 0, 0],
                 [0, 4, 2, 0, 1]], dtype=numpy.double)
b = numpy.array([8, 45, -3, 3, 19], dtype=numpy.double)
solve_linear_system(A, b)
print(b)

Enjoy the speed of solving sparse linear systems~

ATTENTION!

solve_linear_system() will return the result of x in equation Ax = b. While the input argument b will be modified to x, which means that x equals b when solver finish, and they are all pointing to the answer.

LICENSE

SuiteSparse is licensed under LGPL-2.1. This binding library (PyKLU) is released under LGPL-2.1.

Releases

No releases published

Packages

No packages published

Languages

  • Python 66.0%
  • Makefile 23.2%
  • C 10.8%