Collection math-related utilities developed at Body Labs
Collection of math-related utilities developed at Body Labs.
This is a legacy library in active maintenance. The goals are:
Keep the library working in current versions of Python and other tools.
Make bug fixes.
Provide API stability and backward compatibility with the upstream version.
The main thrust is to transition the functionality in this library (and the code which depends on it, such as lace to new libraries include vg and polliwog. In general, new functionality should be added in the new libraries. As needed, additional libraries can be added to the lace org.
brew install homebrew/science/suite-sparse brew install homebrew/science/opencv --without-numpy
sudo apt-get install python-opencv libsuitesparse-dev
Install the library
pip install blmath
And import it just like the upstream library:
from blmath.numerics import vx
A collection of math related utilities used by many bits of BodyLabs’ code.
Functions for manipulating numeric arrays, numbers, and linear algebra.
The most commonly used of these are directly imported into blmath.numerics.
blmath.numerics.vx is a namespace of common linear algebra operations. These are easily expressed in numpy, but abstracted for readability purposes.
blmath.numerics.coercion contains a validation function as_numeric_array, which produces useful error messages up front on bad inputs, in place of cryptic messages like “cannot broadcast…” later on.
blmath.numerics.operations contains basic numerical operations such as zero_safe_divide.
blmath.numerics.predicates contains functions like isnumeric.
blmath.numerics.rounding contains functions including “round to nearest” and roundedlist.
blmath.numerics.numpy_ext contains numpy utility functions.
blmath.numerics.matlab contains some matlab shortcuts which have no numpy equivalent. At MPI the fitting code was originally written in Matlab before it was ported to Python.
blmath.numerics.linalg contains linear algebra operations.
blmath.numerics.linalg.sparse_cg contains a faster matrix solve optimized for sparse Jacobians.
blmath.numerics.linalg.lchol contains a Cythonized implementation of Cholesky factorization.
blmath.numerics.linalg.isomorphism computes the isomorphism between two bases.
blmath.numerics.linalg.gram_schmidt provides a function for orthonormalization.
Geometric operations, transforms, and primitives, in 2D and 3D.
The most commonly used of these are directly imported into blmath.geometry.
blmath.geometry.Box represents an axis-aligned cuboid.
blmath.geometry.Plane represents a 2-D plane in 3-space (not a hyperplane).
blmath.geometry.Polyline represents an unconstrained polygonal chain in 3-space.
blmath.geometry.transform includes code for 3D transforms.
blmath.geometry.transform.CompositeTransform represents a composite transform using homogeneous coordinates. (Thanks avd!)
blmath.geometry.transform.CoordinateManager provides a convenient interface for named reference frames within a stack of transforms and projecting points from one reference frame to another.
blmath.geometry.transform.find_rigid_transform finds a rotation and translation that closely transforms one set of points to another. Its cousin find_rigid_rotation does the same, but only allows rotation, not translation.
blmath.geometry.transform.rotation.rotation_from_up_and_look produces a rotation matrix that gets a mesh into the canonical reference frame from “up” and “look” vectors.
blmath.geometry.apex provides functions for finding the most extreme point.
blmath.geometry.barycentric provides a function for projecting a point to a triangle using barycentric coordinates.
blmath.geometry.convexify provides a function for producing a convex hull from a mostly-planar curve.
blmath.geometry.segment provides functions for working with line segments in n-space.
Class for wrapping and manipulating value/units pairs.
TODO write something here
pip install -r requirements_dev.txt pip install -e . # builds the native extension rake unittest rake lint
Tests are configured to run in both python 2.7 and 3.6 locally via tox as well as in CircleCI. To run tests in multiple versions of python, run tox:
pip install -r requirements_dev.txt tox
You need to make sure that python2.7 and python3.6 are valid commands; this can be done in pyenv via pyenv global 3.6.5 2.7.15
Pull requests welcome!
If you are having issues, please let us know.
This collection was developed at Body Labs and includes a combination of code developed at Body Labs, from legacy code and significant new portions by Eric Rachlin, Alex Weiss, and Paul Melnikow. It was extracted from the Body Labs codebase and open-sourced by Alex Weiss. In 2018 it was forked by Paul Melnikow and published as metablmath. Thanks to a repository and package transfer from Body Labs, the fork has been merged back into the original.
The project is licensed under the two-clause BSD license.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.