Crates.io | nu_plugin_vec |
lib.rs | nu_plugin_vec |
version | 1.1.1 |
source | src |
created_at | 2024-10-12 21:15:11.695296 |
updated_at | 2024-10-22 18:00:05.994973 |
description | A Nushell plugin implementing vector operations |
homepage | https://github.com/PhotonBursted/nu_plugin_vec |
repository | |
max_upload_size | |
id | 1406881 |
size | 93,279 |
A plugin for Nushell, a cross-platform shell and scripting language. This plugin adds support for vector operations.
Get the latest version from crates.io with a local install:
cargo install nu_plugin_vec # Downloads and installs the plugin
plugin add ~/.cargo/bin/nu_plugin_vec # Registers the plugin with Nushell
plugin use vec # Activates the plugin
Manual builds can also be used:
git clone https://github.com/PhotonBursted/nu_plugin_vec.git # Clone the repository
cd nu_plugin_vec # Enter the repo folder
cargo build -r # Build a release version of the plugin
plugin add target/release/nu_plugin_vec # Registers the plugin with Nushell
plugin use vec # Activates the plugin
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.
# Vanilla Nushell
$vec1 | zip $vec2 | each { |pair| ($pair | first) + ($pair | last) }
# Nushell + nu_plugin_vec
$vec1 | vec add $vec2
# Vanilla Nushell
$vec1 | zip $vec2 | each { |pair| ($pair | first) * ($pair | last) } | math sum
# Nushell + nu_plugin_vec
$vec1 | vec dot $vec2
# 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
The list of commands currently available is as follows:
vec add
and vec sub
for addition and subtractionvec cos
and vec sin
for angle calculationvec dot
for dot productsvec sqnorm
and vec magnitude
for length measurementsvec normalize
for conversions into unit vectorsFor more information, invoke help <command>
in your Nushell session.