product_index

Crates.ioproduct_index
lib.rsproduct_index
version0.1.0
sourcesrc
created_at2023-11-17 15:44:36.84393
updated_at2023-11-17 15:44:36.84393
descriptionConvert a cartesian product index into the N indicies of the original arrays
homepagehttps://github.com/chappertron/product_index
repositoryhttps://github.com/chappertron/product_index
max_upload_size
id1039196
size19,628
Aidan Chapman (chappertron)

documentation

README

product_index

A tool for get the ND indicies of a grid from a 1D index.

Usage

arr1=($(seq 1 1 5))
arr2=($(seq 1 1 6))

N=12

# prints 2 0
product_index $N "${#arr1[@]}" "${#arr2[@]}" 

# stores i1=2 i2=0
read -r i1 i2 <<< $(product_index $N "${#arr1[@]}" "${#arr2[@]}")

# Prints 3,1
echo "x,y = ${arr1[$i1]}, ${arr2[$i2]}"

Installation

To install from crates: cargo install product_index

To install manually, clone the repo and use cargo install --path .

Step by step Manual Install

  1. If cargo is not installed, install the rust compilers:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    (See https://www.rust-lang.org/tools/install for more options)
  2. Clone the repo:
    git clone https://github.com/chappertron/product_index.git
    
  3. cd into the repo folder
  4. Run the cargo install command:
    cargo install --path . 
    

You should now be able to access the product_index binary from the command line.

Commit count: 10

cargo fmt