On Sunday, April 10, 2016 09:03:06 AM Fred wrote:
> A huge size difference ! I have to read my array from data file so I
> suppose it is like Y and X is only for simulations ?
There turn out to be many situations in which you can take shortcuts if you
know the values are sorted in increasing
A huge size difference ! I have to read my array from data file so I
suppose it is like Y and X is only for simulations ?
Le dimanche 10 avril 2016 17:50:02 UTC+2, Tim Holy a écrit :
>
> Just FYI:
>
> julia> x = 1:0.1:100
> 1.0:0.1:1.0e6
>
> julia> y = collect(x); # this is the same as y
Just FYI:
julia> x = 1:0.1:100
1.0:0.1:1.0e6
julia> y = collect(x); # this is the same as y = [x;]
julia> sizeof(x)
32
julia> sizeof(y)
7928
--Tim
On Sunday, April 10, 2016 07:26:06 AM Fred wrote:
> Maybe my array is too small to see a difference, but if I increase the size
> I will
Maybe my array is too small to see a difference, but if I increase the size
I will lack of RAM ;)
julia> x = 1:0.1:100
1.0:0.1:1.0e6
julia> @time searchsorted(x, 8.22)
0.045590 seconds (33.21 k allocations: 1.535 MB)
74:73
julia> @time searchsorted(x, 8.22)
0.05 seconds (8
Even better: get rid of the brackets around 1:0.1:10, and you'll be that
much more impressed.
--Tim
On Sunday, April 10, 2016 07:16:16 AM Fred wrote:
> Hi,
>
> I post here my best solution taking advantage that the array is sorted. I
> expected to be a lot much faster than other solutions,
Hi,
I post here my best solution taking advantage that the array is sorted. I
expected that solution to be a lot much faster than other solutions, but
not really.
Indeed I am very impressed by the speed of searchsorted
:
x = [1:0.1:100]
val = 8.22
function dicotomy(x, val)
a =
Hi,
I post here my best solution taking advantage that the array is sorted. I
expected to be a lot much faster than other solutions, but not really.
I am very impressed by the speed of searchsorted
:
x = [1:0.1:100]
val = 8.22
function dicotomy(x, val)
a = start(eachindex(x))
b =
On Sun, 2016-04-10 at 15:24, Fred wrote:
> That's true ! But why a loop is faster in a function ? :)
Check out:
http://docs.julialang.org/en/release-0.4/manual/performance-tips/#avoid-global-variables
>>
>> I seem to recall that your example loop was not in a
That's true ! But why a loop is faster in a function ? :)
>
> I seem to recall that your example loop was not in a function(?) If so,
> that makes it lots slower.
>
>
> I tested my loop monre than 2 times as it is written in my post and I have
> always the same results. The function Tim Holy posted is much faster, I
> posted the results above :)
I seem to recall that your example loop was not in a function(?) If so,
that makes it lots slower.
>> Probably
I tested my loop monre than 2 times as it is written in my post and I have
always the same results. The function Tim Holy posted is much faster, I
posted the results above :)
> Probably you are doing this wrong; it shouldn't be allocating so much
> memory. Is your loop using global
On Sunday, April 10, 2016 at 8:30:48 AM UTC-4, Fred wrote:
>
> my loop solution :
> 0.000419 seconds (547 allocations: 708.797 KB)
> 0.02135 -> 73
>
Probably you are doing this wrong; it shouldn't be allocating so much
memory. Is your loop using global variables? Did you
Thank you very much Mauro ! searchsorted is the simplest solution and one
of the fastest but it gives two indices so another comparison is needed to
find the closest value :
@time searchsorted(x, 8.22)
0.04 seconds (7 allocations: 240 bytes)
74:73
abs(x[73] - 8.22) > abs(x[74] - 8.22)
Thank you very much !
I give you the results :
my loop solution :
0.000419 seconds (547 allocations: 708.797 KB)
0.02135 -> 73
@time closest_index(x,8.22)
0.03 seconds (4 allocations: 160 bytes)
73
@time for (i,x) in enumerate(array)...
0.000181 seconds (821 allocations:
If your array is sorted, as your example suggests, there maybe faster
methods, binary search comes to mind (implemented in searchsorted).
Also, if the array is unsorted but you need to look up many values, it
might be worth sorting it first. Mauro
On Sun, 2016-04-10 at 13:40, Fred
Fred
Yes, the fastest way is a loop. (It might be possible to extend e.g.
`minimum` by a "predicate" argument, but that would require a change
to the base library.)
You would write the loop slightly differently, though:
```Julia
mini = 0
minx = 0.0
mindx = typemax(Float64)
for (i,x) in
indmin(abs(x-val)) is easy and pretty good, but it does create two
temporaries. Faster would be
function closest_index(x, val)
ibest = start(eachindex(x))
dxbest = abs(x[ibest]-val)
for I in eachindex(x)
dx = abs(x[I]-val)
if dx < dxbest
dxbest = dx
Hi,
I am looking for the most efficient (fastest) way to find the indice of the
element with the nearest value of a float in an array.
x = [1:0.1:10]
julia> x
91-element Array{Float64,1}:
1.0
1.1
1.2
1.3
1.4
⋮
9.4
9.5
9.6
9.7
9.8
9.9
10.0
It is very easy to find the
Is there an equivalent of
@edit function(arg1, ...)
for type definitions? @edit is so nice in Emacs. Currently I am using
M-x find-grep-dired RET \(type\|immutable\) Foo
but something built-in for Julia would be very convenient.
Best,
Tamas
`x .> 3` is a bit-array. The function form, which is probably what fits, is
`x->x.>3` (the back-ticks are for quotation, not part of the code).
when trying
x=[0,1,3,4,6,1]
find(x.>3,x)
I always get the error:
ERROR: MethodError: `find` has no method matching find(::BitArray{1},
::Array{Int64,1})
Closest candidates are:
find(::Function, ::AbstractArray{T,N})
find(::BitArray{N})
What is the best way of telling whether an element `x` is present in a
sorted list `a`?
Using `searchsortedlist`, I also need to check that the element is present
in the list. This is what I do
function isinsortedlist(a, x)
n = searchsortedfirst(a, x)
n <= length(a) && a[n] == x
end
On Sat, Nov 7, 2015 at 4:34 PM, Milan Bouchet-Valat
wrote:
> Le samedi 07 novembre 2015 à 06:37 -0800, Michele Zaffalon a écrit :
> > What is the best way of telling whether an element `x` is present in
> > a sorted list `a`?
> >
> > Using `searchsortedlist`, I also need to
Given a set of vectors v1, , vn, I'd like to construct a matrix where
columns correspond to a linearly independent subset of these vectors.
Currenly, I form the matrix hcat(v1, ..., vn), use qrfact!() on it, check
the diagonal of the :R matrix and construct a new matrix as hcat(vj,...)
I'm
Le vendredi 11 septembre 2015 à 16:03 -0700, cormull...@mac.com a écrit
:
> Is there a Julia function/method to find the location(s) of a
> sequence of elements in a 1-D array?
>
> With strings, you can do:
>
> search("longstring", "str")
>
> 5:7
>
> so with arrays it would hopefully
Hi Milan - thanks for the clues! I found `Base._searchindex`, which work
for integers:
julia> a = rand(1:10, 100);
julia> Base._searchindex(a, [19272, 52257], 1)
86
It's pretty quick, too.
Is there a Julia function/method to find the location(s) of a sequence of
elements in a 1-D array?
With strings, you can do:
search("longstring", "str")
5:7
so with arrays it would hopefully be something like:
searcharray( [1, 3, 5, 7, 9, 11, 13], [5, 7, 9])
3:5
Le jeudi 11 septembre 2014 à 20:12 -0700,
i.pallikarakis...@alumni.lboro.ac.uk a écrit :
Hi everyone,
I am new to Julia and just upgraded from 0.2.1 to 0.3.0 and found the
following issue :
find function is no longer working on sparse matrices. For example
A=speye(Bool,10)
Hi everyone,
I am new to Julia and just upgraded from 0.2.1 to 0.3.0 and found the
following issue :
find function is no longer working on sparse matrices. For example
A=speye(Bool,10)
find(x-x==true,A)
-0-element Array{Int64,1}
find(x-x==true,full(A))
-10-element Array{Int64,1}:
1
12
23
Hi julia-users,
I am looking for a function that takes a two-dimensional matrix and a set
of matrix indices as inputs and spits out the nearest non-zero element in
taxicab distance over the matrix index.
I am asking for your advice because this function needs to be very fast as
I have to do
testing against C_NULL is probably the easiest way:
p == C_NULL
On Sat, Jun 14, 2014 at 10:39 PM, J Luis jmfl...@gmail.com wrote:
How do I test if a pointer is NULL?
(did search the docs but couldn't find and answer)
and BTW, I can't get this one either
docs:
pointer(*type*, *int*)
31 matches
Mail list logo