[julia-users] Difference between {a b; c d} and Any[a b; c d]
Seems that Any[...] is not exactly equal to {...} in Julia 0.4. What is the best way to rewrite {a b;c d} ? julia> {1 [1,2];[1,2,3] 4} WARNING: deprecated syntax "{a b; c d}". Use "Any[a b; c d]" instead. 2x2 Array{Any,2}: 1 [1,2] [1,2,3] 4 julia> Any[1 [1,2];[1,2,3] 4] ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)") in cat_t at abstractarray.jl:850 in hcat at abstractarray.jl:875 in typed_hvcat at abstractarray.jl:1026
[julia-users] How to define function f(x::(Int...)) in Julia 0.4?
For example, in Julia 0.3, I can use below function definition: julia> f(::(Int...))="This is an Int tuple." julia> f((1,2)) "This is an Int tuple." julia> f((1,2,3)) "This is an Int tuple." How to define a function with unlimited tuple length in Julia 0.4?
[julia-users] X.2=X*0.2, easy to make mistake.
Today I spend many time to find a bug in my code. It is turn out that I mistakenly wrote sum(X,2) as sum(X.2). No any error information is reported and Julia regarded X.2 as X*0.2. The comma , is quite close to dot . in the keyboard and looks quite similar in some fonts. As there is no any error occur, this bug will be dangerous. Also, it is not intuitive to understand X.2 is X*0.2. I think maybe it is better to forbid syntax like X.2 but only allowed .2X.
[julia-users] Re: X.2=X*0.2, easy to make mistake.
Great, looking forward the next version!! My Julia is 0.3.9 so far. On Wednesday, June 17, 2015 at 3:14:24 PM UTC+2, Seth wrote: On Wednesday, June 17, 2015 at 8:04:11 AM UTC-5, Jerry Xiong wrote: Today I spend many time to find a bug in my code. It is turn out that I mistakenly wrote sum(X,2) as sum(X.2). No any error information is reported and Julia regarded X.2 as X*0.2. The comma , is quite close to dot . in the keyboard and looks quite similar in some fonts. As there is no any error occur, this bug will be dangerous. Also, it is not intuitive to understand X.2 is X*0.2. I think maybe it is better to forbid syntax like X.2 but only allowed .2X. This appears to be fixed in 0.4: julia x = 100 100 julia x.2 ERROR: syntax: extra token 0.2 after end of expression julia sum(x.2) ERROR: syntax: missing comma or ) in argument list julia f(x) = x.2 ERROR: syntax: extra token 0.2 after end of expression julia f(x) = sum(x.2) ERROR: syntax: missing comma or ) in argument list
Re: [julia-users] Re: How to call the original method that was overloaded?
Yes. I tried it, and it indeed went into an infinite recursion. On Sunday, April 26, 2015 at 10:06:57 AM UTC+2, Mauro wrote: Thank you! For this question, invoke indeed a good solution :) How about a more general case. For example, I already have a function foo foo(X::Int)=X+1 in the environment. Then I want to overload foo to forbid negative input: function foo(X::Int) @assert(X=0,X should be a positive number.) invoke(foo,(Int,),X)#Here, I hope to call the original definition of foo. end However, invoke doesn't work as I expected in this case. Is there any other solution? I don't think there is. There can only be one method for each signature for one generic function. So above gets you into an infinite recursion. On Sunday, April 26, 2015 at 8:40:06 AM UTC+2, Sam L wrote: See ?invoke. display(X::Vector)=length(X)10?print(Too long to show.): invoke(display, (Any,), X) On Saturday, April 25, 2015 at 10:41:39 PM UTC-7, Jerry Xiong wrote: For example, if I want to overload the Base.display(::Vector) to repress the display when the vector is too long, I coded as below: julia import Base.display julia display(X::Vector)=length(X)10?print(Too long to show.):Base. display(X) display (generic function with 17 methods) julia display([1,2,3]) ERROR: stack overflow in display at none:1 (repeats 39998 times) I want to call the original Base.display when the length of vector is less than 10, but it is became a dead recurring. Is there any way to do it?
[julia-users] Re: How to call the original method that was overloaded?
Thank you! For this question, invoke indeed a good solution :) How about a more general case. For example, I already have a function foo foo(X::Int)=X+1 in the environment. Then I want to overload foo to forbid negative input: function foo(X::Int) @assert(X=0,X should be a positive number.) invoke(foo,(Int,),X)#Here, I hope to call the original definition of foo. end However, invoke doesn't work as I expected in this case. Is there any other solution? On Sunday, April 26, 2015 at 8:40:06 AM UTC+2, Sam L wrote: See ?invoke. display(X::Vector)=length(X)10?print(Too long to show.): invoke(display, (Any,), X) On Saturday, April 25, 2015 at 10:41:39 PM UTC-7, Jerry Xiong wrote: For example, if I want to overload the Base.display(::Vector) to repress the display when the vector is too long, I coded as below: julia import Base.display julia display(X::Vector)=length(X)10?print(Too long to show.):Base. display(X) display (generic function with 17 methods) julia display([1,2,3]) ERROR: stack overflow in display at none:1 (repeats 39998 times) I want to call the original Base.display when the length of vector is less than 10, but it is became a dead recurring. Is there any way to do it?
Re: [julia-users] Re: How to call the original method that was overloaded?
I even tried below code, but it still went into an infinite recursion: foo2=copy(foo) function foo(X::Int) @assert(X=0,X should be a positive number.) foo2(X) end Since the copy or deepcopy can not really copy a function but still just be a reference of it. On Sunday, April 26, 2015 at 10:22:34 AM UTC+2, Jerry Xiong wrote: Yes. I tried it, and it indeed went into an infinite recursion. On Sunday, April 26, 2015 at 10:06:57 AM UTC+2, Mauro wrote: Thank you! For this question, invoke indeed a good solution :) How about a more general case. For example, I already have a function foo foo(X::Int)=X+1 in the environment. Then I want to overload foo to forbid negative input: function foo(X::Int) @assert(X=0,X should be a positive number.) invoke(foo,(Int,),X)#Here, I hope to call the original definition of foo. end However, invoke doesn't work as I expected in this case. Is there any other solution? I don't think there is. There can only be one method for each signature for one generic function. So above gets you into an infinite recursion. On Sunday, April 26, 2015 at 8:40:06 AM UTC+2, Sam L wrote: See ?invoke. display(X::Vector)=length(X)10?print(Too long to show.): invoke(display, (Any,), X) On Saturday, April 25, 2015 at 10:41:39 PM UTC-7, Jerry Xiong wrote: For example, if I want to overload the Base.display(::Vector) to repress the display when the vector is too long, I coded as below: julia import Base.display julia display(X::Vector)=length(X)10?print(Too long to show.):Base. display(X) display (generic function with 17 methods) julia display([1,2,3]) ERROR: stack overflow in display at none:1 (repeats 39998 times) I want to call the original Base.display when the length of vector is less than 10, but it is became a dead recurring. Is there any way to do it?
[julia-users] Re: Bioinformatics in Julia
Hi, I am a computational biologist and I do my majority of jobs using Julia right now. So far biojulia is not so practical but you can using BioPython package. It is quite convenient and painless to call python package so far. R packages are also necessary for bioinformatics. However, as I known, Julia haven't a good interface to connect with R at this moment. Therefore I wrote some custom code to wrap Rif.jl package in order to better calling R in Julia. What's ever, the reality is there is no any language even close to prefect for the biological data analysis. You could choice using Python+R, or using Julia plus python and R packages. Most people chose the first one for the tradition reason, but I prefer the latter one due to the incomparable characters of Julia language, even I have to pay some price for its immaturity at this moment. At least, I can do all the jobs using one language now, rather than always shifting between python and R. On Saturday, April 25, 2015 at 7:08:16 PM UTC+2, Tim K wrote: Dear All, I am finishing a bioengineering postdoc soon, and am looking to learn some bioinformatics. Accordingly, I was wondering what the status of bioinformatics tools for Julia is? (I would post in the biojulia-dev group, but it has not been updated since July 2014.) Cheers, Tim.
[julia-users] How to call the original method that was overloaded?
For example, if I want to overload the Base.display(::Vector) to repress the display when the vector is too long, I coded as below: julia import Base.display julia display(X::Vector)=length(X)10?print(Too long to show.):Base. display(X) display (generic function with 17 methods) julia display([1,2,3]) ERROR: stack overflow in display at none:1 (repeats 39998 times) I want to call the original Base.display when the length of vector is less than 10, but it is became a dead recurring. Is there any way to do it?
[julia-users] Why X.0 X.1 equal to X . (0 X) . 1 rather than (X.0) (X.1)?
I notice that the logical operations in Julia have a different precedence order from R and Matlab. and | have higher precedence than ., ., etc. For example, X.0 X.1 will be parse as X . (0 X) . 1 rather than (X.0) (X.1). I think there must be a reason for this anti-intuition design. I just curious what it is?
Re: [julia-users] Any plan to support dict$key as abbreviation of dict[key] ?
It is a good news to hear Jeff's plan :) So far ≀: could be a solution. I found ≀ have a rather high precedence. But...considering that it is not easy to type ≀ in other editor, I may still use [...]. Whatever, many thanks for the idea! On Wednesday, April 1, 2015 at 11:41:47 PM UTC+2, Jiahao Chen wrote: You can fake this syntax by using a supported Unicode operator https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm#L17-20, e.g. ≀ (which can be typed with \wrTAB): For example: x≀y = x[string(y)] x=Dict(foo=1, bar=2) x≀:foo+2 #3 In this case ≀: would pretend to be the operator you wanted. Thanks, Jiahao Chen Staff Research Scientist MIT Computer Science and Artificial Intelligence Laboratory On Wed, Apr 1, 2015 at 5:32 PM, Jerry Xiong xiong...@gmail.com javascript: wrote: I sometimes miss the concise way to fetch the element in a dictionary, such as dict$key in R and dict.key in Matlab. In Julia, I have to use dict[key] or dict[:key]. Although they are logically identical, the concise way has both typing and visual conveniences. I can regard dict.key1 and dict.key2 as two independent variables ( equal to dict_key1 and dict_key2) sometimes while regard them as fields of a structure othertimes. I tryed to overload macro @~ to do it, so I can use dict~key instead. However, the precedence of ~ is not high enough, such as dict~key+1 is equal to dict~(key+1) rather than (dict~key)+1. I wonder is there any plan to support such concise way of key fetching, or keep a high-precedence operator (e.g. dict§key, dict..key, dict!!key ) for custom macro defination in the future Julia?
[julia-users] Any plan to support dict$key as abbreviation of dict[key] ?
I sometimes miss the concise way to fetch the element in a dictionary, such as dict$key in R and dict.key in Matlab. In Julia, I have to use dict[key] or dict[:key]. Although they are logically identical, the concise way has both typing and visual conveniences. I can regard dict.key1 and dict.key2 as two independent variables ( equal to dict_key1 and dict_key2) sometimes while regard them as fields of a structure othertimes. I tryed to overload macro @~ to do it, so I can use dict~key instead. However, the precedence of ~ is not high enough, such as dict~key+1 is equal to dict~(key+1) rather than (dict~key)+1. I wonder is there any plan to support such concise way of key fetching, or keep a high-precedence operator (e.g. dict§key, dict..key, dict!!key ) for custom macro defination in the future Julia?
[julia-users] Re: Could it be a bug of PyCall or PyPlot?
Many thanks! On Monday, March 9, 2015 at 10:24:42 PM UTC+1, Steven G. Johnson wrote: On Monday, March 9, 2015 at 5:24:22 PM UTC-4, Steven G. Johnson wrote: On Monday, March 9, 2015 at 5:18:52 PM UTC-4, Steven G. Johnson wrote: Yes, I should probably define a pycall method for ColorMap. For now, you can do pycall(cmap2.o, PyAny, 0.5). Just fixed it in PyCall (master branch on github). I mean in PyPlot.
[julia-users] Re: Could it be a bug of PyCall or PyPlot?
My Julia version is : Julia Version 0.3.6 Commit 0c24dca* (2015-02-17 22:12 UTC) Platform Info: System: Linux (x86_64-redhat-linux) CPU: Intel(R) Xeon(R) CPU E7- 4830 @ 2.13GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem) LAPACK: libopenblas LIBM: libopenlibm LLVM: libLLVM-3.3
[julia-users] Could it be a bug of PyCall or PyPlot?
When I ran below codes: using PyCall @pyimport pylab as plb cmap1=plb.get_cmap(jet) pycall(cmap1,PyAny,0.5) Every thing goes fine, output result (0.4901960784313725,1.0,0.4775458570524984,1.0) However, after I loaded PyPlot: require(PyPlot) cmap2=plb.get_cmap(jet) pycall(cmap2,PyAny,0.5) A error is occured: ERROR: `pycall` has no method matching pycall(::ColorMap, ::Type{PyAny}, ::Float64) I found cmap1 is a PyObject, but cmap2 is another type called ColorMap. There is no any element named plb in PyPlot, so importing PyPlot should be independent from the previously imported module plb, therefore cmap1 should equal to cmap2. How could it happen?
[julia-users] Is string in Julia extendable?
Considering below code: str=abc str*=def Is the new string def just be appended after the memory space of abc, or both strings were copied to a new momory space? Is str*=def equal to str=str*def and str=$(str)def in speed and memory level? Is below code in O(n) or in O(n^2) speed? s= for i=1:1 s*=string(i) end
[julia-users] Is julia string extendable?
str=abc str*=def Is the new string def just be appended after the memory space of abc, or both strings were copied to a new momory space? Is str=str*def equal to str*=def in speed and memory level? Is below code O(n) or O(n^2)? s= for i=1:1 end
[julia-users] Re: Is string in Julia extendable?
Thanks a lot! I tested them on Julia 0.3.6: julia N=10; julia @time concat1(N); elapsed time: 37.870699284 seconds (23955546560 bytes allocated, 82.31% gc time) julia @time concat2(N); elapsed time: 0.016476456 seconds (9538836 bytes allocated) I also tried another way: julia function concat3(N) s=Char[] for i=1:N k=string(i) for j=1:length(k) push!(s,k[j]) end end string(s) end julia @time concat3(N); elapsed time: 0.147099074 seconds (23086132 bytes allocated, 40.51% gc time) Using IOString is the fastest way. On Thursday, February 26, 2015 at 4:32:27 PM UTC+1, David P. Sanders wrote: El jueves, 26 de febrero de 2015, 9:15:38 (UTC-6), Josh Langsfeld escribió: It's equivalent to str = str * def. I believe that's the case for all +=, *=, etc operators and all types. That's correct. So the original code is O(n^2). A good way to do this is using IOBuffer, as below. function concat1(N) s= for i=1:N s*=string(i) end s end function concat2(N) buf = IOBuffer() for i=1:N print(buf, string(i)) end takebuf_string(buf) end # Compile the functions and check they give the same output: N = 10 println(concat1(N)) println(concat2(N)) N = 1 @time concat1(N); @time concat2(N); With N = 10, concat2 is almost instantaneous, and I couldn't be bothered to wait for concat1 to finish. David. On Thursday, February 26, 2015 at 9:23:19 AM UTC-5, Jerry Xiong wrote: Considering below code: str=abc str*=def Is the new string def just be appended after the memory space of abc, or both strings were copied to a new momory space? Is str*=def equal to str=str*def and str=$(str)def in speed and memory level? Is below code in O(n) or in O(n^2) speed? s= for i=1:1 s*=string(i) end
Re: [julia-users] Re: Is string in Julia extendable?
Could you give a example code? On Thursday, February 26, 2015 at 5:53:51 PM UTC+1, Tim Holy wrote: There's also a RopeString type. --Tim On Thursday, February 26, 2015 07:32:27 AM David P. Sanders wrote: El jueves, 26 de febrero de 2015, 9:15:38 (UTC-6), Josh Langsfeld escribió: It's equivalent to str = str * def. I believe that's the case for all +=, *=, etc operators and all types. That's correct. So the original code is O(n^2). A good way to do this is using IOBuffer, as below. function concat1(N) s= for i=1:N s*=string(i) end s end function concat2(N) buf = IOBuffer() for i=1:N print(buf, string(i)) end takebuf_string(buf) end # Compile the functions and check they give the same output: N = 10 println(concat1(N)) println(concat2(N)) N = 1 @time concat1(N); @time concat2(N); With N = 10, concat2 is almost instantaneous, and I couldn't be bothered to wait for concat1 to finish. David. On Thursday, February 26, 2015 at 9:23:19 AM UTC-5, Jerry Xiong wrote: Considering below code: str=abc str*=def Is the new string def just be appended after the memory space of abc, or both strings were copied to a new momory space? Is str*=def equal to str=str*def and str=$(str)def in speed and memory level? Is below code in O(n) or in O(n^2) speed? s= for i=1:1 s*=string(i) end
[julia-users] Re: Calculate 95% confidential intervals of p in binomial distribution
Many thanks! We have two solutions now :) The BinomialTest Package seems cool, hope that it can be more powerful than, meanwhile as easy-understandable as, matlab statistics toolbox.
[julia-users] Calculate 95% confidential intervals of p in binomial distribution
I want to calculate the 95% confidential intervals of the parameter p of a binomial distribution, for a given x and n. I known that in MATLAT, it could be got in the 2nd output of binofit(x,n,0.95) Is there any way to do it in Julia, using Distributions.jl or any python package?