Re: [julia-users] Re: Extending functions in Base (or another module)

2016-06-28 Thread Rafael Fourquet
I'm far from expert on those questions, but would the "invoke" function work? I think it's considered to be a tool of the last resort, but seems to be the situation you are in! invoke(f, (types...), args...) Invoke a method for the given generic function matching the specified types (as a tuple

Re: [julia-users] indexing over `zip(collection1, collection2)`

2016-06-23 Thread Rafael Fourquet
> My recollection is that part of the indexing interface in Julia (just by > convention) is that indexing should be of O(1) (or close to that) > complexity. As the OP suggested, this could still be the case, the zip object would simply forward the indexing to the zipped collections, which would fa

Re: [julia-users] inner constructor returning an object of a different type

2016-06-11 Thread Rafael Fourquet
In the pre-jb/functions era, where higher-order functions where suboptimal (because function calls would not specialize on them), there was a trick using the feature you noticed to overcome this limitation, i.e. make it fast. Cf the discussion at https://groups.google.com/d/topic/julia-users/qscRyN

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Rafael Fourquet
I think the OP's question is not about the difference between a macro and a function, but rather about the syntactic way of defining a macro: if a macro can be seen as a function taking an expression and returning another one, why can't we just define a macro with the standard function syntax (i.e.

Re: [julia-users] Lack of an explicit return in Julia, heartache or happiness?

2016-05-26 Thread Rafael Fourquet
And indeed, as Scott points, a function can switch from using the short form to the long form only because the number of characters grows a bit, which is uncorelated to the functionalness. Having the short form and long form disagree on the "default" returned value would increase the risk to introd

Re: [julia-users] Lack of an explicit return in Julia, heartache or happiness?

2016-05-26 Thread Rafael Fourquet
I would be sorry to see this so elegant functional aspect of Julia return to the void. It fits well with the expression-rather-than-statement feel of Julia. Regarding the annoyance of having to explicitly "return nothing" for "procedures" (functions which are called only for side-effects): I would

Re: [julia-users] How to change REPL mode on startup?

2016-05-15 Thread Rafael Fourquet
John, I tried your branch which works as expected, thank you. I found that there has been a PR at https://github.com/JuliaLang/julia/pull/13545 related to REPL hooks, not sure how much this overlaps with your solution. In any case, I hope to see this functionality merged.

Re: [julia-users] How to change REPL mode on startup?

2016-04-19 Thread Rafael Fourquet
> Again, I don't know if there is any demand for adding a general > facility for this. If you have in mind to make a PR, I would be a client for such a facility. IIUC, this would e.g. allow me to change automatically the prompt by calling a function from .juliarc.jl ? (which I do manually now with

Re: [julia-users] Newbie Question : Averaging neighbours for every element

2016-02-01 Thread Rafael Fourquet
This in-preparation blogpost may be relevant? https://github.com/JuliaLang/julialang.github.com/pull/324/files

Re: [julia-users] randperm run time is slow

2016-01-23 Thread Rafael Fourquet
The problem I think came essentially from the repeated creation of RangeGenerator objects, cf. https://github.com/JuliaLang/julia/pull/14772.

Re: [julia-users] randperm run time is slow

2016-01-22 Thread Rafael Fourquet
> Let's capture this as a Julia performance issue on github, > if we can't figure out an easy way to speed this up right away. I think I remember having identified a potentially sub-optimal implementation of this function few weeks back (perhaps no more than what Tim suggested) and had planned to

Re: [julia-users] Security problem with unitialized memory

2014-11-24 Thread Rafael Fourquet
Regarding Mauro's example: it is my understanding that your first example is that much faster mainly for cache reasons; indeed, the speed difference is less visible with the following two functions: f1(n) = (b = Array(Float64, n); fill!(b, 0.0)) f2(n) = (b = zeros(Float64, n); fill!(b, 0.0)) Then

Re: [julia-users] Make a Copy of an Immutable with Specific Fields Changed

2014-09-18 Thread Rafael Fourquet
I think the idiomatic way remains to be designed: https://github.com/JuliaLang/julia/issues/5333.

Re: [julia-users] Does Julia have something similar to Python's documentation string?

2014-09-15 Thread Rafael Fourquet
> > Docile.jl looks great, but I think that the API should be made into > comments. One of Julia's goals is to have a simple syntax that even people > who are not acquainted with programming can easily understand. > Python, despite using docstrings, is a great example of a language having "a simpl

Re: [julia-users] Copy a BigFloat?

2014-09-13 Thread Rafael Fourquet
BigFloats are indeed immutable "in spirit" but not really: julia> BigFloat.mutable == isimmutable(big(0.1)) true So copy is a no-op (returns its argument as for every number), and deepopy returns a new instance ("deepcopy(a) === a" is false), but then there is no public API to mutate a or its cop

Re: [julia-users] Does Julia have something similar to Python's documentation string?

2014-09-13 Thread Rafael Fourquet
> To me the only difference is that I `> really don't want to write > > @doc """ > commentary > """ > function ... > > > whereas I already write things along the lines of > > # commentary > function ... doc "function doc" function ... is already better, and then let's get rid of even the doc keyw

Re: [julia-users] Does Julia have something similar to Python's documentation string?

2014-09-11 Thread Rafael Fourquet
> Then one could use the existing Julia syntax for substituting values into > the documentation, like: > > # This is a comment. 1 + 2 = $(1 + 2) > I don't have a strong opinion on this topic, but I really don't understand why this is better than using directly: @doc "This is a doc string: 1 + 2 =

Re: [julia-users] why sum(abs(A)) is very slow

2014-08-23 Thread Rafael Fourquet
> > There's a complicated limit to when you want to fuse loops – at some point > multiple iterations becomes better than fused loops and it all depends on > how much and what kind of work you're doing. In general doing things lazily > does not cut down on allocation since you have to allocate the >

Re: [julia-users] why sum(abs(A)) is very slow

2014-08-22 Thread Rafael Fourquet
> Could you please explain why the iterator version is so much faster? Is > it simply from avoiding temporary array allocation? > That's what I understand, and maybe marginally because there is only one pass over the data.

Re: [julia-users] why sum(abs(A)) is very slow

2014-08-22 Thread Rafael Fourquet
> If that was the way things worked, would sum(abs(A)) do the computation > right away or just wait until you ask for the result? In other words, > should sum also be lazy if we're doing all vectorized computations that > way? > sum(abs(A)) returns a scalar, so lazy would buy nothing here (in mos

Re: [julia-users] why sum(abs(A)) is very slow

2014-08-22 Thread Rafael Fourquet
> > Obviously it would be even nicer not to have to do that :-) > My naive answer is then why not make vectorized functions lazy (like iabs above, plus dimensions information) by default? Do you have links to relevant discussions?

Re: [julia-users] why sum(abs(A)) is very slow

2014-08-22 Thread Rafael Fourquet
> > We'd like to eventually be able to do stream fusion to make the vectorized > version as efficient as the manually fused version, but for now there's a > performance gap. > It is also not too difficult to implement a fused version via iterators, eg : immutable iabs{X} x::X end Base.start(

Re: [julia-users] Re: We have typed functions, don't we?

2014-08-20 Thread Rafael Fourquet
> > 'Traditional' Julia: you can pass a function f as an argument to another > function g. > > Rafael's functors: instead you create new type F whose constructor is f, > and then you make g a parametric function with a parameter F instead of an > argument f. > A typo here, the constructor of type

Re: [julia-users] We have typed functions, don't we?

2014-08-19 Thread Rafael Fourquet
> > This is a really cool family of tricks. Time for me to start replacing some > ::Function specifiers in my argument lists... I saw in julia base that `Base.Callable`, an alias for Union(Function, DataType), is used in argument lists. I'm starting to consider replacing most normal functions by

Re: [julia-users] We have typed functions, don't we?

2014-08-18 Thread Rafael Fourquet
I'm glad to report that the general and beautifully functional solution sum( imap(sinc_plus_x, x)) is in fact as efficient as the "devectorized" hand-written one! It turns out I made the mistake to forget to forward an expression like "{Type{F}}" to the imap iterator constructor (cf. code below),

Re: [julia-users] We have typed functions, don't we?

2014-08-17 Thread Rafael Fourquet
> Love it! I get your point much better now. I'll be using it in the future > :). :) Yes I was probably a bit succint. > Re Iterators, yes, your guess is spot on---it's those pesky tuples (which > are > way better than they used to be, see > https://github.com/JuliaLang/julia/pull/4042). In hig

Re: [julia-users] Equivalent of c++ functor objects, std::bind, and lambdas

2014-08-15 Thread Rafael Fourquet
Ok thanks. I guess the heart of the question is overcoming Julia's builtin pass-by-reference behavior. I would be fine using an explicit copy function, but is there any way I can avoid defining a copy function for all my types, which would be annoying? OK, it seems that deepcopy corresponds bette

Re: [julia-users] Equivalent of c++ functor objects, std::bind, and lambdas

2014-08-15 Thread Rafael Fourquet
If the function "copy" is implemented for z: z = ... newfun = let zz = copy(z); (x, y) -> f(zz, x, y) end I think I understood that lambdas are less efficient than functions so this may be faster: let zz = copy(z) global newfun newfun(x, y) = f(zz, x, y) end

Re: [julia-users] We have typed functions, don't we?

2014-08-15 Thread Rafael Fourquet
> I've not used NumericFuctors so I can't comment on your main question. If > it's of any use, there's an entirely different approach (more of a dirty > trick, really) to inlining functions passed in as arguments. Here's a gist > that shows the trick: > https://gist.github.com/timholy/bdcee95f9b772

Re: [julia-users] We have typed functions, don't we?

2014-08-15 Thread Rafael Fourquet
> Hi Rafael, I recently posted an example of using function types, see: Thanks Adrian, but I couldn't see how it helps to make a function specialize on its (higher-order) function parameter (and possibly inline it).

Re: [julia-users] We have typed functions, don't we?

2014-08-15 Thread Rafael Fourquet
Oh, and by the way functions specialized on values can be emulated, e.g. type plusN{N} plusN(x) = x+N end plus{10}(1) And writing a constrained function can be slightly simpler than in my previous post: # constrained function: f{F<:BinaryFunctor}(::Type{F}, x) = F(x, x) f(plus, 1) Or, as a

[julia-users] We have typed functions, don't we?

2014-08-14 Thread Rafael Fourquet
Hi Julia users, As this is my first post, I must say I'm extremely impressed by julia, met 2 weeks ago. For many months I've meant to clean-up a C++/python lib of mine, for public consumption. I couldn't help but procrastinate, as the maintenance cost is so high a tax (eg. too clever hacks, big