项目作者: wqferr

项目描述 :
Vectorization library for lua
高级语言: C
项目地址: git://github.com/wqferr/lua-vectorize.git
创建时间: 2020-12-24T00:57:45Z
项目社区:https://github.com/wqferr/lua-vectorize

开源协议:GNU General Public License v3.0

下载


Vectorize

A modern numeric library for Lua.

Motivation

While Lua is a simple, flexible, and easily expandable language, it is not
efficient when operating on sequences. In particular, this is important
when dealing with high-dimensional vectors, since even O(n) algorithms can
lead to significant wait times for large enough vectors.

Historically, NumLua has served to
help with this use case. However, the last contribution to its GitHub
repository was 10 years ago. Newer versions of Lua have been released, and
their FFI has changed significantly, now being incompatible with the one
NumLua was coded for.

This project aims to add many features of NumLua over time. For now, it
only supports basic vector operations such as vector addition, scaling,
hadamard product, and normalizing, as well as element-wise trigonometric
and exponential functions.

Example Usage

  1. local vec = require "vec"
  2. local v = vec {2, 0, 1}
  3. -- Functions can be accessed by the vec table
  4. print(vec.sum(v)) --> 3.0
  5. -- Or directly as methods
  6. print(v:sum()) --> 3.0
  7. -- Operator broadcasting
  8. print(v + 2) --> [4.0, 2.0, 3.0]
  9. print(v ^ 0.5) --> [1.41, 0.0, 1.0]
  10. -- 50 equally-spaced values between 0 and pi
  11. local t = vec.linspace(0, math.pi, 50)
  12. print(t[1], t[50]) -- 0.0 3.14
  13. -- Evaluate sin at every point of t
  14. local s = vec.sin(t) -- or local s = t:sin()
  15. local area = vec.trapz(s, t) -- integrate using trapezoid rule
  16. print(area) -- 1.99
  17. -- Allows for in-place operations to avoid unnecessary allocs
  18. local x = vec.linspace(-2, 2, 1001)
  19. for _ = 1, 1000 do
  20. x:sin_()
  21. -- ^ Extra _ at the end of the function name stores
  22. -- result in the same variable, or you can define
  23. -- a destination vector as an additional parameter.
  24. -- See doc/vec.md for more information
  25. end
  26. print(x) -- sin(sin(sin(sin(...sin(x)))))

Documentation

The full reference to the functions implemented in this library can be found in
the doc directory. See doc/vector.md for basic vector
functions. See also doc/ode.md for basic ODE numerical
integration functions.

Future Development

For now I am the only developer for the project. The current things I wish to
implement in the future can be found in the TODO.md file.