Skip to content

Commit 0ef3447

Browse files
committed
Adopt examples in README to current Julia version
I have noticed, that some of the code examples in the `Quick start` section of the README don't work because they were designed for an older version of Julia. This PR modifies these examples to make them work with Julia v1.1.1.
1 parent 3b1c73f commit 0ef3447

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
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+
eigvecs(m3) # eigvecs(), 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(eigvecs(m3) == SArray{Tuple{3,3},Float64,2,9})
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

0 commit comments

Comments
 (0)