3
3
``` julia
4
4
Pkg. add (" StaticArrays" ) # or Pkg.clone("https://github.com/JuliaArrays/StaticArrays.jl")
5
5
using StaticArrays
6
+ using LinearAlgebra
6
7
7
8
# Create an SVector using various forms, using constructors, functions or macros
8
9
v1 = SVector (1 , 2 , 3 )
@@ -22,7 +23,7 @@ size(typeof(v1)) == (3,)
22
23
m1 = SMatrix {2,2} (1 , 2 , 3 , 4 ) # flat, column-major storage, equal to m2:
23
24
m2 = @SMatrix [ 1 3 ;
24
25
2 4 ]
25
- m3 = eye ( SMatrix{3 ,3 })
26
+ m3 = SMatrix {3,3} ( 1 I )
26
27
m4 = @SMatrix randn (4 ,4 )
27
28
m5 = SMatrix {2,2} ([1 3 ; 2 4 ]) # Array conversions must specify size
28
29
@@ -43,14 +44,14 @@ typeof(v1[[1,2,3]]) <: Vector # Can't determine size from the type of [1,2,3]
43
44
44
45
# Is (partially) hooked into BLAS, LAPACK, etc:
45
46
rand (MMatrix{20 ,20 }) * rand (MMatrix{20 ,20 }) # large matrices can use BLAS
46
- eig (m3) # eig (), etc uses specialized algorithms up to 3×3, or else LAPACK
47
+ eigvecs (m3) # eigvecs (), etc uses specialized algorithms up to 3×3, or else LAPACK
47
48
48
49
# Static arrays stay statically sized, even when used by Base functions, etc:
49
- typeof (eig (m3)) == Tuple{SVector{ 3 ,Float64}, SMatrix{ 3 , 3 , Float64,9 }}
50
+ typeof (eigvecs (m3) == SArray{ Tuple{3 , 3 }, Float64,2 , 9 })
50
51
51
52
# similar() returns a mutable container, while similar_type() returns a constructor:
52
- typeof (similar (m3)) == MMatrix{ 3 ,3 ,Float64 ,9 } # (final parameter is length = 9)
53
- similar_type (m3) == SMatrix{ 3 ,3 ,Float64 ,9 }
53
+ typeof (similar (m3)) == MArray{Tuple{ 3 ,3 },Int64, 2 ,9 } # (final parameter is length = 9)
54
+ similar_type (m3) == SArray{Tuple{ 3 ,3 },Int64, 2 ,9 }
54
55
55
56
# The Size trait is a compile-time constant representing the size
56
57
Size (m3) === Size (3 ,3 )
@@ -62,6 +63,6 @@ inv(m4) # Take advantage of specialized fast methods
62
63
# reshape() uses Size() or types to specify size:
63
64
reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 )) == @SMatrix [ 1 3 ;
64
65
2 4 ]
65
- typeof (reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 ))) === SizedArray{( 2 , 2 ) ,Int64,2 ,1 }
66
+ typeof (reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 ))) === SizedArray{Tuple{ 2 , 2 } ,Int64,2 ,1 }
66
67
67
68
```
0 commit comments