vector: Efficient Arrays

[ bsd3, data, data-structures, library ] [ Propose Tags ] [ Report a vulnerability ]

. An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework . . It is structured as follows: . [Data.Vector] Boxed vectors of arbitrary types. . [Data.Vector.Unboxed] Unboxed vectors with an adaptive representation based on data type families. . [Data.Vector.Storable] Unboxed vectors of Storable types. . [Data.Vector.Primitive] Unboxed vectors of primitive types as defined by the primitive package. Data.Vector.Unboxed is more flexible at no performance cost. . [Data.Vector.Generic] Generic interface to the vector types. . There is also a (draft) tutorial on common uses of vector. . * http://haskell.org/haskellwiki/Numeric_Haskell:_A_Vector_Tutorial


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
boundschecks

Enable bounds checking

Enabled
unsafechecks

Enable bounds checking in unsafe operations at the cost of a significant performance penalty

Disabled
internalchecks

Enable internal consistency checks at the cost of a significant performance penalty

Disabled
wall

Enable all -Wall warnings

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.3, 0.3.1, 0.4, 0.4.1, 0.4.2, 0.5, 0.6, 0.6.0.1, 0.6.0.2, 0.7, 0.7.0.1, 0.7.1, 0.8, 0.9, 0.9.1, 0.10, 0.10.0.1, 0.10.9.0, 0.10.9.1, 0.10.9.2, 0.10.9.3, 0.10.10.0, 0.10.11.0, 0.10.12.0, 0.10.12.1, 0.10.12.2, 0.10.12.3, 0.11.0.0, 0.12.0.0, 0.12.0.1, 0.12.0.2, 0.12.0.3, 0.12.1.0, 0.12.1.1, 0.12.1.2, 0.12.2.0, 0.12.3.0, 0.12.3.1, 0.13.0.0, 0.13.1.0, 0.13.2.0 (info)
Change log changelog.md
Dependencies base (>=4.9 && <4.22), deepseq (>=1.1 && <1.6), primitive (>=0.6.4.0 && <0.10), random (>=1.2), tasty, vector, vector-stream (>=0.1 && <0.2) [details]
Tested with ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.4, ghc ==9.8.2
License BSD-3-Clause
Copyright (c) Roman Leshchinskiy 2008-2012, Alexey Kuleshevich 2020-2022, Aleksey Khudyakov 2020-2022, Andrew Lelechenko 2020-2022
Author Roman Leshchinskiy <rl@cse.unsw.edu.au>
Maintainer Haskell Libraries Team <libraries@haskell.org> Alexey Kuleshevich <alexey@kuleshevi.ch>, Aleksey Khudyakov <alexey.skladnoy@gmail.com>, Andrew Lelechenko <andrew.lelechenko@gmail.com>
Category Data, Data Structures
Home page https://github.com/haskell/vector
Bug tracker https://github.com/haskell/vector/issues
Source repo head: git clone https://github.com/haskell/vector.git(vector)
Uploaded by AlexeyKhudyakov at 2024-10-31T18:01:59Z
Distributions Arch:0.13.1.0, Debian:0.12.1.2, Fedora:0.13.0.0, FreeBSD:0.10.12.3, LTSHaskell:0.13.1.0, NixOS:0.13.1.0, Stackage:0.13.2.0, openSUSE:0.13.1.0
Reverse Dependencies 2058 direct, 12843 indirect [details]
Downloads 422174 total (855 in the last 30 days)
Rating 2.75 (votes: 14) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for vector-0.13.2.0

[back to package description]

The vector package Build Status

Vector is a collection of efficient Int-indexed array implementations: boxed, unboxed, storable, and primitive vectors (all can be mutable or immutable). The package features a generic API, polymorphic in vector type, and implements stream fusion, a powerful optimisation framework that can help eliminate intermediate data structures.

Table of Contents

Tutorial

A beginner-friendly tutorial for vectors can be found on MMHaskell.

If you have already started your adventure with vectors, the tutorial on Haskell Wiki covers more ground.

Vector vs Array

Arrays are data structures that can store a multitude of elements and allow immediate access to every one of them. However, they are often seen as legacy constructs that are rarely used in modern Haskell. Even though Haskell has a built-in Data.Array module, arrays might be a bit overwhelming to use due to their complex API. Conversely, vectors incorporate the array’s O(1) access to elements with a much friendlier API of lists. Since they allow for framework optimisation via loop fusion, vectors emphasise efficiency and keep a rich interface. Unless you’re confident with arrays, it’s well-advised to use vectors when looking for a similar functionality.

Vectors Available in the Package

Lazy boxed vectors (Data.Vector) store each of their elements as a pointer to a heap-allocated value. Because of indirection, lazy boxed vectors are slower in comparison to unboxed vectors.

Strict boxed vectors (Data.Vector.Strict) contain elements that are strictly evaluated.

Unboxed vectors (Data.Vector.Unboxed) determine an array's representation from its elements' type. For example, vector of primitive types (e.g. Int) will be backed by primitive array while vector of product types by structure of arrays. They are quite efficient due to the unboxed representation they use.

Storable vectors (Data.Vector.Storable) are backed by pinned memory, i.e., they cannot be moved by the garbage collector. Their primary use case is C FFI.

Primitive vectors (Data.Vector.Primitive) are backed by simple byte array and can store only data types that are represented in memory as a sequence of bytes without a pointer, i.e., they belong to the Prim type class, e.g., Int, Double, etc. It's advised to use unboxed vectors if you're looking for the performance of primitive vectors, but more versality.

Stream Fusion

An optimisation framework used by vectors, stream fusion is a technique that merges several functions into one and prevents creation of intermediate data structures. For example, the expression sum . filter g . map f won't allocate temporary vectors if compiled with optimisations.