@@ -58,29 +58,31 @@ implemented in `BLAS.gemv!` using a lazy applied object:
5858julia> A = randn (5 ,5 ); b = randn (5 ); c = randn (5 ); d = similar (c);
5959
6060julia> d .= @~ 2.0 * A * b + 3.0 * c # Calls gemv!
61- 5 - element Array {Float64, 1 }:
61+ 5 - element Vector {Float64}:
6262 - 2.5366335879717514
6363 - 5.305097174484744
6464 - 9.818431932350942
6565 2.421562605495651
6666 0.26792916096572983
6767
6868julia> 2 * (A* b) + 3 c
69- 5 - element Array {Float64, 1 }:
69+ 5 - element Vector {Float64}:
7070 - 2.5366335879717514
7171 - 5.305097174484744
7272 - 9.818431932350942
7373 2.421562605495651
7474 0.26792916096572983
7575
7676julia> function mymul (A, b, c, d) # need to put in function for benchmarking
77- d .= @~ 2.0 * A * b + 3.0 * c
77+ d .= @~ 2.0 * A * b + 3.0 * c
7878 end
7979mymul (generic function with 1 method)
8080
81+ julia> using BenchmarkTools
82+
8183julia> @btime mymul (A, b, c, d) # calls gemv!
8284 77.444 ns (0 allocations: 0 bytes)
83- 5 - element Array {Float64, 1 }:
85+ 5 - element Vector {Float64}:
8486 - 2.5366335879717514
8587 - 5.305097174484744
8688 - 9.818431932350942
@@ -96,7 +98,7 @@ This also works for inverses, which lower to BLAS calls whenever possible:
9698julia> A = randn (5 ,5 ); b = randn (5 ); c = similar (b);
9799
98100julia> c .= @~ A \ b
99- 5 - element Array {Float64, 1 }:
101+ 5 - element Vector {Float64}:
100102 - 2.5366335879717514
101103 - 5.305097174484744
102104 - 9.818431932350942
@@ -105,22 +107,21 @@ julia> c .= @~ A \ b
105107```
106108
107109
108-
109110## Lazy arrays
110111
111112Often we want lazy realizations of matrices, which are supported via ` ApplyArray ` .
112113For example, the following creates a lazy matrix exponential:
113114``` julia
114115julia> E = ApplyArray (exp, [1 2 ; 3 4 ])
115- 2 × 2 ApplyArray{Float64, 2 , typeof (exp),Tuple{Array{ Int64, 2 }}} :
116+ exp ( 2 × 2 Matrix{ Int64}) :
116117 51.969 74.7366
117118 112.105 164.074
118119```
119120
120121A lazy matrix exponential is useful for, say, in-place matrix-exponential* vector:
121122``` julia
122123julia> b = Vector {Float64} (undef, 2 ); b .= @~ E* [4 ,4 ]
123- 2 - element Array {Float64, 1 }:
124+ 2 - element Vector {Float64}:
124125 506.8220830628333
125126 1104.7145995988594
126127```
@@ -138,7 +139,7 @@ vectors without actually allocating memory, and support a fast
138139julia> using BenchmarkTools
139140
140141julia> A = ApplyArray (vcat,1 : 5 ,2 : 3 ) # allocation-free
141- 7 - element ApplyArray{Int64, 1 , typeof (vcat),Tuple{ UnitRange{Int64},UnitRange{Int64}}} :
142+ vcat ( 5 - element UnitRange{Int64}, 2 - element UnitRange{Int64}) :
142143 1
143144 2
144145 3
@@ -159,7 +160,7 @@ julia> @btime vcat(1:5, 2:3); # takes twice as long due to memory creation
159160Similar is the lazy analogue of ` hcat ` :
160161``` julia
161162julia> A = ApplyArray (hcat, 1 : 3 , randn (3 ,10 ))
162- 3 × 11 ApplyArray{Float64, 2 , typeof (hcat),Tuple{ UnitRange{Int64},Array {Float64, 2 }}} :
163+ hcat ( 3 - element UnitRange{Int64}, 3 × 10 Matrix {Float64}) :
163164 1.0 1.16561 0.224871 - 1.36416 - 0.30675 0.103714 0.590141 0.982382 - 1.50045 0.323747 - 1.28173
164165 2.0 1.04648 1.35506 - 0.147157 0.995657 - 0.616321 - 0.128672 - 0.671445 - 0.563587 - 0.268389 - 1.71004
165166 3.0 - 0.433093 - 0.325207 - 1.38496 - 0.391113 - 0.0568739 - 1.55796 - 1.00747 0.473686 - 1.2113 0.0119156
@@ -185,7 +186,7 @@ array:
185186julia> A = randn (2 ,2 ); B = randn (3 ,3 );
186187
187188julia> K = ApplyArray (kron,A,B)
188- 6 × 6 ApplyArray {Float64, 2 , typeof (kron),Tuple{Array{Float64, 2 },Array {Float64, 2 }}} :
189+ kron ( 2 × 2 Matrix {Float64}, 3 × 3 Matrix {Float64}) :
189190 - 1.08736 - 0.19547 - 0.132824 1.60531 0.288579 0.196093
190191 0.353898 0.445557 - 0.257776 - 0.522472 - 0.657791 0.380564
191192 - 0.723707 0.911737 - 0.710378 1.06843 - 1.34603 1.04876
0 commit comments