GithubHelp home page GithubHelp logo

chrissimpkins / vectora Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 297 KB

A Rust library for n-dimensional vector computation with real and complex scalar data

Home Page: https://docs.rs/crate/vectora/latest

License: Apache License 2.0

Rust 100.00%
vector vector-math vector-computations 2d 3d rust rust-lang scalar rust-crate rust-library

vectora's Introduction

A Rust library for vector computation

Crates.io docs.rs GitHub

Test Status

stable toolchain unit tests beta toolchain unit tests clippy lints rustfmt check

About

Vectora is a library for n-dimensional vector computation with real and complex scalar types. The main library entry point is the Vector struct. Please see the Gettting Started Guide for a detailed library API overview with examples.

User documentation

User documentation is available at https://docs.rs/vectora.

Minimum Rust Version Compatibility Policy

This project parameterizes generics by constants and relies on the constant generics feature support stabilized in Rust v1.51.0.

The minimum supported rustc version is believed to be v1.51.0.

Include Vectora in Your Project

Import the library in the [dependencies] section of your Cargo.toml file:

Cargo.toml

[dependencies]
vectora = "0.8.1"

Developer documentation

Contributing

L4 Header Issues

The issue tracker is available on the GitHub repository. Don't be shy. Please report any issues that you identify so that we can address them.

L4 Header Source contributions

Contributions are welcomed. Submit your changes as a GitHub pull request. Please add new tests for source contributions that our current test suite does not cover.

L4 Header Clone the repository

git clone https://github.com/chrissimpkins/vectora.git

L4 Header Testing

The project is tested with the latest GitHub Actions macOS, Linux (Ubuntu), and Windows environment runners using the stable and beta rustc toolchains.

Unit and doc test suite

Edit the source files, then run the unit and doc test suite locally with the command:

cargo test
Unit tests only
cargo test --lib
Doc tests only
cargo test --doc
Clippy lints

Clippy lints are not executed with the above commands. Use the following to lint Rust source files with clippy:

cargo clippy -- -D warnings
Fuzzing

This crate supports cargo fuzz + libFuzzer based fuzzing with the nightly rustc toolchain in supported environments.

Install the rustc nightly toolchain.

Then, install cargo-fuzz with:

cargo +nightly install -f cargo-fuzz

Edit the fuzz target source in the fuzz/fuzz_vectora.rs file and begin fuzzing with the command:

cargo +nightly fuzz run fuzz_vectora

Please see the Fuzzing with cargo-fuzz chapter of the Rust Fuzz book for additional documentation.

L4 Header Documentation contributions

The docs.rs documentation is authored in the Rust source files. Edit the text and build a local version of the project documentation for review with the command:

cargo doc

The documentation index.html page can be found on the following relative path from the repository's root: target/doc/vectora/index.html.

Submit your doc edits as a GitHub pull request.

Changes

Please see CHANGELOG.md.

License

Vectora is released under the Apache License, v2.0.

vectora's People

Contributors

chrissimpkins avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vectora's Issues

Add M × N matrix scalar multiplication support

Requirements:

  • any M by N matrix size
  • any supported T numeric scalar type

Properties:

  • Associative: where c, d are scalar values and A is a matrix, (cd)A=c(dA)
  • Distributive: where c,d are scalar values and A, B are matrices with the same dimension c(A+B)=cA+cB and (c+d)A=cA+dA
  • Multiplicative identity: where 1 is the scalar value 1 and A is a matrix 1A=A
  • Multiplicative property with zero: where 0 is the scalar value 0, A is a matrix, and O is the zero matrix with the same dimensions as A: 0⋅A=O

Add M × N matrix:matrix addition support

Requirements:

  • left hand side and right hand side matrix column and row lengths must be the same

Properties:

  • commutative (A + B = B + A)
  • associative ((A + B) + C = A + (B + C))
  • additive identity with zero matrix (A + 0)
  • additive inverse (A + -A)

Add M × N Matrix type and matrix arithmetic support

I am thinking about how to approach higher-level abstractions of finite vector spaces as collections of Vector.

Motivating case: a Bezier closed contour defined as an ordered list of 2-tuple of x, y coordinates in a Cartesian coordinate system.

This begins to head into more extensive linear algebra support terrain.

Update README documentation links with docs.rs

Vectora is a library for n-dimensional vector computation. The main library entry point is the Vector struct. Please see the Gettting Started guide for a detailed library API overview with examples.

The library entry point and Getting Started guide URL need to be updated once we push to crates.io and have the first docs.rs documentation build.

Add unchecked Vector methods

The data validity checks that were used in the default implementation (added in #49) significantly slow the calculation of a harmonic mean with f32 and f64 data (Criterion benchmarks added in the same PR).

Consider adding an unchecked version that is more performant and assumes data validation by the user. Perhaps under an optional feature and not part of the default crate distribution. Panics will occur with zero values. Use of values < 0.0 will not panic, but return f32 or f64 values that are not valid geometric means.

A refactor to:

let sum_of_reciprocal = self.components.iter().copied().map(|x| x.powi(-1)).sum::<T>();

in place of the #49 approach improves execution time from:

Vector mean_harmonic method: f64 5D Vector
                        time:   [4.6057 ns 4.6161 ns 4.6294 ns]
                        change: [+0.0120% +0.2572% +0.5116%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high severe

to:

Vector mean_harmonic method: f64 5D Vector
                        time:   [542.75 ps 543.07 ps 543.48 ps]
                        change: [-88.222% -88.193% -88.164%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  3 (3.00%) high mild
  8 (8.00%) high severe

The f32 benchmark changes are comparable.

Test environment:

MBP 16" 2021
Apple M1 Max
32GB RAM
macOS 12.1

related #44
related #8

Add M × N matrix : vector addition support

Requirements:

  • matrix and vector column and row lengths must be the same

Properties:

commutative (A + B = B + A)
associative ((A + B) + C = A + (B + C))
additive identity with zero matrix (A + 0)
additive inverse (A + -A)

Questions:

  • how do we approach the Vector shape? Always a column vector?

Add Vector enumerate method

Add support for an enumerate method that returns an Iterator over tuples of (index number, reference to Vector item at the respective index number).

Support scalar real integer and float multiplication with Complex Vector types

Add support for scalar multiplication * operator overload that scales the real and imaginary parts with a real integer or float scalar value. The scalar type must be the same type as that used for the real and imaginary parts of the num::Complex number.

This will support:

  • num::Complex * all int types
  • num::Complex * all float types

and supplements the num::Complex number * num::Complex number multiplication operator overload that was added in #14.

Add M × N matrix : vector subtraction support

Requirements:

Left hand side Matrix and right hand side Vector must have the same row and column dimensions.

Properties:

anti-commutative: A - B = -(B - A)
non-associative (order of subtraction operations matters)
subtraction with additive identity matrix (zero matrix) yields the same matrix

Questions:

  • how do we approach the Vector shape? Always a column vector?

Broaden Vector numeric type cast support

Broaden numeric type cast support with to_[TYPE] methods that are defined in the num::ToPrimitive trait. These methods will return Option<Vector<[TYPE], N>> with None returned when the cast does not fall within the range of scalars supported by the type.

Add complex number support to Vector type

Complex numbers can currently be expressed as 2-Vectors of real and imaginary parts. It might be useful to support Vector collections of complex numbers as defined by the num crate Complex type. This should be partially implemented already with our generic approach. Requires additional research and tests. Focus on the areas of the source with Float rather than Num trait bounds.

Add `matrix!` macro for initialization of `Matrix` structs with array-like syntax

Add a matrix! macro that supports the following Matrix struct initialization idioms:

With row vectors that define each ordered scalar value

let m = matrix!(
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
);

With row vectors that use an array-like repetition pattern

The following will make a 3 x 5 Matrix filled with 1's.

let m = matrix!(
    [1; 5],
    [1; 5],
    [1; 5]
);

This macro will take row vectors only.

Add M × N Matrix : Matrix multiplication support

Requirements:

for matrices A (=lhs) and B (=rhs):

  • the column number in A must match the row number in B

Properties

for matrices A, B, and C:

  • not commutative: AB ≠ BA)
  • associative: (AB)C = A(BC)
  • left distributive: A(B + C) = AB + AC
  • right distributive: (B + C)A = BA + CA
  • multiplication by zero matrix yields zero matrix: A0 = 0A = 0

Add `vector` macro for initialization of `Vector` with argument-defined type and length

The approach will be similar to that used by the standard lib vec! macro for Vec types and will support the following initialization syntax:

Comma-delimited list of numbers with the same type

use vectora::vector;

use num::Complex;

let v_int = vector![1, 2, 3];
let v_float = vector![1.0, 2.0, 3.0];
let v_complex = vector![Complex::new(1, 2), Complex::new(-1, -2), Complex::new(-1, 2)];

[NUM; LEN] expansion syntax

use vectora::vector;

use num::Complex;

let v_int: Vector<i32, 3> = vector![1; 3];
let v_float: Vector<f64, 3> = vector![1.0; 3];
let v_complex: Vector<Complex<i32>, 3> = vector![Complex::new(1, 2); 3];

Add `try_vector` macro for initialization of a `Vector` with fallible data collection types

This approach will take a single data collection argument type that is supported by the Vector TryFrom trait implementations. These are data collection types that may not have known length at compile time.

The approach with a std lib Vec type will be:

let stdlib_vec = vec![1, 2, 3];
let v: Vector<i32, 3> = try_vector!(stdlib_vec).unwrap();

The macro will return an error when the std lib Vec length differs from the requested Vector length:

let stdlib_vec = vec![1, 2, 3, 4, 5];

// expected length 3, received length 5
let res: Result<Vector<i32, 3>, _> = try_vector!(stdlib_vec);

assert!(res.is_err());

Add parallel feature

Add optional feature support for rayon-based parallel iterators over, and parallel slices of, Vector scalar data.

Add M × N matrix:matrix subtraction support

Requirements:

  • left hand side and right hand side matrices must have the same row and column dimensions

Properties:

  • anti-commutative: A - B = -(B - A)
  • non-associative (order of subtraction operations matters in contrast to matrix addition)
  • subtraction with additive identity matrix (zero matrix) yields the same matrix

Add floating point Vector approximate equivalence support for customizable absolute, relative epsilon, and units in last place (ULPs) comparisons

The default [Vector] == [Vector] operator overload approach uses the approx crate default relative epsilon floating point approximate eq implementation. This defines the epsilon and max relative values for the user. The goals of the operator overload are simplicity and coverage of a broad range of common float Vector type comparison use cases.

Let's broaden support to include more floating point comparison approaches, and greater flexibility by allowing the user to define custom parameters for these comparisons according to their needs.

Will broaden our relative epsilon eq approach to support:

  • definition of epsilon value
  • definition of max relative value

This will work through a new method. The == operator overload strategy will remain unchanged.

Will add:

  • absolute eq comparisons with support for custom epsilon definitions
  • units in last place (ULPs) eq comparisons with support for custom epsilon and max ULPs definitions

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.