Skip to content

Commit 71ae355

Browse files
committed
Various doc updates as fallout from merging #127, #134.
1 parent c4008ff commit 71ae355

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

README.md

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
[![Coverage Status](https://coveralls.io/repos/github/JuliaArrays/StaticArrays.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaArrays/StaticArrays.jl?branch=master)
99

1010
**StaticArrays** provides a framework for implementing statically sized arrays
11-
in Julia (≥ 0.5), using the abstract type `StaticArray{T,N} <: AbstractArray{T,N}`.
11+
in Julia (≥ 0.5), using the abstract type `StaticArray{Size,T,N} <: AbstractArray{T,N}`.
1212
Subtypes of `StaticArray` will provide fast implementations of common array and
1313
linear algebra operations. Note that here "statically sized" means that the
14-
size can be determined from the *type* (so concrete implementations of
15-
`StaticArray` must define a method `size(::Type{T})`), and "static" does **not**
16-
necessarily imply `immutable`.
14+
size can be determined from the *type*, and "static" does **not** necessarily
15+
imply `immutable`.
1716

1817
The package also provides some concrete static array types: `SVector`, `SMatrix`
1918
and `SArray`, which may be used as-is (or else embedded in your own type).
@@ -172,9 +171,6 @@ reshape(svector, Size(2,2)) # Convert SVector{4} to SMatrix{2,2}
172171
Size(3,3)(rand(3,3)) # Construct a random 3×3 SizedArray (see below)
173172
```
174173

175-
Users that introduce a new subtype of `StaticArray` should define a (`@pure`)
176-
method for `Size(::Type{NewArrayType})`.
177-
178174
### Indexing
179175

180176
Statically sized indexing can be realized by indexing each dimension by a
@@ -212,13 +208,8 @@ specifying the size as plain integers).
212208

213209
### `SVector`
214210

215-
The simplest static array is the `SVector`, defined as
216-
217-
```julia
218-
immutable SVector{N,T} <: StaticVector{T}
219-
data::NTuple{N,T}
220-
end
221-
```
211+
The simplest static array is the type `SVector{N,T}`, which provides an
212+
immutable vector of fixed length `N` and type `T`.
222213

223214
`SVector` defines a series of convenience constructors, so you can just type
224215
e.g. `SVector(1,2,3)`. Alternatively there is an intelligent `@SVector` macro
@@ -234,36 +225,27 @@ limitation.)
234225

235226
### `SMatrix`
236227

237-
Static matrices are also provided by `SMatrix`. It's definition is a little
238-
more complicated:
239-
240-
```julia
241-
immutable SMatrix{S1, S2, T, L} <: StaticMatrix{T}
242-
data::NTuple{L, T}
243-
end
244-
```
228+
Statically sized `N×M` matrices are provided by `SMatrix{N,M,T,L}`.
245229

246-
Here `L` is the `length` of the matrix, such that `S1 × S2 = L`. However,
247-
convenience constructors are provided, so that `L`, `T` and even `S2` are
230+
Here `L` is the `length` of the matrix, such that `N × M = L`. However,
231+
convenience constructors are provided, so that `L`, `T` and even `M` are
248232
unnecessary. At minimum, you can type `SMatrix{2}(1,2,3,4)` to create a 2×2
249-
matrix (the total number of elements must divide evenly into `S1`). A
233+
matrix (the total number of elements must divide evenly into `N`). A
250234
convenience macro `@SMatrix [1 2; 3 4]` is provided (which also accepts
251235
comprehensions and the `zeros()`, `ones()`, `fill()`, `rand()`, `randn()` and `eye()`
252236
functions).
253237

254238
### `SArray`
255239

256240
A container with arbitrarily many dimensions is defined as
257-
`immutable SArray{Size,T,N,L} <: StaticArray{T,N}`, where
258-
`Size = (S1, S2, ...)` is a tuple of `Int`s. You can easily construct one with
241+
`immutable SArray{Size,T,N,L} <: StaticArray{Size,T,N}`, where
242+
`Size = Tuple{S1, S2, ...}` is a tuple of `Int`s. You can easily construct one with
259243
the `@SArray` macro, supporting all the features of `@SVector` and `@SMatrix`
260244
(but with arbitrary dimension).
261245

262-
Notably, the main reason `SVector` and `SMatrix` are defined is to make it
263-
easier to define the types without the extra tuple characters (compare
264-
`SVector{3}` to `SArray{(3,)}`). This extra convenience was made possible
265-
because it is so easy to define new `StaticArray` subtypes, and they naturally
266-
work together.
246+
The main reason `SVector` and `SMatrix` are defined is to make it easier to
247+
define the types without the extra tuple characters (compare `SVector{3}` to
248+
`SArray{Tuple{3}}`).
267249

268250
### `Scalar`
269251

@@ -307,7 +289,7 @@ Convenience macros `@MVector`, `@MMatrix` and `@MArray` are provided.
307289

308290
Another convenient mutable type is the `SizedArray`, which is just a wrapper-type
309291
about a standard Julia `Array` which declares its knwon size. For example, if
310-
we knew that `a` was a 2×2 `Matrix`, then we can type `sa = SizedArray{(2,2)}(a)`
292+
we knew that `a` was a 2×2 `Matrix`, then we can type `sa = SizedArray{Tuple{2,2}}(a)`
311293
to construct a new object which knows the type (the size will be verified
312294
automatically). A more convenient syntax for obtaining a `SizedArray` is by calling
313295
a `Size` object, e.g. `sa = Size(2,2)(a)`.

src/StaticArrays.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ export similar_type
2828
export push, pop, shift, unshift, insert, deleteat, setindex
2929

3030
"""
31-
abstract type StaticArray{T, N} <: AbstractArray{T, N} end
32-
StaticScalar{T} = StaticArray{T, 0}
33-
StaticVector{T} = StaticArray{T, 1}
34-
StaticMatrix{T} = StaticArray{T, 2}
31+
abstract type StaticArray{S, T, N} <: AbstractArray{T, N} end
32+
StaticScalar{T} = StaticArray{Tuple{}, T, 0}
33+
StaticVector{N,T} = StaticArray{Tuple{N}, T, 1}
34+
StaticMatrix{N,M,T} = StaticArray{Tuple{N,M}, T, 2}
3535
3636
`StaticArray`s are Julia arrays with fixed, known size.
3737
3838
## Dev docs
3939
4040
They must define the following methods:
4141
- Constructors that accept a flat tuple of data.
42-
- `Size()` on the *type*, returning an *instance* of `Size{(dim1, dim2, ...)}` (preferably `@pure`).
4342
- `getindex()` with an integer (linear indexing) (preferably `@inline` with `@boundscheck`).
4443
- `Tuple()`, returning the data in a flat Tuple.
4544

0 commit comments

Comments
 (0)