6 Arrays

Performance Warning: Indexing the elements of arrays created in untyped Racket is currently 25-50 times slower than doing the same in Typed Racket, due to the overhead of checking higher-order contracts. We are working on it.

For now, if you need speed, use the typed/racket language.

 (require math/array) package: math-lib

One of the most common ways to structure data is with an array: a rectangular grid of homogeneous, independent elements. But an array data type is usually absent from functional languages’ libraries. This is probably because arrays are perceived as requiring users to operate on them using destructive updates, write loops that micromanage array elements, and in general, stray far from the declarative ideal.

Normally, they do. However, experience in Python, and more recently Data-Parallel Haskell, has shown that providing the right data types and a rich collection of whole-array operations allows working effectively with arrays in a functional, declarative style. As a bonus, doing so opens the possibility of parallelizing nearly every operation.

    6.1 Quick Start

    6.2 Definitions

    6.3 Broadcasting

      6.3.1 Broadcasting Rules

      6.3.2 Broadcasting Control

    6.4 Slicing

      6.4.1 (Sequenceof Integer): pick rows

      6.4.2 Slice: pick rows in a length-aware way

      6.4.3 Slice-Dots: preserve remaining axes

      6.4.4 Integer: remove an axis

      6.4.5 Slice-New-Axis: add an axis

    6.5 Nonstrict Arrays

      6.5.1 Caching Nonstrict Elements

      6.5.2 Performance Considerations

    6.6 Types, Predicates and Accessors

    6.7 Construction

    6.8 Conversion

      6.8.1 Printing

    6.9 Comprehensions and Sequences

    6.10 Pointwise Operations

      6.10.1 Broadcasting

    6.11 Indexing and Slicing

    6.12 Transformations

    6.13 Folds, Reductions and Expansions

      6.13.1 Axis Folds

      6.13.2 Whole-Array Folds

      6.13.3 General Reductions and Expansions

    6.14 Other Array Operations

      6.14.1 Fast Fourier Transform

    6.15 Subtypes

      6.15.1 Flonum Arrays

      6.15.2 Float-Complex Arrays

    6.16 Strictness