nu_plugin_vec
A plugin for Nushell, a cross-platform shell and scripting language. This plugin adds support for vector operations.
Installation
Cargo
Get the latest version from crates.io with a local install:
Manual build
Manual builds can also be used:
Features
The plugin offers adds some new commands, which aim to make scripting vector-like operations a smoother experience. Below, a few use cases are shown, which outline the difference this plugin makes.
Showcase
Addition and subtraction
# Vanilla Nushell
$vec1 | zip $vec2 | each { |pair| ($pair | first) + ($pair | last) }
# Nushell + nu_plugin_vec
$vec1 | vec add $vec2
Dot product
# Vanilla Nushell
$vec1 | zip $vec2 | each { |pair| ($pair | first) * ($pair | last) } | math sum
# Nushell + nu_plugin_vec
$vec1 | vec dot $vec2
Vector similarity
# Vanilla Nushell
let dot_product = ($vec1 | zip $vec2 | each { |pair| ($pair | first) * ($pair | last) } | math sum)
let magnitude1 = ($vec1 | each { |v| $v * $v } | math sum | math sqrt)
let magnitude2 = ($vec2 | each { |v| $v * $v } | math sum | math sqrt)
$dot_product / ($magnitude1 * $magnitude2)
# Nushell + nu_plugin_vec
$vec1 | vec cos $vec2
Command list
The list of commands currently available is as follows:
vec addandvec subfor addition and subtractionvec cosandvec sinfor angle calculationvec dotfor dot productsvec sqnormandvec magnitudefor length measurementsvec normalizefor conversions into unit vectors
For more information, invoke help <command> in your Nushell session.