Skip to content

Commit b81044a

Browse files
authored
Merge pull request #611 from goggle/readme-eye
Adopt examples in README to current Julia version
2 parents 725708a + 44e3ae5 commit b81044a

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ julia 0.5 with default optimizations.
6262
```julia
6363
Pkg.add("StaticArrays") # or Pkg.clone("https://github.com/JuliaArrays/StaticArrays.jl")
6464
using StaticArrays
65+
using LinearAlgebra
6566

6667
# Create an SVector using various forms, using constructors, functions or macros
6768
v1 = SVector(1, 2, 3)
@@ -81,7 +82,7 @@ size(typeof(v1)) == (3,)
8182
m1 = SMatrix{2,2}(1, 2, 3, 4) # flat, column-major storage, equal to m2:
8283
m2 = @SMatrix [ 1 3 ;
8384
2 4 ]
84-
m3 = eye(SMatrix{3,3})
85+
m3 = SMatrix{3,3}(1I)
8586
m4 = @SMatrix randn(4,4)
8687
m5 = SMatrix{2,2}([1 3 ; 2 4]) # Array conversions must specify size
8788

@@ -91,7 +92,7 @@ a = @SArray randn(2, 2, 2, 2, 2, 2)
9192
# Supports all the common operations of AbstractArray
9293
v7 = v1 + v2
9394
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)
9596
# map, reduce, broadcast, map!, broadcast!, etc...
9697

9798
# 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]
102103

103104
# Is (partially) hooked into BLAS, LAPACK, etc:
104105
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
106107

107108
# 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}}
109110

110111
# 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}
113114

114115
# The Size trait is a compile-time constant representing the size
115116
Size(m3) === Size(3,3)
@@ -121,7 +122,7 @@ inv(m4) # Take advantage of specialized fast methods
121122
# reshape() uses Size() or types to specify size:
122123
reshape([1,2,3,4], Size(2,2)) == @SMatrix [ 1 3 ;
123124
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}
125126

126127
```
127128

docs/src/pages/quickstart.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
```julia
44
Pkg.add("StaticArrays") # or Pkg.clone("https://github.com/JuliaArrays/StaticArrays.jl")
55
using StaticArrays
6+
using LinearAlgebra
67

78
# Create an SVector using various forms, using constructors, functions or macros
89
v1 = SVector(1, 2, 3)
@@ -22,7 +23,7 @@ size(typeof(v1)) == (3,)
2223
m1 = SMatrix{2,2}(1, 2, 3, 4) # flat, column-major storage, equal to m2:
2324
m2 = @SMatrix [ 1 3 ;
2425
2 4 ]
25-
m3 = eye(SMatrix{3,3})
26+
m3 = SMatrix{3,3}(1I)
2627
m4 = @SMatrix randn(4,4)
2728
m5 = SMatrix{2,2}([1 3 ; 2 4]) # Array conversions must specify size
2829

@@ -43,14 +44,14 @@ typeof(v1[[1,2,3]]) <: Vector # Can't determine size from the type of [1,2,3]
4344

4445
# Is (partially) hooked into BLAS, LAPACK, etc:
4546
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+
eigen(m3) # eigen(), etc uses specialized algorithms up to 3×3, or else LAPACK
4748

4849
# 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(eigen(m3)) == Eigen{Float64,Float64,SArray{Tuple{3,3},Float64,2,9},SArray{Tuple{3},Float64,1,3}}
5051

5152
# 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}
5455

5556
# The Size trait is a compile-time constant representing the size
5657
Size(m3) === Size(3,3)
@@ -62,6 +63,6 @@ inv(m4) # Take advantage of specialized fast methods
6263
# reshape() uses Size() or types to specify size:
6364
reshape([1,2,3,4], Size(2,2)) == @SMatrix [ 1 3 ;
6465
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}
6667

6768
```

0 commit comments

Comments
 (0)