You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alternatively you can install MKL directly [from intel](https://software.intel.com/en-us/mkl/choose-download).
16
16
17
17
Note that intel MKL has a separate license, which you may want to check for commercial projects (see [FAQ](https://software.intel.com/en-us/mkl/license-faq)).
After loading `VML`, you have the supported function listed below available to call, i.e. `VML.sin(rand(100))`. This should provide a significant speed-up over broadcasting the Base functions.
26
-
```
27
-
julia> using VML
28
-
julia> a = rand(10000);
29
-
julia>@time sin.(a);
30
-
0.159878 seconds (583.25 k allocations: 30.720 MiB, 2.78% gc time)
31
-
julia> @time VML.sin(a);
32
-
0.000465 seconds (6 allocations: 781.484 KiB)
33
-
```
26
+
```julia
27
+
julia>using VML, BenchmarkTools
28
+
29
+
julia> a =randn(10^4);
30
+
31
+
julia>@btimesin.($a); # apply Base.sin to each element
32
+
102.128 μs (2 allocations:78.20 KiB)
33
+
34
+
julia>@btime VML.sin($a); # apply VML.sin to the whole array
35
+
20.900 μs (2 allocations:78.20 KiB)
34
36
35
-
Most function do currently (julia 1.x) not have a vectorized form, meaning that i.e. `sin(rand(10))` will not work. If you would like to extend the Base function with this functionality you can overload them with the `@overload` macro:
37
+
julia> b =similar(a);
38
+
39
+
julia>@btime VML.sin!(b, a); # in-place version
40
+
20.008 μs (0 allocations:0 bytes)
36
41
```
37
-
julia> @overload sin
38
-
julia> @time sin(a);
39
-
0.000485 seconds (6 allocations: 781.484 KiB)
42
+
43
+
Most Julia functions do not automatically apply to all elements of an array, thus `sin(a)` gives a MethodError. If you would like to extend the Base function with this functionality, you can add methods to them with the `@overload` macro:
44
+
```julia
45
+
julia>@overload sin cos tan;
46
+
47
+
julia>@btimesin($a);
48
+
20.944 μs (2 allocations:78.20 KiB)
49
+
50
+
julia> ans ≈sin.(a)
51
+
true
40
52
```
41
-
Note the lack of the broadcasting dot`.` Now calling i.e. `sin` with an array as input will call the VML functions.
53
+
Calling `sin` on an array now calls the a VML function, while its action on scalars is unchanged.
42
54
43
55
#### Note:
44
-
Some functions like `exp` and `log` do operate on matrices from Base and refer to the [matrix exponential](https://en.wikipedia.org/wiki/Matrix_exponential) and logarithm. Using `@overload exp` will overwrite this behaviour with element-wise exponentiation/ logarithm.
45
-
```
46
-
julia> exp([1 1; 1 1.0])
56
+
57
+
Some Julia functions like `exp` and `log` do operate on matrices, and refer to the [matrix exponential](https://en.wikipedia.org/wiki/Matrix_exponential) and logarithm. Using `@overload exp` will overwrite this behaviour with element-wise exponentiation/ logarithm.
58
+
```julia
59
+
julia>exp(ones(2,2))
47
60
2×2 Array{Float64,2}:
48
61
4.194533.19453
49
62
3.194534.19453
50
63
51
-
julia> VML.exp([1 1; 1 1.0])
64
+
julia> VML.exp(ones(2,2))
52
65
2×2 Array{Float64,2}:
53
66
2.718282.71828
54
67
2.718282.71828
68
+
69
+
julia> ans ==exp.(ones(2,2))
70
+
true
55
71
```
72
+
If your code, or any code you call, uses matrix exponentiation, then `@overload exp` may silently lead to incorrect results. This caution applies to all trigonometric functions, too, since they have matrix forms defined by matrix exponential.
0 commit comments