[julia-users] Re: help understanding different ways of wrapping functions

2016-09-27 Thread Gunnar Farnebäck
It's normal that manually inlined code of this kind is faster than wrapped code unless the compiler manages to see the full inlining potential. In this case the huge memory allocations for the wrapped solutions indicates that it's nowhere near doing that at all. I doubt it will take you all the

[julia-users] GC rooting for embedding: what is safe and unsafe?

2016-10-14 Thread Gunnar Farnebäck
Reading through the threads and issues on gc rooting for embedded code, as well as the code comments above the JL_GC_PUSH* macros in julia.h, I'm still uncertain about how defensive it's necessary to be and best practices. I'll structure this into a couple of cases with questions. 1. One of the

Re: [julia-users] GC rooting for embedding: what is safe and unsafe?

2016-10-17 Thread Gunnar Farnebäck
Thanks. That makes things clearer. Den fredag 14 oktober 2016 kl. 14:16:54 UTC+2 skrev Yichao Yu: > > > > On Fri, Oct 14, 2016 at 7:03 AM, Bart Janssens > wrote: > >> Hi, >> >> Replies below, to the best of my understanding of the Julia C interface: >>

[julia-users] Re: unsafe_wrap from a pointer from a Julia array

2016-11-15 Thread Gunnar Farnebäck
Is this what you're looking for? julia> using SIMD julia> v = rand(2, 5) 2×5 Array{Float64,2}: 0.391832 0.785861 0.352291 0.874891 0.874593 0.697768 0.51637 0.711525 0.400077 0.266559 julia> w = reinterpret(Vec{2, Float64}, vec(v)) 5-element Array{SIMD.Vec{2,Float64},1}: Float64⟨0.39

[julia-users] Re: Please help, simple double while

2015-01-27 Thread Gunnar Farnebäck
A double for loop requires a comma between the variables julia> for i=1:10, j=1:10 println(i," , ",j) end To get you're desired result a single loop is sufficient. julia> for i=1:10 println(i," , ",i) end 1 , 1 2 , 2 3 , 3 4 , 4 5 , 5 6 , 6 7 , 7 8 , 8 9 , 9 10

[julia-users] Re: Please help, simple double while

2015-01-27 Thread Gunnar Farnebäck
Syntactically you're still missing a comma between the loop variables. Semantically that's not how the double for loop works. Try either julia> for i = 1:length(x) println(x[i], y[i]) end or julia> for (i, j) in zip(x, y) println(i, j) end Den tisdag 27 ja

[julia-users] Re: How to quickly count the moving average with one vector and save in the other vec? Whitout while

2015-02-10 Thread Gunnar Farnebäck
If speed is what's important you almost certainly want some kind of loop. If it's more important not to have a loop you can satisfy your specification with b = reshape(repmat(mean(reshape(a,10,10),1),10),100) although that's not what I would call a moving average. Den tisdag 10 februari 2015 k

Re: [julia-users] Some simple use cases for multi-threading

2015-03-20 Thread Gunnar Farnebäck
Den fredag 20 mars 2015 kl. 05:36:15 UTC+1 skrev Kiran Pamnany: > > Hey Stefan, > > >> Depending on how well Julia-generated code performs, some important >>> concurrent data structures might be better implemented in C and wrapped. >> >> >> I would argue that until we can implement efficient con

[julia-users] Re: Efficient way to split an array/dataframe?

2015-03-26 Thread Gunnar Farnebäck
It doesn't behave the same with respect to duplicates in A but I would do N = 100 A = rand(N) n = iceil(0.7 * N) testindex = sample(1:size(A,1), replace=false, n) testA = A[testindex] trainindex = setdiff(1:N, testindex) trainA = A[trainindex] Den torsdag 26 mars 2015 kl. 06:21:42 UTC+1 skrev ver

[julia-users] Re: Convert Array{Tuple} to Matrix

2015-07-07 Thread Gunnar Farnebäck
This is reasonably clean: [y[i] for y in x, i in 1:3] If performance matters you are probably better off with the other suggestions. Den måndag 6 juli 2015 kl. 22:10:01 UTC+2 skrev Júlio Hoffimann: > > Hi, > > How to convert: > > 1000-element Array{Tuple{Integer,Integer,Integer},1}: > (10,2,1)

[julia-users] Re: Syntax for slicing with an array of ranges?

2015-08-19 Thread Gunnar Farnebäck
julia> [foo[r] for r in some_ranges] 2-element Array{Any,1}: [6,2] [4,9] julia> vcat([foo[r] for r in some_ranges]...) 4-element Array{Int64,1}: 6 2 4 9 Den onsdag 19 augusti 2015 kl. 04:53:55 UTC+2 skrev John Brock: > > Is there an easy way to slice an array using an array of ranges? I'm

Re: [julia-users] Re: Why is string concatenation done with * not +

2014-07-05 Thread Gunnar Farnebäck
Here's an example of a language that does a bit more with string operations. % pike Pike v7.8 release 700 running Hilfe v3.5 (Incremental Pike Frontend) > "ab" + "c"; (1) Result: "abc" > "abc" * 2; (2) Result: "abcabc" > "abcabc" - "ca"; (3) Result: "abbc" > "abcabc" / "b"; (4) Result: ({ /* 3 ele

Re: [julia-users] Numerical types and machine word size

2014-07-30 Thread Gunnar Farnebäck
In medical imaging, and probably most other parts of image processing with any kind of real-time expectations, single precision is used because the factor of 2 for SIMD operations is an enormously big deal, regardless whether the computations are done on a GPU or a CPU. There are pitfalls relat

[julia-users] Re: Trouble with BoundsError()

2014-07-30 Thread Gunnar Farnebäck
BoundsError means you're trying to index out of bounds. I see nothing in the backtrace indicating the splice function being involved and I have no way of knowing which line in your function is numbered 204 but there's a good chance Varraycut[i-1] will try to index at 0 in the first turn of your

[julia-users] Re: Counting instances from an array that fulfill some inequality statements

2014-07-30 Thread Gunnar Farnebäck
This is not the most efficient way, neither the clearest, but it's compact. In a language like Matlab it would be the preferred approach. sum((outputarray[1:end-1] .< 0) & (outputarray[2:end] .>= 0)) Den onsdagen den 30:e juli 2014 kl. 22:03:32 UTC+2 skrev yaois...@gmail.com: > > Hi guys, > > I

[julia-users] Re: question about array comparison

2014-08-07 Thread Gunnar Farnebäck
Is this easy enough? julia> x = reshape(1:16, 4, 4) 4x4 Array{Int64,2}: 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 julia> a = x[1,:] 1x4 Array{Int64,2}: 1 5 9 13 julia> [a == x[k,:] for k = 1:size(x,1)] 4-element Array{Any,1}: true false false false julia> any([a == x[k,:]

Re: [julia-users] Re: question about array comparison

2014-08-08 Thread Gunnar Farnebäck
gt; > To be honest, the custom for loop is probably your best bet in terms > > of performance: > > > > |function isrow(row, x::Matrix) > > for k=1:size(x,1) > >if row == x[k,:] > > return true > >end > > end

Re: [julia-users] Re: question about array comparison

2014-08-09 Thread Gunnar Farnebäck
Den fredagen den 8:e augusti 2014 kl. 22:25:01 UTC+2 skrev Steven G. Johnson: > > > > On Friday, August 8, 2014 3:19:00 AM UTC-4, Gunnar Farnebäck wrote: >> >> 1. As in Ethan's response (modulo a trivial bug): >> >> Matrix[x[k,:] for k=1:size(x,1)] >

[julia-users] Re: Best way to convert Any of vectors into matrix

2014-08-24 Thread Gunnar Farnebäck
For maximum efficiency Diego's loop solution is likely best but for succinctness, try hcat(A...). Den lördagen den 23:e augusti 2014 kl. 04:05:19 UTC+2 skrev Bradley Setzler: > > Good evening, > > I often have Any types filled with vectors (especially as the return of a > pmap), and need them as

Re: [julia-users] Re: How quickly calculate the entropy for long vectors ? -sum(x->x*log(2,x), [count(x->x==c,s)/length(s) for c in unique(s)])

2014-09-05 Thread Gunnar Farnebäck
You get NaN because the binning has left some bin empty and x * log(2, x) for x = 0.0 results in 0.0 * -Inf which is NaN. You can avoid this particular problem by replacing x * log(2,x) with something that special cases x = 0.0 to return 0.0 rather than NaN. Note that the result you get from th

Re: [julia-users] slow julia version of c code

2014-09-16 Thread Gunnar Farnebäck
This function helped me find a couple of type problems in a somewhat complex code base. The idea is to first run your code, then use this function to dig up the type signatures that were actually called and identify type problematic variables from code_typed. I strongly suspect that the inspect

[julia-users] Re: Article on `@simd`

2014-09-17 Thread Gunnar Farnebäck
In the section "The Loop Body Should Be Straight-Line Code", the first and second code example look identical with ifelse constructions. I assume the first one should use ? instead. Also the third code example has a stray x[i] > I've posted an article on the @simd feature to > https://software.

Re: [julia-users] Re: Article on `@simd`

2014-09-18 Thread Gunnar Farnebäck
as a nested ifelse in the same way as example 2 (although in the opposite order, so it also differs for a>b). Den onsdagen den 17:e september 2014 kl. 16:28:45 UTC+2 skrev Arch Robison: > > Thanks. Now fixed. > > On Wed, Sep 17, 2014 at 4:14 AM, Gunnar Farnebäck > wrote: >

Re: [julia-users] unexpected domain error for ^(float,float)

2014-09-18 Thread Gunnar Farnebäck
It's not like Julia is doing anything strange or uncommon here. Most people would be really surprised if -10² meant positive 100. Den torsdagen den 18:e september 2014 kl. 15:01:44 UTC+2 skrev Jutho: > > because it is not recognized/parsed as literal but as the application of a > unary minus, wh

Re: [julia-users] Is there a direct way to get binary representation of a float?

2015-10-18 Thread Gunnar Farnebäck
It might help if you explain something about what you want to do with the binary representation. For example, julia> f(x::Float64) = reinterpret(Float64, reinterpret(UInt64, x) & 0x7fff) f (generic function with 1 method) generates very simple LLVM code julia> code_llvm(f, (Float6

Re: [julia-users] Is there a direct way to get binary representation of a float?

2015-10-19 Thread Gunnar Farnebäck
Den måndag 19 oktober 2015 kl. 10:28:15 UTC+2 skrev Uliano Guerrini: > > > > Il giorno lunedì 19 ottobre 2015 08:56:32 UTC+2, Gunnar Farnebäck ha > scritto: >> >> It might help if you explain something about what you want to do with the >> binary representatio

[julia-users] Re: non-modifying push (and unshift, etc.)

2015-10-19 Thread Gunnar Farnebäck
Array{T, N} is a non-concrete type and thus an inference failure when a concrete type could have been inferred. Most of the concatenation inference failures existed in 0.3 but there are also some regressions, most annoyingly for some constructions referred to by deprecation messages. Den måndag

[julia-users] Re: Code runs 500 times slower under 0.4.0

2015-10-22 Thread Gunnar Farnebäck
If you don't have deprecation warnings I would suspect some change in 0.4 has introduced type instabilities. If you are using typed concatenations you could be hit by https://github.com/JuliaLang/julia/issues/13254. Den torsdag 22 oktober 2015 kl. 23:03:00 UTC+2 skrev Kris De Meyer: > > Are ther

[julia-users] Re: obtain T from Ptr{T} at runtime

2015-11-02 Thread Gunnar Farnebäck
julia> eltype(Ptr{Float64}) Float64 Den tisdag 3 november 2015 kl. 07:51:43 UTC+1 skrev Petr Hlavenka: > > Hi, > is there a way to obtain a type T from a Ptr{T}, e.g. get UInt32 from > Ptr{UInt32}. > > I'm trying to fix NIDAQ for 0.4 (tupplecalypse) > > This is needed if I have a signature of a f

[julia-users] Re: Google releases TensorFlow as open source

2015-11-12 Thread Gunnar Farnebäck
Den torsdag 12 november 2015 kl. 06:36:28 UTC+1 skrev Alireza Nejati > > Anyway, the problem I'm facing right now is that even though TensorFlow's > python interface works fine, I can't get TensorFlow's C library to build! > Has anyone else had any luck with this? I've had to update java AND gcc

Re: [julia-users] why does Julia have both map and broadcast?

2016-05-24 Thread Gunnar Farnebäck
In case the accidental matrix happens to be huge you can also get into all sorts of memory shortage related inconveniences. Den tisdag 24 maj 2016 kl. 07:27:24 UTC+2 skrev Tony Kelman: > > I can see some situations where getting a matrix instead of a vector > because one of the inputs was unexpe

[julia-users] Re: Strange performance issue in filling in a matrix column

2016-07-21 Thread Gunnar Farnebäck
fill_W1! allocates memory because it makes copies when constructing the right hand sides. fill_W2 allocates memory in order to construct the comprehensions (that you then discard). In both cases memory allocation could plausibly be avoided by a sufficiently smart compiler, but until Julia becom

[julia-users] Re: map(mean, zip(v...)) doesn't scale

2016-08-10 Thread Gunnar Farnebäck
I realize the question is about the performance of the zip approach but may I suggest just running mean(v)? On Wednesday, August 10, 2016 at 11:34:08 AM UTC+2, Tamas Papp wrote: > > I was benchmarking code for calculating means of vectors, eg > > v = [rand(100) for i in 1:100] > > m1(v) = map(m

[julia-users] Re: Loading data just once

2014-10-10 Thread Gunnar Farnebäck
I wrote this when I wanted to cache the results of matread. Your problem sounds like it could be similar. let matread_cache = (String => Any)[] global caching_matread function caching_matread(filename) if !haskey(matread_cache, filename) matread_cache[filename] = matre

[julia-users] Re: Ported a CSPRNG (Isaac64) from C, run times ~100x slower

2014-10-18 Thread Gunnar Farnebäck
I leave it to someone with more insights to comment on the efficiency of nested functions, but this seems at least to be substantially faster: type State a::Uint64 b::Uint64 aa::Uint64 bb::Uint64 cc::Uint64 RANDSIZL::Int RANDSIZ::Int end function ind(s::State, mm, x)

[julia-users] Re: Getting Julia to emit an unrolled inner loop with SIMD instructions

2014-11-02 Thread Gunnar Farnebäck
It might be possible to get further doing llvmcall with LLVM inline assembly but my feeble attempts at that have only resulted in crashes (well, sort of, getting dumped back to shell prompt without ceremony). Getting good load/store instructions by default would be a lot better of course but I

[julia-users] Re: ternary operator with return() gives (sometimes) errors

2014-11-25 Thread Gunnar Farnebäck
Most likely Julia tries to parse it as x > 10 ? return ((0):nothing) Try x > 10 ? (return 0) : nothing instead. Or the more popular construction x <= 10 || return 0 Den tisdagen den 25:e november 2014 kl. 11:21:39 UTC+1 skrev andreas: > > > Dear list, > > I observed that this > > function foo(x

Re: [julia-users] simplex in Julia is very slow

2014-11-27 Thread Gunnar Farnebäck
It does have issues. I tracked down a part of the story to https://github.com/JuliaLang/julia/pull/9086 Den onsdagen den 26:e november 2014 kl. 20:52:57 UTC+1 skrev Stefan Karpinski: > > I wonder if \ might be type unstable. >

[julia-users] Re: JULIA code performance help

2014-12-24 Thread Gunnar Farnebäck
Most likely your performance is destroyed by the conditional definition of the Ti, c1, ... coefficients. It's a rather unfortunate limitation of the type inference, causing all those variables to be handled as Any, and everything that depends on them as well, i.e. more or less everything in you

[julia-users] Re: if .. else on a whole array

2016-02-10 Thread Gunnar Farnebäck
If you're not concerned about performing unneeded calls to u2_0 you can get away with (x.>Lbox/2) .* (0.5*(u2_0(x)+u2_0(Lbox-x))-u2_ 0(Lbox/2)) Den onsdag 10 februari 2016 kl. 11:58:58 UTC+1 skrev Ferran Mazzanti: > > Hi folks, > > probably a stupid question but can't find the answer, so please

[julia-users] Re: Concurrently install two versions of Julia

2016-03-08 Thread Gunnar Farnebäck
The environment variable JULIA_PKGDIR may be of use. Den måndag 7 mars 2016 kl. 05:44:29 UTC+1 skrev Vishnu Raj: > > In my system I have Juno with 0.4.2 and julia with 0.4.3. Every time I > start one, all my packages are getting recompiled. They are all under same > v0.4 folder and I think that'

[julia-users] Re: compact syntax for mapping vector to tuple

2016-03-31 Thread Gunnar Farnebäck
This is at least shorter. julia> (v.^2...) (1,4,81) Den torsdag 31 mars 2016 kl. 10:28:09 UTC+2 skrev Tamas Papp: > > Hi, > > Is there a preferred syntax for mapping a vector to a tuple? Eg an > alternative for (contrived example) > > v = [1,2,9] > ntuple(i -> v[i]^2, length(v)) > tuple([e^2

[julia-users] Re: Declaration of types in function construction...

2016-05-12 Thread Gunnar Farnebäck
Your problem is probably that you try to call your function with four positional arguments, although the last two should have been named. Compare julia> f(x, y; z=0) = x + y + z f (generic function with 1 method) julia> f(2, 3) 5 julia> f(2, 3, 4) ERROR: MethodError: `f` has no method matching

[julia-users] Re: Type Parameter Tags, Constructor Generators, and Lazy Loading, oh my!

2013-12-19 Thread Gunnar Farnebäck
It's the same kind of technique I used to generate convolution loops for different number of dimensions in https://github.com/GunnarFarneback/julia/commit/51d8c86dd6bdb4c02d03e312dede7e5013da5ae1 See the start and end of the imfilterN_loops function. I'm obviously biased but I think the construc

[julia-users] Julia implementation of zlib and gzip decompression

2014-01-04 Thread Gunnar Farnebäck
At some point when I had trouble loading zlib I wrote a pure Julia implementation of zlib and gzip decompression. Pros: * Written in Julia. * No external dependencies. Cons: * Only supports decompression and only from a buffer (i.e. no streaming). * Substantially slower than zlib (about five tim

Re: [julia-users] Julia implementation of zlib and gzip decompression

2014-01-06 Thread Gunnar Farnebäck
magnitude faster. Den lördagen den 4:e januari 2014 kl. 19:03:33 UTC+1 skrev Stefan Karpinski: > > Possibly relevant is Julia Evan's gzip implementation: > > http://jvns.ca/blog/2013/10/24/day-16-gzip-plus-poetry-equals-awesome/ > > > On Sat, Jan 4, 2014 at 6:54 AM, Gunnar F

[julia-users] Re: Fast (symmetric) matrix subsetting

2014-01-22 Thread Gunnar Farnebäck
You can index both dimensions at once. matrix[subset, subset] On Wednesday, January 22, 2014 10:20:21 AM UTC+1, Robert Feldt wrote: > > I need to repeatedly take subsets of large symmetric matrices > (symmetrically with the same subset indicies for rows and columns) and > first tried like so: >

[julia-users] Re: Method redefinition only half works

2014-03-07 Thread Gunnar Farnebäck
This is a long-standing issue. See https://github.com/JuliaLang/julia/issues/265 Den fredagen den 7:e mars 2014 kl. 17:17:49 UTC+1 skrev David Moon: > > In Julia-0.3.0-prerelease-d2d9bd93ed.app on Mac OS X 10.6: > > julia> p() = q() > p (generic function with 1 method) > julia> p2() = q() > p2 (g

[julia-users] Re: Constructing arrays with dim > 2

2014-03-24 Thread Gunnar Farnebäck
[f(i,j)[k] for k in 1:K, i in 1:n, j in i:m] Den måndagen den 24:e mars 2014 kl. 15:07:49 UTC+1 skrev Linus Mellberg: > > Hi! > > I'm trying to construct a 3 dimensional array from a number of 1 > dimensional arrays. Essentially what i would like to do is > > a = [f(i, j) for i in 1:n, j in 1:m]

[julia-users] Re: Constructing arrays with dim > 2

2014-03-24 Thread Gunnar Farnebäck
Ok, one might be less redundant if reading the thread properly before posting. Sorry about the noise. Den måndagen den 24:e mars 2014 kl. 23:12:03 UTC+1 skrev Gunnar Farnebäck: > > [f(i,j)[k] for k in 1:K, i in 1:n, j in i:m] > > Den måndagen den 24:e mars 2014 kl. 15:07:49 UTC+1

[julia-users] Re: preserve column type when building a matrix

2014-04-01 Thread Gunnar Farnebäck
Ugly workaround: julia> [Array(Any,3,0) [1:3] float([1:3])] 3x2 Array{Any,2}: 1 1.0 2 2.0 3 3.0 Den tisdagen den 1:e april 2014 kl. 10:39:15 UTC+2 skrev harven: > > When I build a matrix from columns using vcat, the type of the columns is > sometimes modified, e.g. > > julia> [[1:3] float(

Re: [julia-users] line continuation

2014-04-17 Thread Gunnar Farnebäck
You can also use parentheses to make the first line incomplete. if (a>b && b>c) Den torsdagen den 17:e april 2014 kl. 00:30:41 UTC+2 skrev K leo: > > Thanks for the answer. > > I tested previously this but it did not work: > if a>b && b>c && c>d > && d>e && e>f > > But now this works

[julia-users] Re: Performance expectations and benchmarks

2014-04-17 Thread Gunnar Farnebäck
I have, in the process of evaluating Julia, ported some proprietary matlab image processing code, at the order of 3k lines matlab and 1k lines C mex code, into pure Julia. The matlab code is fairly well optimized with most computations vectorized (usually comes natural in image processing) and

[julia-users] Re: question on multiple assignment

2014-04-17 Thread Gunnar Farnebäck
You can do multiple assignment with anything you can iterate over on the right hand side, in this case you could do e.g. aa, bb = 12:3:15 with the same assignment to aa and bb. One difference is in the value of the expression, as printed by the REPL, which coincides with the RHS but would usual

Re: [julia-users] All packages for numerical math

2014-04-24 Thread Gunnar Farnebäck
Sum uses pairwise summation, see https://github.com/JuliaLang/julia/pull/4039 To find the definition: julia> @which sum(int) sum{T}(a::AbstractArray{T,N}) at reduce.jl:276 Den torsdagen den 24:e april 2014 kl. 11:46:37 UTC+2 skrev Alex: > > I couldn't find the definition of sum right now, but I

[julia-users] Re: Expand array in all dimensions

2014-04-25 Thread Gunnar Farnebäck
The padarray function in the Images package can solve your problem or give you inspiration if you want to do it differently. Den fredagen den 25:e april 2014 kl. 05:43:40 UTC+2 skrev Tomas Lycken: > > Given the following function definition > > function foo{T<:FloatingPoint}(A::Array{T}) > B

[julia-users] Re: logical indexing... broadcasting

2014-05-14 Thread Gunnar Farnebäck
If nothing else works you can solve it with a manual repmat. A different approach is to forgo the logical indexing entirely. species_codes = ["setosa" => [1 0 2], "versicolor" => [2 1 0], "virginica" => [0 2 1]] N = length(iris_data.columns[5]) iris_output = zer

Re: [julia-users] Re: step function like behaviour

2014-06-10 Thread Gunnar Farnebäck
Other options, both faster: int(x.*x + y.*y .< radius*radius) [(x[k]*x[k] + y[k]*y[k] < r*r)?1:0 for k=1:length(x)] Den söndagen den 8:e juni 2014 kl. 02:02:56 UTC+2 skrev Zahirul ALAM: > > thanks guys for all of these :) > > On Saturday, 7 June 2014 14:25:08 UTC-4, David Einstein wrote: >> >> It

[julia-users] Re: Repeated array indexing

2014-06-10 Thread Gunnar Farnebäck
You can do B[E[:],:] or better write E as a vector (rather than a 1x10 array) directly: E = [5, 5, 5, 4, 5, 5, 5, 5, 1, 5] Then B[E,:] works as expected. Den tisdagen den 10:e juni 2014 kl. 15:40:50 UTC+2 skrev Bruno Rodrigues: > > Hi, I posted a first thread but can't find it anywhere, so I prob