blob: e75084c3480c90702037d8d49d2a8f2b96c12691 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The rulinalg crate."><meta name="keywords" content="rust, rustlang, rust-lang, rulinalg"><title>rulinalg - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../rulinalg/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../rulinalg/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate rulinalg</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.4.2</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">rulinalg</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/rulinalg/lib.rs.html#1-125">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="the-rulinalg-crate"><a href="#the-rulinalg-crate">The rulinalg crate.</a></h2>
<p>A crate that provides high-dimensional linear algebra
implemented entirely in Rust.</p>
<hr />
<p>This crate provides two core data structures: <code>Matrix</code> and
<code>Vector</code>. These structs are designed to behave as you would expect
with relevant operator overloading.</p>
<p>The library currently contains (at least) the following linear algebra
methods:</p>
<ul>
<li>Matrix inversion</li>
<li>LUP decomposition</li>
<li>QR decomposition</li>
<li>SVD decomposition</li>
<li>Cholesky decomposition</li>
<li>Eigenvalue decomposition</li>
<li>Upper Hessenberg decomposition</li>
<li>Linear system solver</li>
<li>Other standard transformations, e.g. Transposing, concatenation, etc.</li>
</ul>
<hr />
<h3 id="usage"><a href="#usage">Usage</a></h3>
<p>Specific usage of modules is described within the modules themselves. This section
will highlight the basic usage.</p>
<p>We can create new matrices.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rulinalg::matrix::Matrix;
<span class="comment">// A new matrix with 3 rows and 2 columns.
</span><span class="kw">let </span>a = Matrix::new(<span class="number">3</span>, <span class="number">2</span>, <span class="macro">vec!</span>[<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>, <span class="number">6.0</span>]);</code></pre></div>
<p>The matrices are stored in row-major order. This means in the example above the top
row will be [1, 2].</p>
<p>We can perform operations on matrices.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rulinalg::matrix::Matrix;
<span class="comment">// A new matrix with 3 rows and 2 columns.
</span><span class="kw">let </span>a = Matrix::new(<span class="number">3</span>, <span class="number">2</span>, <span class="macro">vec!</span>[<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>, <span class="number">6.0</span>]);
<span class="kw">let </span>b = Matrix::new(<span class="number">3</span>, <span class="number">2</span>, <span class="macro">vec!</span>[<span class="number">6.0</span>, <span class="number">5.0</span>, <span class="number">4.0</span>, <span class="number">3.0</span>, <span class="number">2.0</span>, <span class="number">1.0</span>]);
<span class="comment">// Produces a 3x2 matrix filled with sevens.
</span><span class="kw">let </span>c = a + b;</code></pre></div>
<p>Sometimes we want to construct small matrices by hand, usually for writing unit tests
or examples. For this purpose, <code>rulinalg</code> provides the <code>matrix!</code> macro:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// Remember to enable macro usage in rulinalg!
</span><span class="attribute">#[macro_use]
</span><span class="kw">extern crate </span>rulinalg;
<span class="comment">// Construct a 3x3 matrix of f64
// Commas separate columns and semi-colons separate rows
</span><span class="kw">let </span>mat = <span class="macro">matrix!</span>[<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>;
<span class="number">4.0</span>, <span class="number">5.0</span>, <span class="number">6.0</span>;
<span class="number">7.0</span>, <span class="number">8.0</span>, <span class="number">9.0</span>];</code></pre></div>
<p>Of course the library can support more complex operations but you should check the individual
modules for more information.</p>
<h2 id="matrix-slices"><a href="#matrix-slices">Matrix Slices</a></h2>
<p>Often times it is desirable to operate on only a sub-section of a <code>Matrix</code> without copying this block.
Rulinalg allows this via the <code>MatrixSlice</code> and <code>MatrixSliceMut</code> structs. These structs can be created
from <code>Matrix</code> structs and follow all of the borrowing rules of Rust.</p>
<p>Note finally that much of the <code>Matrix</code>/<code>MatrixSlice</code>/<code>MatrixSliceMut</code> functionality is contained behind
the <code>BaseMatrix</code>/<code>BaseMatrixMut</code> traits. This allows us to be generic over matrices or slices.</p>
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><div class="item-table"><div class="item-row"><div class="item-left import-item" id="reexport.VectorNorm"><code>pub use norm::<a class="trait" href="norm/trait.VectorNorm.html" title="trait rulinalg::norm::VectorNorm">VectorNorm</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.MatrixNorm"><code>pub use norm::<a class="trait" href="norm/trait.MatrixNorm.html" title="trait rulinalg::norm::MatrixNorm">MatrixNorm</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.VectorMetric"><code>pub use norm::<a class="trait" href="norm/trait.VectorMetric.html" title="trait rulinalg::norm::VectorMetric">VectorMetric</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.MatrixMetric"><code>pub use norm::<a class="trait" href="norm/trait.MatrixMetric.html" title="trait rulinalg::norm::MatrixMetric">MatrixMetric</a>;</code></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="convert/index.html" title="rulinalg::convert mod">convert</a></div><div class="item-right docblock-short">The convert module.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="error/index.html" title="rulinalg::error mod">error</a></div><div class="item-right docblock-short">Error handling for the linalg module.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="macros/index.html" title="rulinalg::macros mod">macros</a></div><div class="item-right docblock-short">Macros for the linear algebra modules.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="matrix/index.html" title="rulinalg::matrix mod">matrix</a></div><div class="item-right docblock-short">The matrix module.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="norm/index.html" title="rulinalg::norm mod">norm</a></div><div class="item-right docblock-short">The norm module</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="ulp/index.html" title="rulinalg::ulp mod">ulp</a></div><div class="item-right docblock-short">Tools for ULP-based comparison of floating point numbers.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="utils/index.html" title="rulinalg::utils mod">utils</a></div><div class="item-right docblock-short">Linear algebra utils module.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="vector/index.html" title="rulinalg::vector mod">vector</a></div><div class="item-right docblock-short">The vector module.</div></div></div><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_matrix_eq.html" title="rulinalg::assert_matrix_eq macro">assert_matrix_eq</a></div><div class="item-right docblock-short">Compare matrices for exact or approximate equality.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_scalar_eq.html" title="rulinalg::assert_scalar_eq macro">assert_scalar_eq</a></div><div class="item-right docblock-short">Compare scalars for exact or approximate equality.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_vector_eq.html" title="rulinalg::assert_vector_eq macro">assert_vector_eq</a></div><div class="item-right docblock-short">Compare vectors for exact or approximate equality.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.matrix.html" title="rulinalg::matrix macro">matrix</a></div><div class="item-right docblock-short">The <code>matrix!</code> macro enables easy construction of small matrices.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.vector.html" title="rulinalg::vector macro">vector</a></div><div class="item-right docblock-short">The <code>vector!</code> macro enables easy construction of small vectors.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="rulinalg" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>