@@ -62,6 +62,7 @@ julia 0.5 with default optimizations.
62
62
``` julia
63
63
Pkg. add (" StaticArrays" ) # or Pkg.clone("https://github.com/JuliaArrays/StaticArrays.jl")
64
64
using StaticArrays
65
+ using LinearAlgebra
65
66
66
67
# Create an SVector using various forms, using constructors, functions or macros
67
68
v1 = SVector (1 , 2 , 3 )
@@ -81,7 +82,7 @@ size(typeof(v1)) == (3,)
81
82
m1 = SMatrix {2,2} (1 , 2 , 3 , 4 ) # flat, column-major storage, equal to m2:
82
83
m2 = @SMatrix [ 1 3 ;
83
84
2 4 ]
84
- m3 = eye ( SMatrix{3 ,3 })
85
+ m3 = SMatrix {3,3} ( 1 I )
85
86
m4 = @SMatrix randn (4 ,4 )
86
87
m5 = SMatrix {2,2} ([1 3 ; 2 4 ]) # Array conversions must specify size
87
88
@@ -91,7 +92,7 @@ a = @SArray randn(2, 2, 2, 2, 2, 2)
91
92
# Supports all the common operations of AbstractArray
92
93
v7 = v1 + v2
93
94
v8 = sin .(v3)
94
- v3 == m3 * v3 # recall that m3 = eye( SMatrix{3,3})
95
+ v3 == m3 * v3 # recall that m3 = SMatrix{3,3}(1I )
95
96
# map, reduce, broadcast, map!, broadcast!, etc...
96
97
97
98
# Indexing can also be done using static arrays of integers
@@ -102,14 +103,14 @@ typeof(v1[[1,2,3]]) <: Vector # Can't determine size from the type of [1,2,3]
102
103
103
104
# Is (partially) hooked into BLAS, LAPACK, etc:
104
105
rand (MMatrix{20 ,20 }) * rand (MMatrix{20 ,20 }) # large matrices can use BLAS
105
- eig (m3) # eig (), etc uses specialized algorithms up to 3×3, or else LAPACK
106
+ eigen (m3) # eigen (), etc uses specialized algorithms up to 3×3, or else LAPACK
106
107
107
108
# Static arrays stay statically sized, even when used by Base functions, etc:
108
- typeof (eig (m3)) == Tuple{SVector{ 3 ,Float64}, SMatrix{ 3 ,3 ,Float64,9 }}
109
+ typeof (eigen (m3)) == Eigen{Float64 ,Float64,SArray{Tuple{ 3 ,3 } ,Float64,2 , 9 },SArray{Tuple{ 3 },Float64, 1 , 3 }}
109
110
110
111
# similar() returns a mutable container, while similar_type() returns a constructor:
111
- typeof (similar (m3)) == MMatrix{ 3 ,3 ,Float64 ,9 } # (final parameter is length = 9)
112
- similar_type (m3) == SMatrix{ 3 ,3 ,Float64 ,9 }
112
+ typeof (similar (m3)) == MArray{Tuple{ 3 ,3 },Int64, 2 ,9 } # (final parameter is length = 9)
113
+ similar_type (m3) == SArray{Tuple{ 3 ,3 },Int64, 2 ,9 }
113
114
114
115
# The Size trait is a compile-time constant representing the size
115
116
Size (m3) === Size (3 ,3 )
@@ -121,7 +122,7 @@ inv(m4) # Take advantage of specialized fast methods
121
122
# reshape() uses Size() or types to specify size:
122
123
reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 )) == @SMatrix [ 1 3 ;
123
124
2 4 ]
124
- typeof (reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 ))) === SizedArray{( 2 , 2 ) ,Int64,2 ,1 }
125
+ typeof (reshape ([1 ,2 ,3 ,4 ], Size (2 ,2 ))) === SizedArray{Tuple{ 2 , 2 } ,Int64,2 ,1 }
125
126
126
127
```
127
128
0 commit comments