Skip to content

Latest commit

 

History

History
94 lines (74 loc) · 3.55 KB

README.md

File metadata and controls

94 lines (74 loc) · 3.55 KB

LazyGrids.jl

A Julia package for representing multi-dimensional grids.

https://github.com/JuliaArrays/LazyGrids.jl

docs-stable docs-dev action status pkgeval status codecov license Aqua QA code-style deps version pkgeval

Methods

This package exports the following methods:

  • ndgrid : a "lazy" version of ndgrid that returns a tuple of AbstractArray objects essentially instantly with just a few bytes of memory allocated.
  • ndgrid_array : return a traditional tuple of Array objects, which takes much longer to create and can use a lot of memory. It is not recommended, but is included for comparison purposes.

See the documentation linked in the blue badges above for examples, and for a 1-line lazy version of meshgrid.

As shown in the examples, the lazy version typically is as fast, if not faster, than using conventional dense Array objects.

Example

julia> using LazyGrids
(xg, yg) = ndgrid(1:2, 3:0.5:4)
([1 1 1; 2 2 2], [3.0 3.5 4.0; 3.0 3.5 4.0])

julia> xg
2×3 LazyGrids.GridUR{Int64, 1, 2}:
 1  1  1
 2  2  2

julia> yg
2×3 LazyGrids.GridSL{Float64, 2, 2, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}:
 3.0  3.5  4.0
 3.0  3.5  4.0

julia> x = range(-1,1,1001)
-1.0:0.002:1.0

julia> (xg, yg, zg) = ndgrid(x, x, x)
{... lots of output ...}

julia> size(xg) # show array dimensions
(1001, 1001, 1001)

julia> sizeof(xg) # show number of bytes used
72

Related packages

Compatibility

Tested with Julia ≥ 1.10.