GithubHelp home page GithubHelp logo

nnls's Introduction

nnls

This is a Rust version of nnls (Non-Negative Least Squares). It's a port from a Fortran90 script used by scipy.optimize.nnls and probably several others.

Why?

I decided to port nnls to Rust because:

  • The C version of nnls is not thread-safe! There are several static variables throughout the code which make it unusable in parallel. If you plan to use nnls only in single-thread, you might prefer linking to that version: it has been heavily tested and has no known problem.
  • Both Fortran versions (77 and 90) require some knowledge of Fortran memory model and some compiler tricks to successfuly link against. I wasn't able to do it and I didn't want to waste more hours into this adventure, so I simply ported the script to Rust.

Advantages

  • It has been used several millions of times and it will be used billions of times soon. I work with 3D images and each image I see contains around 1 million voxels. For a specific algorithm, I need to call nnls 2 times for each voxel. Several of those images has been tested and compared with the original Fortran version.
  • There's no unsafe and it is forbidden to use any in this crate.

Problems

  • This is not idiomatic Rust. I tried cleaning and enhancing the code but it's not always possible.
  • I use ndarray. You might prefer something else. I do not plan to change this but you're welcome to discuss it.
  • There are currently 3 panic! in the code because there are 3 code paths in the original code which use goto that I couldn't translate properly to Rust. I planned to handle those cases but it turns out that they are never called. As I wrote, nnls has been extensively used and I couldn't find any dataset that triggers those conditions. If my programs ever panic because of this, it will be repaired quickly.

nnls's People

Contributors

nilgoyette avatar jordanmb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.