It's easy to abuse the BLAS interface functions with "nice" Julia objects. The following will usually cause a segfault:
using Base.LinAlg.BLAS
x = ones(10)
scal!(10000,10.0,x,1)
Is there an opinion or thinking on how "safe" these interface functions should be? Of course all bets are off if a Ptr
is passed. What should we expect if we pass an Array
?
The behavior on a SubArray
seems a bit strange:
using Base.LinAlg.BLAS
A = ones(10,10)
B = sub(A,6:10,6:10)
scal!(length(B),10.0,B,1)
Result:
julia> A
10x10 Array{Float64,2}:
1.0 1.0 1.0 1.0 1.0 1.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 10.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 10.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 10.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 10.0 10.0 10.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 10.0 10.0 10.0 1.0 1.0
julia> B
5x5 SubArray{Float64,2,Array{Float64,2},(UnitRange{Int64},UnitRange{Int64})}:
10.0 10.0 10.0 1.0 1.0
10.0 10.0 10.0 1.0 1.0
10.0 10.0 10.0 1.0 1.0
10.0 10.0 10.0 1.0 1.0
10.0 10.0 10.0 1.0 1.0
$ ./julia -v
julia version 0.4.0-dev+654