Int array from two ranges

100 views
Skip to first unread message

Gabor

unread,
Jan 9, 2013, 1:52:37 PM1/9/13
to juli...@googlegroups.com
I have a problem with creating an Int array from two ranges:

> n=8; m=ceil(n/2); [0:m-1, m-n:-1]
8-element Float64 Array:
0.0
1.0
2.0
3.0
-4.0
-3.0
-2.0
-1.0

So without forcing types this works fine as well as both:
> Int[0:m-1]
> Int[m-n:-1]

However, the following code fails:
> Int[0:m-1, m-n:-1]
no method convert(Type{Int32},Range1{Float64})
 
Is this a bug (0.0.0-win32-4)  or I am doing something wrong?

Tim Holy

unread,
Jan 9, 2013, 3:21:45 PM1/9/13
to juli...@googlegroups.com
julia> ceil(3.5)
4.0

julia> iceil(3.5)
4

--Tim

Gabor

unread,
Jan 9, 2013, 3:37:31 PM1/9/13
to juli...@googlegroups.com
Thanks, but:
 
1. iceil() returns Int64 and not Int32 which is the default Int on Win32
    How to add this option would be a valid separate question.
 
2. The basic problem still remains
> n=8; m=iceil(n/2); Int[0:m-1, m-n:-1]
no method convert(Type{Int32},Range1{Int64})

Keno Fischer

unread,
Jan 9, 2013, 3:53:11 PM1/9/13
to juli...@googlegroups.com
1. This seems like a bug. I opened an issue. We'll figure it out.
2. You probably want n=8; m=int32(iceil(n/2)); Int[0:m-1,m-n:-1:-1] though the code you posted work for me so this might just be because of the outdated windows binary

New binaries will be released at some point during the next week.

Gabor

unread,
Jan 9, 2013, 3:58:41 PM1/9/13
to juli...@googlegroups.com
Thanks, Keno!
 
> n=8; m=int32(iceil(n/2)); Int[0:m-1,m-n:-1:-1]
no method convert(Type{Int32},Range1{Int32})
 
still fails for me (32-bit Vista, Julia version 0.0.0-win32-4).
Looking forward to you new binary.

Tim Holy

unread,
Jan 9, 2013, 4:18:27 PM1/9/13
to juli...@googlegroups.com
On Wednesday, January 09, 2013 12:37:31 PM Gabor wrote:
> Thanks, but:
>
> 1. iceil() returns Int64 and not Int32 which is the default Int on Win32

That's weird, and I wonder if it should be viewed as a bug. OK, then use m =
int(ceil(n/2)).

--Tim

Toivo Henningsson

unread,
Jan 10, 2013, 3:27:13 PM1/10/13
to juli...@googlegroups.com

I believe that this is how it has been designed (more or less).
While [x, y] is concatenation, T[x, y] where T is a type is AFAIK just meant to construct a vector of element type T with elements x and y. What surprises me is that Int[1:3] works. Apparently the case ref{T<:Number}(::Type{T}, r::Ranges) has been special cased to destructure the range (here), and I'm not sure why. (Convenience?)

Anyways, Int[(0:m-1)..., (m-n:-1)...] will do the trick.

Gabor

unread,
Jan 11, 2013, 9:55:09 AM1/11/13
to juli...@googlegroups.com
Thank you for the Int[(0:m-1)..., (m-n:-1)...]  trick!
 
At the same time I still think that if Int[0:m-1] works, then Int[0:m-1,m-n:-1] should work too.
Reply all
Reply to author
Forward
0 new messages