Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundsError in transpose(::Vector{Dec128}) #38

Closed
rdeits opened this issue Mar 29, 2017 · 9 comments
Closed

BoundsError in transpose(::Vector{Dec128}) #38

rdeits opened this issue Mar 29, 2017 · 9 comments

Comments

@rdeits
Copy link

rdeits commented Mar 29, 2017

Attempting to transpose a vector of Dec128 fails with a BoundsError on Julia v0.5 and v0.6, running in Ubuntu 14.04 and macOS. I can reproduce this both on the last tagged release of DecFP and on master.

julia> transpose(zeros(Dec128, 5))
ERROR: BoundsError: attempt to access 5-element Array{DecFP.Dec128,1} at index [6]
 in prod_next at ./iterator.jl:527 [inlined]
 in next at ./iterator.jl:538 [inlined]
 in next at ./generator.jl:25 [inlined]
 in collect_to!(::Array{DecFP.Dec128,2}, ::Base.Generator{Base.Prod2{Base.OneTo{Int64},Array{DecFP.Dec128,1}},Base.##207#208}, ::Int64, ::Tuple{Int64,Int64,Nullable{DecFP.Dec128},Bool}) at ./array.jl:340
 in collect(::Base.Generator{Base.Prod2{Base.OneTo{Int64},Array{DecFP.Dec128,1}},Base.##207#208}) at ./array.jl:308
 in transpose(::Array{DecFP.Dec128,1}) at ./arraymath.jl:459

This occurs regardless of the length of the vector:

julia> transpose(zeros(Dec128, 1))
ERROR: BoundsError: attempt to access 1-element Array{DecFP.Dec128,1} at index [2]
 in prod_next at ./iterator.jl:527 [inlined]
 in next at ./iterator.jl:538 [inlined]
 in next at ./generator.jl:25 [inlined]
 in collect_to!(::Array{DecFP.Dec128,2}, ::Base.Generator{Base.Prod2{Base.OneTo{Int64},Array{DecFP.Dec128,1}},Base.##207#208}, ::Int64, ::Tuple{Int64,Int64,Nullable{DecFP.Dec128},Bool}) at ./array.jl:340
 in collect(::Base.Generator{Base.Prod2{Base.OneTo{Int64},Array{DecFP.Dec128,1}},Base.##207#208}) at ./array.jl:308
 in transpose(::Array{DecFP.Dec128,1}) at ./arraymath.jl:459

reshape() works fine, and transpose() works fine for vectors of Dec64 and Dec32. Transpose also works for 2-dimensional arrays of Dec128.

size() and length() give the right answers:

julia> length(zeros(Dec128, 5))
5

julia> size(zeros(Dec128, 5))
(5,)

Any ideas?

@rdeits
Copy link
Author

rdeits commented Mar 29, 2017

A reduced case that still exhibits the problem is:

julia> collect(v for i in 1:1, v in x)
ERROR: BoundsError: attempt to access 5-element Array{DecFP.Dec128,1} at index [6]
 in prod_next at ./iterator.jl:527 [inlined]
 in next at ./iterator.jl:538 [inlined]
 in next at ./generator.jl:25 [inlined]
 in collect_to!(::Array{DecFP.Dec128,2}, ::Base.Generator{Base.Prod2{UnitRange{Int64},Array{DecFP.Dec128,1}},##11#12}, ::Int64, ::Tuple{Int64,Int64,Nullable{DecFP.Dec128},Bool}) at ./array.jl:340
 in collect(::Base.Generator{Base.Prod2{UnitRange{Int64},Array{DecFP.Dec128,1}},##11#12}) at ./array.jl:308

Swapping the ranges causes a segfault:

julia> collect(v for v in x, i in 1:1)

signal (11): Segmentation fault
while loading no file, in expression starting on line 0
next at ./generator.jl:25 [inlined]
collect_to! at ./array.jl:340
collect at ./array.jl:308
unknown function (ip: 0x7fe136c070e2)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:66
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:190
eval_body at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:465
jl_interpret_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:573
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:572 [inlined]
jl_toplevel_eval at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:580
jl_toplevel_eval_in_warn at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:590
eval at ./boot.jl:234
unknown function (ip: 0x7fe35b0efc9f)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
eval_user_input at ./REPL.jl:64
unknown function (ip: 0x7fe136bcad46)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
macro expansion at ./REPL.jl:95 [inlined]
#3 at ./event.jl:68
unknown function (ip: 0x7fe136bc7ecf)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1392 [inlined]
start_task at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:254
unknown function (ip: 0xffffffffffffffff)
Allocations: 4365820 (Pool: 4364674; Big: 1146); GC: 5

Perhaps this is related to JuliaLang/julia#21216 ?

Edit: I can also reproduce it on macOS, so perhaps it's not related to 21216.

@stevengj
Copy link
Member

With Julia 0.6, I get:

julia> transpose(zeros(Dec128, 5))
1×5 RowVector{DecFP.Dec128,Array{DecFP.Dec128,1}}:
 +0E+0  +0E+0  +0E+0  +0E+0  +0E+0

@rdeits
Copy link
Author

rdeits commented Mar 29, 2017

Perhaps my v0.6 is too old. I'll update again.

@stevengj
Copy link
Member

With the latest 0.6 I get:

julia> collect(v for i in 1:1, v in zeros(Dec64, 1))
1×1 Array{DecFP.Dec64,2}:
 +0E+0

julia> collect(v for i in 1:1, v in zeros(Dec128, 1))
1×1 Array{DecFP.Dec128,2}:
 +4639814192E-6176

which is clearly wrong (it seems to be accessing invalid memory). But I'm guessing it is related to JuliaLang/julia#21216?

@rdeits
Copy link
Author

rdeits commented Mar 29, 2017

Yeah, I can confirm that transpose is working on the latest v0.6, but I'm still getting some segfaults:

julia> x = zeros(Dec128, 5)
5-element Array{DecFP.Dec128,1}:
 +0E+0
 +0E+0
 +0E+0
 +0E+0
 +0E+0

julia> transpose(x)
1×5 RowVector{DecFP.Dec128,Array{DecFP.Dec128,1}}:
 +0E+0  +0E+0  +0E+0  +0E+0  +0E+0

julia> collect(v for i in 1:1, v in x)
[1]    31025 segmentation fault  julia-0.6

This is on macOS, so maybe JuliaLang/julia#21216 is not actually restricted to linux?

@stevengj
Copy link
Member

Yup seems like a Julia bug.

abstract type DecimalFloatingPoint <: AbstractFloat end
primitive type Dec128 <: DecimalFloatingPoint 128 end
collect(v for i in 1:1, v in [reinterpret(Dec128, UInt128(0))])

gives

1×1 Array{Dec128,2}:
 Dec128(0x000000011428beb0ffffffffffffffff)

in Julia 0.6, and

abstract DecimalFloatingPoint <: AbstractFloat
bitstype 128 Dec128 <: DecimalFloatingPoint
collect(v for i in 1:1, v in [reinterpret(Dec128, UInt128(0))])

gives

ERROR: BoundsError: attempt to access 1-element Array{Dec128,1} at index [2]
 in prod_next at ./iterator.jl:527 [inlined]
 in next at ./iterator.jl:538 [inlined]
 in next at ./generator.jl:25 [inlined]
 in collect_to!(::Array{Dec128,2}, ::Base.Generator{Base.Prod2{UnitRange{Int64},Array{Dec128,1}},##1#2}, ::Int64, ::Tuple{Int64,Int64,Nullable{Dec128},Bool}) at ./array.jl:340
 in collect(::Base.Generator{Base.Prod2{UnitRange{Int64},Array{Dec128,1}},##1#2}) at ./array.jl:308

in Julia 0.5.

@stevengj
Copy link
Member

Closing this issue as a duplicate of #37.

@rdeits
Copy link
Author

rdeits commented Mar 29, 2017

Ok, thanks @stevengj !

@rdeits
Copy link
Author

rdeits commented Mar 29, 2017

By the way, in case you're interested, the reason this came up is that I've ported the original Lawson & Hanson non-negative least squares code from Fortran to Julia, so now I'm having some fun trying out NNLS problems with different levels of floating-point precision: https://github.com/rdeits/nnls.jl

stevengj added a commit that referenced this issue Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants