Skip to content

Instantly share code, notes, and snippets.

@nwh
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwh/0e4f9b32afd7f15dbff8 to your computer and use it in GitHub Desktop.
Save nwh/0e4f9b32afd7f15dbff8 to your computer and use it in GitHub Desktop.
2014-09-18: Issues with julia blas.jl

Abusing scal!

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?

Using scal! with a SubArray

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

Version of Julia

$ ./julia -v
julia version 0.4.0-dev+654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment