Memory usage can be an issue if you're simply iterating over a long range,
e.g.
julia> function pi_half_montecarlo(n)
mysum = 0
for x in linrange(0,1,n)
y = rand()
if x*x + y*y < 1
mysum += 1
end
end
return
On Sunday, 25 October 2015 07:05:03 UTC-7, Christoph Ortner wrote:
>
>
> very nice example - thank you - but I notice that you use linrange :).
>
> Thanks, Christoph
>
Man I wish they had called it linrange ;) with type LinRange. Still I am at
peace with the new way it works. Hopefully it will
very nice example - thank you - but I notice that you use linrange :).
Thanks, Christoph
So here is a reason for keeping the linespace a vector:
julia> t = linspace(0, 1, 1_000_000);
julia> s = collect(t);
julia> @time for n = 1:10; exp(t); end
0.209307 seconds (20 allocations: 76.295 MB, 3.42% gc time)
julia> @time for n = 1:10; exp(s); end
0.054603 seconds (20 allocations:
P.S.: It occurred to me that I should also have tried this:
@time for n = 1:10; AppleAccelerate.exp(collect(s)); end
0.041035 seconds (60 allocations: 152.589 MB, 22.94% gc time)
You're making a good point about an Array being sometimes faster than a
LinSpace. But a LinSpace gets you a factor N improvement in terms of memory
efficiency for a size N range, an Array only gets you a constant factor
improvement in speed (the factor 15 being admittedly relatively large in
Le mercredi 21 octobre 2015 à 16:22 -0400, Spencer Russell a écrit :
> On Wed, Oct 21, 2015, at 04:07 PM, Gabriel Gellner wrote:
> > That doesn't feel like a reason that they can't be iterators,
> > rather that they might be slow ;) a la python. My point is not
> > about speed but the consistency
I may have said this earlier, but we just need
https://github.com/JuliaLang/julia/issues/7799.
--Tim
On Thursday, October 22, 2015 12:11:05 AM Christoph Ortner wrote:
> So here is a reason for keeping the linespace a vector:
>
> julia> t = linspace(0, 1, 1_000_000);
> julia> s = collect(t);
>
On Thursday, October 22, 2015 at 9:44:28 AM UTC-4, Gabriel Gellner wrote:
>
> A related discussion is about a special Ones type representing an array
>> of 1, which would allow efficient generic implementations of
>> (non-)weighted statistical functions:
>>
>
> A related discussion is about a special Ones type representing an array
> of 1, which would allow efficient generic implementations of
> (non-)weighted statistical functions:
> https://github.com/JuliaStats/StatsBase.jl/issues/135
>
> But regarding zeros(), there might not be any
On Thursday, 22 October 2015 10:24:50 UTC+1, Andras Niedermayer wrote:
>
> You're making a good point about an Array being sometimes faster than a
> LinSpace. But a LinSpace gets you a factor N improvement in terms of memory
> efficiency for a size N range, an Array only gets you a constant
All true.
One tip: if you want to find out what abstract type is a parent to all the
concrete types you're interested in, you can use the "typejoin" function.
julia> typejoin(Array, LinSpace)
AbstractArray{T,N}
julia> typejoin(Vector,LinSpace)
AbstractArray{T,1}
On Wednesday, October 21,
On Wednesday, October 21, 2015 at 11:50:32 AM UTC-4, Spencer Russell wrote:
>
> For efficiency you'll still want to use a concrete Vector field if you're
> defining your own types, but luckily there seems to be a convert method
> defined so you can do:
>
> type MyArr{T}
> x::Vector{T}
>
On Wed, Oct 21, 2015, at 11:38 AM, Gabriel Gellner wrote:
> No that is a good point. Often you can use an iterator where an
> explicit array would also work. The issue I guess is that this puts
> the burden on the developer to always write generic code that when you
> would want to accept an Array
Actually it is that easy... you just have to get in the habit of doing it:
julia> function mysum(arr::Array)
s = zero(eltype(arr))
for a in arr
s += a
end
s
end
mysum (generic function with 1 method)
julia> mysum(1:10)
ERROR:
On Wed, Oct 21, 2015, at 12:08 PM, Steven G. Johnson wrote:
> On Wednesday, October 21, 2015 at 11:50:32 AM UTC-4, Spencer Russell wrote:
>>
>> For efficiency you'll still want to use a concrete Vector field if
>> you're defining your own types, but luckily there seems to be a
>> convert method
Just to add to Spencer's answer: Is there a particular reason to have your
function arguments have type annotations at all in the function definition?
You could just write
function f(x)
y= x[3:5] # or whatever
z = length(x)
end
and now someone could call f with any kind of object that
On Wednesday, October 21, 2015 at 11:57:08 AM UTC-4, Jonathan Malmaud wrote:
>
> Just to add to Spencer's answer: Is there a particular reason to have your
> function arguments have type annotations at all in the function definition?
> You could just write
>
> function f(x)
> y= x[3:5] # or
Wow! Thanks everyone for all the advice!!! Super helpful. I now see that it
is super easy to deal with the LinSpace objects.
That being said I guess I get scared when the docs tell me to use concrete
types for performance ;) Most of the code I write for myself is working
with Float64 arrays a
On Wed, Oct 21, 2015 at 4:07 PM, Gabriel Gellner
wrote:
> That doesn't feel like a reason that they can't be iterators, rather that
> they might be slow ;) a la python. My point is not about speed but the
> consistency of the language.
How do you propose making
I actually tend to think that's a pretty strong reason.
On Wednesday, October 21, 2015 at 10:07:23 PM UTC+2, Gabriel Gellner wrote:
>
> That doesn't feel like a reason that they can't be iterators, rather that
> they might be slow ;) a la python.
>
I have no issue with the LinSpace object, I simply do not see why it is the
special case for this kind of object (I imagine the choice was made since
it was seen to be used mainly for looping vs being used for array creation
like similar functions logspace, zeros, ones, etc). If the iterator
On Wed, Oct 21, 2015, at 04:07 PM, Gabriel Gellner wrote:
> That doesn't feel like a reason that they can't be iterators, rather
> that they might be slow ;) a la python. My point is not about speed
> but the consistency of the language. Are there many cases in Julia
> where there is a special
It’s still hard for me to understanding what the value of returning an array is
by default.
By getting a structured LinSpace object, it enables things like having the REPL
print it in a special way, to optimize arithmetic operations on it (so that
adding a scalar to a LinSpace is O(1) instead
The reason why not all arrays can be iterators is that in general arrays
can not be 'compressed' like that. A linear range can be compressed to: a
start value, an increment, and a length, making it incredibly lightweight.
Doing this for sin() is not that easy. Doing it for rand() is simply
That doesn't feel like a reason that they can't be iterators, rather that
they might be slow ;) a la python. My point is not about speed but the
consistency of the language. Are there many cases in Julia where there is a
special type like this because it is convenient/elegant to implement? This
You're making good points for sure - logspace and linspace are inconsistent
wrt return types.
But I just having trouble seeing how it impacts you as a user of the
language; it's essentially an implementation detail that allows for some
optimizations when performing arithmetic on array-like
The whole notion of always using a single dense array type is simply a
non-starter. Do we just scrap the whole sparse array thing? There goes half
of the stuff you might want to do in linear algebra or machine learning.
Special matrix types like Diagonal or UpperTriangular, etc.? Toss those out
On Wed, Oct 21, 2015 at 5:13 PM, Gabriel Gellner
wrote:
> Maybe all this is just transitional that soon LinSpace objects will always
> work like Arrays in all code I might use as an end user. Currently as a new
> user I have not had this experience. I have noticed that
Okay so I am starting to see the light. I see that if LinSpace becomes
fully replacable for an Array it is fine.
Final Questions:
* I can't use LinSpace in matrix mult A * b::LinSpace, is this simply a
Bug/Missing Feature? Or intentional? In general if basic builtin functions
that operate on
Sweetness. Thank you. AbstractArray it is for me!
On Wednesday, 21 October 2015 16:29:28 UTC-7, Tim Holy wrote:
>
> On Wednesday, October 21, 2015 03:32:04 PM Gabriel Gellner wrote:
> > * I can't use LinSpace in matrix mult A * b::LinSpace, is this simply a
> > Bug/Missing Feature?
>
> Yes
>
On Wednesday, October 21, 2015 03:32:04 PM Gabriel Gellner wrote:
> * I can't use LinSpace in matrix mult A * b::LinSpace, is this simply a
> Bug/Missing Feature?
Yes
> * LinSpace objects seem much slower when used in things like element
> multiplication A .* b::LinSpace is much much Slower than
Isn't the situation actually similar to functions like `eye` which returns
a dense array (which doesn't feel intuitive for what an eye or diagonal
matrix actually is) whereas we have to call the special version seye to get
a sparse array. For most users linspace is like `eye` by default
33 matches
Mail list logo