Snuggs
Snuggs is a Python library that provides s-expressions for Numpy, allowing users to define and evaluate array computations using a Lisp-like syntax. It is currently at version 1.4.7 and appears to have a stable, though not frequently updated, release cadence, with the last release in September 2019.
Warnings
- deprecated The `kwd_dict` parameter in `snuggs.eval()` is deprecated. Users should pass context variables directly as keyword arguments instead.
- gotcha Snuggs does not provide performance optimizations like multithreading or elimination of temporary data, unlike libraries such as `numexpr`. It is primarily designed for simple calculator programs.
- gotcha When using functions or operators that reference the order in which values have been provided within the evaluation context (e.g., 'read' function), it's important to pass a dictionary, specifically an `OrderedDict`, as keyword arguments might not preserve order.
Install
-
pip install snuggs
Imports
- snuggs
import snuggs
Quickstart
import snuggs
import numpy as np
# Basic arithmetic
result_add = snuggs.eval('(+ 1 2)')
print(f"Addition: {result_add}")
# Array creation and multiplication
result_multiply_array = snuggs.eval("(* 3.5 (asarray 1 1))")
print(f"Multiply with array: {result_multiply_array}")
# Evaluation with a local context
ctx_array = np.array([2, 2])
result_context = snuggs.eval("(+ (asarray 1 1) b)", b=ctx_array)
print(f"With context: {result_context}")