Skip to content

A Julia package for representing multi-dimensional grids

License

Notifications You must be signed in to change notification settings

JuliaArrays/LazyGrids.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

98a0dc7 · Feb 2, 2022

History

34 Commits
Feb 2, 2022
Jul 12, 2021
Jul 10, 2021
Feb 2, 2022
Feb 1, 2022
Jul 8, 2021
Jul 6, 2021
Feb 1, 2022
Jul 10, 2021

Repository files navigation

LazyGrids.jl

A Julia package for representing multi-dimensional grids

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

action status pkgeval status codecov license docs-stable docs-dev code-style

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.GridAR{Float64, 2, 2}:
 3.0  3.5  4.0
 3.0  3.5  4.0

julia> x = LinRange(-1,1,1001)
1001-element LinRange{Float64}: ...

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
40

Related packages