8
8
[ ![ Coverage Status] ( https://coveralls.io/repos/github/JuliaArrays/StaticArrays.jl/badge.svg?branch=master )] ( https://coveralls.io/github/JuliaArrays/StaticArrays.jl?branch=master )
9
9
10
10
** 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} ` .
12
12
Subtypes of ` StaticArray ` will provide fast implementations of common array and
13
13
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 ` .
17
16
18
17
The package also provides some concrete static array types: ` SVector ` , ` SMatrix `
19
18
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}
172
171
Size (3 ,3 )(rand (3 ,3 )) # Construct a random 3×3 SizedArray (see below)
173
172
```
174
173
175
- Users that introduce a new subtype of ` StaticArray ` should define a (` @pure ` )
176
- method for ` Size(::Type{NewArrayType}) ` .
177
-
178
174
### Indexing
179
175
180
176
Statically sized indexing can be realized by indexing each dimension by a
@@ -212,13 +208,8 @@ specifying the size as plain integers).
212
208
213
209
### ` SVector `
214
210
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 ` .
222
213
223
214
` SVector ` defines a series of convenience constructors, so you can just type
224
215
e.g. ` SVector(1,2,3) ` . Alternatively there is an intelligent ` @SVector ` macro
@@ -234,36 +225,27 @@ limitation.)
234
225
235
226
### ` SMatrix `
236
227
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} ` .
245
229
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
248
232
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
250
234
convenience macro ` @SMatrix [1 2; 3 4] ` is provided (which also accepts
251
235
comprehensions and the ` zeros() ` , ` ones() ` , ` fill() ` , ` rand() ` , ` randn() ` and ` eye() `
252
236
functions).
253
237
254
238
### ` SArray `
255
239
256
240
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
259
243
the ` @SArray ` macro, supporting all the features of ` @SVector ` and ` @SMatrix `
260
244
(but with arbitrary dimension).
261
245
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}} ` ).
267
249
268
250
### ` Scalar `
269
251
@@ -307,7 +289,7 @@ Convenience macros `@MVector`, `@MMatrix` and `@MArray` are provided.
307
289
308
290
Another convenient mutable type is the ` SizedArray ` , which is just a wrapper-type
309
291
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) `
311
293
to construct a new object which knows the type (the size will be verified
312
294
automatically). A more convenient syntax for obtaining a ` SizedArray ` is by calling
313
295
a ` Size ` object, e.g. ` sa = Size(2,2)(a) ` .
0 commit comments