Skip to content

MoreMaps.jl

A flexible mapping framework for Julia that provides different parallel backends, progress tracking, and iteration patterns.

Features

  • Multiple backends: Sequential, Threaded, Distributed (Pmap), and Daggermap execution

  • Progress tracking: LogLogger, ProgressLogger, TermLogger, and QualityLogger

  • Nested array support: Map over specific leaf types in nested array structures

  • Cartesian (and arbitrary) expansions: Easy combinatorial iteration over inputs

  • Tuple / NamedTuple inputs: Map over Tuples and NamedTuples, returning the same shape

  • DimensionalData support: Map directly over Dimension arguments

Quick Start

julia
using MoreMaps

# Basic usage with default sequential backend
x = rand(100)
C = Chart()
y = map(sqrt, C, x)

# Use threading for parallel execution
C_threaded = Chart(Threaded())
y_threaded = map(sqrt, C_threaded, x)

# Add progress tracking
C_progress = Chart(Threaded(), LogLogger(10))
y_progress = map(sqrt, C_progress, x)
100-element Vector{Float64}:
 0.34914961360310737
 0.40055702518911207
 0.8807955343170545
 0.9057378512767278
 0.8972943616114474
 0.9547030006771129
 0.5568015092010962
 0.6630790200376405
 0.7318565800561634
 0.6394248531802791

 0.8970944646092702
 0.8252408887884574
 0.5504704290538582
 0.34047163365563593
 0.7863103920454634
 0.8060433938886132
 0.5786580637306644
 0.6122977934594961
 0.22436979701217263

You can also pass a Backend or Progress value (or even the bare type) directly to map, and a default Chart wrapping it will be constructed for you:

julia
using MoreMaps
x = rand(10)
map(sqrt, Threaded(), x)        # equivalent to map(sqrt, Chart(Threaded()), x)
map(sqrt, LogLogger(5), x)      # equivalent to map(sqrt, Chart(LogLogger(5)), x)
10-element Vector{Float64}:
 0.8714702033471169
 0.3229929329400027
 0.2886206567029162
 0.836329964017776
 0.9149352222326682
 0.9549539706887665
 0.8955996479801254
 0.8358746224451905
 0.8604450093324014
 0.6508575991701937

Basics

The basis of a MoreMaps map is the Chart type, which configures how mapping operations are executed.

A Chart is parameterised by four things:

  • backend: Specifies the execution backend

  • progress: Configures the progress logging behavior

  • leaf: The element type where recursion terminates, used for mapping nested arrays. Stored as a type parameter rather than a field.

  • expansion: Determines how the input iterables are combined (e.g. Cartesian product). Either NoExpansion() or a Function.

A chart can be constructed using keywords or arbitrary-order positional arguments. The default Chart() reproduces Base.map(), and is constructed as:

julia
C = Chart(backend   = Sequential(),    # No parallel execution; similar to Base.map
          progress  = NoProgress(),    # No progress logging
          leaf      = MoreMaps.All,    # Map over each element of the root array, like Base.map
          expansion = NoExpansion())   # Map over the original input arrays, as for Base.map

# Or, using positional arguments in any order. Each argument is dispatched on its
# type: `Backend` -> backend, `Progress` -> progress, `Type` -> leaf, `Function`
# -> expansion.
C = Chart(Sequential(), NoProgress(), MoreMaps.All, NoExpansion())

# Default behavior
C == Chart()

Mapping

Once you have a Chart, pass it to the standard Base.map function:

julia
using MoreMaps

x = rand(10)
C = Chart()
y = map(sqrt, C, x)
y == map(sqrt, x)
true

Tuple and NamedTuple inputs are supported and the result is returned with the same shape:

julia
map(x -> x^2, Chart(), (1, 2, 3))             # -> Tuple
map(x -> x^2, Chart(), (a = 1, b = 2, c = 3)) # -> NamedTuple
(a = 1, b = 4, c = 9)

See the following pages for details on configuring a Chart:

  • Backends - Execution strategies (Sequential, Threaded, Pmap, Daggermap)

  • Progress - Progress tracking options (LogLogger, ProgressLogger, TermLogger, QualityLogger, NoProgress)

  • Leaves - Nested array handling

  • Expansions - Cartesian product and custom iterations