[julia-users] Re: Questions about ranges

2015-10-22 Thread Rory Finnegan
Wow, you're right, that is a more serious bug.

On Thursday, 22 October 2015 02:29:13 UTC-5, andy hayden wrote:
>
> > I don't really understand why you can't just use the StepRange for 
> everything
>
> You could. However, you can be more efficient by having special types 
> (e.g. with UnitRange you don't need to check the steps).
>
> >  `findin(::UnitRange, ::UnitRange)` returns another UnitRange
>
> This seems good.
>
> > `findin(::StepRange, ::StepRange)` returns an array of the indices
>
> You might be able to do some maths here to return a StepRange... at least 
> for Integers:
>
> function Base.findin{T <: Integer}(a::StepRange{T}, b::StepRange{T})
> start = ??
> step = b.step รท gcd(a.step, b.step)
> stop = max(a.stop, b.stop)
> start:step:stop
> end
>
> but I 'm not sure this is possible with floats...
>
> Looking in the source mentioning UnitRange here's a more serious bug: 
> https://github.com/JuliaLang/julia/blob/e16c6784e1ba6f24b6faf0d282c78d8c14a1fbb3/base/array.jl#L866
>
> julia> findin([5.2, 3.3], 3:20)
> 2-element Array{Int64,1}:
>  1
>  2
>
> julia> findin([5.2, 3.3], 3:1:20)
> 0-element Array{Int64,1}
>
> !
>
> On Wednesday, 21 October 2015 19:59:20 UTC-7, Rory Finnegan wrote:
>>
>> Hi folks,
>>
>> I just had a couple questions about ranges that maybe someone can answer.
>>
>>
>> 1) Why are there so many Range types? There is a UnitRange (start, stop), 
>>  a StepRange (start, step, stop), and a FloatRange(start, step, length, 
>> divisor), but I don't really understand why you can't just use the 
>> StepRange for everything. Maybe I'm just missing some obvious use cases, 
>> but this seems to lead to inconsistent or confusing behaviour like the 1 in 
>> my second question.
>>
>> 2) `findin` seems to have inconsistent behaviour for ranges depending on 
>> types in the ranges. `findin(::UnitRange, ::UnitRange)` returns another 
>> UnitRange, but `findin(::StepRange, ::StepRange)` returns an array of the 
>> indices. Is there some reason that these shouldn't be consistent?
>>
>> Ex:
>> ```
>> julia> findin(1:10, 2:5)
>> 2:5
>>
>> julia> findin(1:1:10, 2:2:5)
>> 2-element Array{Int64,1}:
>>  2
>>  4
>>
>> julia> r1 = DateTime(now())-Dates.Day(60):DateTime(now())
>> 2015-08-22T19:07:47:1 day:2015-10-21T19:07:47
>>
>> julia> r2 = r1[1:20]
>> 2015-08-22T19:07:47:1 day:2015-09-10T19:07:47
>>
>> julia> findin(r1, r2)
>> 20-element Array{Int64,1}:
>>   1
>>   2
>>   3
>>   4
>>   5
>>   6
>>   7
>>   8
>>   9
>>  10
>>  11
>>  12
>>  13
>>  14
>>  15
>>  16
>>  17
>>  18
>>  19
>>  20
>> ```
>>
>

[julia-users] Questions about ranges

2015-10-21 Thread Rory Finnegan
Hi folks,

I just had a couple questions about ranges that maybe someone can answer.


1) Why are there so many Range types? There is a UnitRange (start, stop), 
 a StepRange (start, step, stop), and a FloatRange(start, step, length, 
divisor), but I don't really understand why you can't just use the 
StepRange for everything. Maybe I'm just missing some obvious use cases, 
but this seems to lead to inconsistent or confusing behaviour like the 1 in 
my second question.

2) `findin` seems to have inconsistent behaviour for ranges depending on 
types in the ranges. `findin(::UnitRange, ::UnitRange)` returns another 
UnitRange, but `findin(::StepRange, ::StepRange)` returns an array of the 
indices. Is there some reason that these shouldn't be consistent?

Ex:
```
julia> findin(1:10, 2:5)
2:5

julia> findin(1:1:10, 2:2:5)
2-element Array{Int64,1}:
 2
 4

julia> r1 = DateTime(now())-Dates.Day(60):DateTime(now())
2015-08-22T19:07:47:1 day:2015-10-21T19:07:47

julia> r2 = r1[1:20]
2015-08-22T19:07:47:1 day:2015-09-10T19:07:47

julia> findin(r1, r2)
20-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
```


[julia-users] Re: Announcement: Playground.jl

2014-08-24 Thread Rory Finnegan
Awesome! Thanks for letting my know it works on Mac.  I'll see if I can fix 
that warning message.

On Sunday, 24 August 2014 11:59:47 UTC-4, Adam Smith wrote:
>
> Nice work! It seems to work on a Mac as well. There is a warning that gets 
> printed every time you use the playground command, but it still seems to 
> work.
>
> $ playground . activate
> Warning: requiring "Playground" did not define a corresponding module.
> playground> echo "foo"
> foo
> playground> julia
>_
>_   _ _(_)_ |  A fresh approach to technical computing
>   (_) | (_) (_)|  Documentation: http://docs.julialang.org
>_ _   _| |_  __ _   |  Type "help()" for help.
>   | | | | | | |/ _` |  |
>   | | |_| | | | (_| |  |  Version 0.3.0 (2014-08-20 20:43 UTC)
>  _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
> |__/   |  x86_64-apple-darwin13.3.0
>
> julia> using Gadfly
> ERROR: Gadfly not found
>  in require at loading.jl:47
>
> julia>
>
> playground> exit
>
>
>
> On Saturday, August 23, 2014 4:01:45 PM UTC-4, Rory Finnegan wrote:
>>
>> Hi everyone,
>>
>> I've published my Playground.jl 
>> <https://github.com/Rory-Finnegan/Playground.jl> package to create julia 
>> sandboxes like python virtual environments, if anyone wants to give it a 
>> try.  So far I've tested it on Funtoo and Linux Mint, but I'm looking for 
>> people to try it out on other platforms (like Windows and OSX).
>>
>> Cheers,
>> Rory
>>
>

[julia-users] Announcement: Playground.jl

2014-08-23 Thread Rory Finnegan
Hi everyone,

I've published my Playground.jl 
<https://github.com/Rory-Finnegan/Playground.jl> package to create julia 
sandboxes like python virtual environments, if anyone wants to give it a 
try.  So far I've tested it on Funtoo and Linux Mint, but I'm looking for 
people to try it out on other platforms (like Windows and OSX).

Cheers,
Rory