3 ms·
Somewhat related: I've developed a library for operations involving multi-dimensional arrays [1, 2]. When possible it uses GCC for jit-compilation to achieve hi
by wedesoft 13y ago
Somewhat related: I've developed a library for operations involving multi-dimensional arrays [1, 2]. When possible it uses GCC for jit-compilation to achieve higher performance.
require 'multiarray'
include Hornetseye
# Object
lazy(4) { |i| i + 2 }
# Sequence(INT):
# [ 2, 3, 4, 5 ]
lazy(3, 2) { |x, y| x }
# MultiArray(INT,2):
# [ [ 0, 1, 2 ],
# [ 0, 1, 2 ] ]
lazy(3, 2) { |x, y| x + 1 }
# MultiArray(INT,2):
# [ [ 1, 2, 3 ],
# [ 1, 2, 3 ] ]
lazy(3, 3) { |x, y| y + 4 }
# MultiArray(INT,2):
# [ [ 4, 4, 4 ],
# [ 5, 5, 5 ],
# [ 6, 6, 6 ] ]
lazy(3, 3) { |x, y| (x + 1) * (y + 4) }
# MultiArray(INT,2):
# [ [ 4, 8, 12 ],
# [ 5, 10, 15 ],
# [ 6, 12, 18 ] ]
lazy { |x,y| Sequence['n', 'p', 'r', 't'][x] + Sequence['a', 'i', 'u', 'e', 'o'][y] }
# MultiArray(OBJECT,2):
# [ [ "na", "pa", "ra", "ta" ],
# [ "ni", "pi", "ri", "ti" ],
# [ "nu", "pu", "ru", "tu" ],
# [ "ne", "pe", "re", "te" ],
# [ "no", "po", "ro", "to" ] ]
s = lazy(33) { |i| 3 * (i+1) }
# Sequence(INT):
# [ 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, .... ]
s.mask((s % 2).eq(0)).collect { |i| i ** 2 / 3 }
# Sequence(INT):
# [ 12, 48, 108, 192, 300, 432, 588, 768, 972, 1200, 1452, 1728, .... ]
[1] https://github.com/wedesoft/multiarray https://github.com/wedesoft/multiarray
[2] http://www.wedesoft.de/hornetseye-api/ http://www.wedesoft.de/hornetseye-api/