[julia-users] Is the compiler able to give warnings that an iterator's internal state modified?

2016-11-18 Thread FANG Colin
I guess the following is buggy code dict = Dict(x=>x for x in 1:100); for x in keys(dict) delete!(dict, x) end As we need to `collect(keys(...))` to make a copy. However the code above still runs with correct results. Even when it fails to return correct results, no

Re: [julia-users] How to tell if Val{T} is using a fast route

2016-11-16 Thread FANG Colin
Typo, should be module ... ff(x::Type{Val{1}}) = 1 x = 1 a = ff(Val{x}) const y = 1 a = ff(Val{y}) end > >

[julia-users] How to tell if Val{T} is using a fast route

2016-11-16 Thread FANG Colin
In performance tips, it says Essentially, Val{T}works only when T is either hard-coded (Val{3}) or already specified in the type-domain. Suppose I have ff(::Type{Val{1}}) = 1 I guess the following is on a slower route. x = 1 a = ff(::Type{Val{x}}) And maybe this one can be determined in

Re: [julia-users] Good way to organize constants?

2016-11-16 Thread FANG Colin
Is there going to be overhead if I create constant group modules and use them via module_name.abc? On 16 November 2016 at 13:31, Milan Bouchet-Valat <nalimi...@club.fr> wrote: > Le mercredi 16 novembre 2016 à 04:18 -0800, FANG Colin a écrit : > > Say, I have a few constant

[julia-users] Re: Syntax sugar for composite type decomposition?

2016-11-16 Thread FANG Colin
Macro seems to have answered this in a different thread https://github.com/mauro3/Parameters.jl On Wednesday, November 16, 2016 at 1:01:32 PM UTC, FANG Colin wrote: > > Do we have a decomposition syntax or macro that simplifies this > > > a = x.a > b = x.b > c = x.c > ... > > >

[julia-users] Syntax sugar for composite type decomposition?

2016-11-16 Thread FANG Colin
Do we have a decomposition syntax or macro that simplifies this a = x.a b = x.b c = x.c ...

[julia-users] Good way to organize constants?

2016-11-16 Thread FANG Colin
Say, I have a few constants const VTYPE_BINARY = 'B' const VTYPE_INTEGER = 'I' const VTYPE_CONTINUOUS = 'C' What's a good way to have a namespace on it? So that I can use Vtype.BINARY, Vtype.INTEGER, Vtype.CONTINUOUS Should I put those in a separator module? or create a type and get an

[julia-users] Does Julia support Integer literal suffix like 1234L or 1234U

2016-10-22 Thread FANG Colin
Just wondering if Julia has any integer literal suffix support? So we don't have to write Int64(1234) or Int32(1234) in a long expression containing constants, but use 1234L or 1234S instead.

[julia-users] Re: canonical binary representation for Array

2016-10-13 Thread FANG Colin
Are you trying to serialise Julia objects? Why don't you try json or msgpack or so as your encoding? The default serialize could also work but you need to be careful it doesn't guarantee version safe.

Re: [julia-users] hashing floating point zeroes

2016-07-09 Thread FANG Colin
I would suggest replace `round(result, 10)` with `round(result, 10) + 0.0` On Saturday, July 9, 2016 at 1:34:43 PM UTC+1, Davide Lasagna wrote: > > Thanks, interesting point. > > In my specific use case -0.0 and 0.0 actually need to have the same hash, > as they represent conceptually the same

[julia-users] Re: Fun Fact: Julia is space sensitive (in some sense)

2016-07-05 Thread FANG Colin
Agree. It is very hard to spot the issue if it is combined with the bug that error message sometimes cannot get the line number right.

[julia-users] Re: VS code extension

2016-07-05 Thread FANG Colin
Thank you. I used to use https://github.com/Mike43110/julia.vscode which unfortunately doesn't provide the command for mark selection as comments.

[julia-users] Which way is preferred to define a closure?

2016-07-01 Thread FANG Colin
it seems there are 2 ways to define a closure. I am wondering why one is recommended. const myfun = let x = ... function f() do_something(x) end f end or let x = .. global myfun() function myfun() do_something(x) end end

[julia-users] Re: Another nested function scope issue

2016-07-01 Thread FANG Colin
Never mind, I get it. On the third run, the `state` variable that `counter` modified is the one from the second let block.

[julia-users] Another nested function scope issue

2016-07-01 Thread FANG Colin
I am wondering why the following happens: Julia 0.4.6 let state = 0 counter() = state += 1 counter() @show state end let state = 0 global counter counter() = state += 1 counter() @show state end let state = 0 global counter counter() =

[julia-users] good practice with dictionary pop!?

2016-06-06 Thread FANG Colin
I find myself often writing code like this when dealing pop! with a Dict{A, B} if !haskey(my_dict, key) do_something... end value = pop!(my_dict, key) do_something_else... The code above has an issue: it looks up the key in a dict twice unnecessary. I know I can opt for the

[julia-users] Why these 2 functions generate very different llvm?

2016-05-30 Thread FANG Colin
function t1(n::Int, x::Int, a::Float64) x::Float64 = x for i in 1:n x += a end x end @time t1(10^6, 1, 1.0) 0.005445 seconds (1.00 M allocations: 15.259 MB) function t2(n::Int, y::Int, a::Float64) x::Float64 = y for i in 1:n x += a end x end @time

Re: [julia-users] Change of immutable memory layout in julia v0.5?

2016-05-21 Thread FANG Colin
he versioninfo for v0.5 in my case is Julia Version 0.5.0-dev+3305 Commit c45175f (2016-03-29 03:51 UTC) It seems to be a bit earlier than your commit. On Sunday, May 22, 2016 at 1:26:28 AM UTC+1, Yichao Yu wrote: > > On Sat, May 21, 2016 at 7:04 PM, FANG Colin <coli...@gmail.com

[julia-users] Change of immutable memory layout in julia v0.5?

2016-05-21 Thread FANG Colin
immutable MyType x::AbstractString y::Int end @time for i in 1:10^5 MyType("a", 1).y end In julia v0.4 0.000813 seconds (100.00 k allocations: 3.052 MB) In julia v0.5 0.03 seconds (5 allocations: 176 bytes) It seems the memory layout for immutable which contains fields

Re: [julia-users] Re: Is there a function/macro that shows the line number where it is called?

2016-05-10 Thread FANG Colin
Thank you! On Tuesday, May 10, 2016 at 3:20:48 PM UTC+1, Isaiah wrote: > > Use `@__LINE__` and `@__FILE__`. > > (note, however, `@__LINE__` does not work when used within another macro, > see https://github.com/JuliaLang/julia/issues/9577) > > On Tue, May 10, 2016 at 6:25

[julia-users] Re: Is there a function/macro that shows the line number where it is called?

2016-05-10 Thread FANG Colin
markup(1) end compile time OK: #1 to_debug() run time OK: #1 On Tuesday, May 10, 2016 at 11:16:20 AM UTC+1, FANG Colin wrote: > > I am debugging some code. > > I would like to insert some markup function/macro in my code, so that I > know my code at least works fine until certain line number >

[julia-users] Is there a function/macro that shows the line number where it is called?

2016-05-10 Thread FANG Colin
I am debugging some code. I would like to insert some markup function/macro in my code, so that I know my code at least works fine until certain line number

[julia-users] what's good practice for default value in optional arguments?

2016-05-05 Thread FANG Colin
For example, function f(x::Int; y::Union{Void, Dict}) z = y == nothing ? Dict() : y ... end Or function f(x::Int; y::Dict=Dict()) ... end Which one should I use?

Re: [julia-users] What is Task switch not allowed from inside gc finalizer?

2016-04-12 Thread FANG Colin
What's the easiest way to print the object in finalizer? On 12 April 2016 at 14:16, Yichao Yu <yyc1...@gmail.com> wrote: > On Tue, Apr 12, 2016 at 8:15 AM, FANG Colin <colinf...@gmail.com> wrote: > > type C > >x::Symbol > > > >fu

[julia-users] Re: scoping wat

2016-04-12 Thread FANG Colin
I think the complicated scoping rules are inevitable in Julia as it is a dynamic language. Every layer of flexibility in the language comes with a cost. static languages normally have simple scoping rules (And IDE can help a lot with static analysis). Functional languages have even simpler

Re: [julia-users] scoping wat

2016-04-12 Thread FANG Colin
Python has similar rules. x = 10 def foo(): print x x = 5 print x foo() UnboundLocalError: local variable 'x' referenced before assignment On Tuesday, April 12, 2016 at 1:52:23 PM UTC+1, Didier Verna wrote: > > Mauro wrote: > > > Maybe you can be a bit

[julia-users] What is Task switch not allowed from inside gc finalizer?

2016-04-12 Thread FANG Colin
type C x::Symbol function C(x::Symbol) c = new(x) finalizer(c, c->println(1, c, 2)) c end end a = C(:x) a = 1 gc() error in running finalizer: ErrorException("task switch not allowed from inside gc finalizer") However, it works if I manually call finalizer(a).

[julia-users] Re: What version of libstdc++6 does libjulia.so use?

2016-04-11 Thread FANG Colin
I am writing a library in Python that needs to import julia. If I do the "load julia's libstdc++ first" trick, it means all users of my library have to do the same. Are there any alternative solutions? On Monday, April 11, 2016 at 1:07:43 PM UTC+1, Tony Kelman wrote: > > Load Julia's libstdc++

[julia-users] What version of libstdc++6 does libjulia.so use?

2016-04-11 Thread FANG Colin
I installed julia via the official linux generic binaries. And I managed to call julia from python. However, because libjulia.so links to its own libstdc++.so.6, if I import other libraries which need system libstdc++.so in python before julia, I would end up with missing symbol when link

Re: [julia-users] constructor & function have different promotion rules?

2016-04-05 Thread FANG Colin
Tuesday, April 5, 2016 at 10:19:05 AM UTC-4, FANG Colin wrote: >> >> methods(TT) >> >> call(::Type{TT}, x::Float64, y::Float64) at In[22]:2 >> call(::Type{TT}, x, y) at In[22]:2 >> call{T}(::Type{T}, arg) at essentials.jl:56 >> call{T}(::Type{T}, a

Re: [julia-users] constructor & function have different promotion rules?

2016-04-05 Thread FANG Colin
(Float64, x) & convert(Float64, y)? I.e does it always try to convert each argument to the type of the field defined in the type? On 5 April 2016 at 15:11, Yichao Yu <yyc1...@gmail.com> wrote: > On Tue, Apr 5, 2016 at 10:09 AM, FANG Colin <colinf...@gmail.com> wrote: > &g

[julia-users] constructor & function have different promotion rules?

2016-04-05 Thread FANG Colin
Sorry if this has been discussed somewhere as I am unable to find the relative post. immutable TT x::Float64 y::Float64 end function tt(x::Float64, y::Float64) x + y end tt(1,2) # doesn't work TT(1,2) # works What rule applies here for TT(1,2)?

[julia-users] Re: Julia is a great idea, but it disqualifies itself for a big portion of its potential consumers

2016-04-05 Thread FANG Colin
+ 1 to Gabriel's reply. On Tuesday, April 5, 2016 at 2:36:09 PM UTC+1, Gabriel Gellner wrote: > > you can do the python example as: > > a[[1, 4] + range(7, 17, 2)] > (ignoring the issues that this is not the same range as julia since python > uses 0-based indices ...) > > you don't need to index

[julia-users] Re: Is there a performance penalty for defining functions inside functions?

2016-03-30 Thread FANG Colin
What about include in a function? function mainFunc() include("helper.jl") call helper() and do stuff return something end inside helper.jl function helper() do stuff return something end On Wednesday, March 30, 2016 at 1:26:22 PM UTC+1, Christopher

[julia-users] Nothing conditional operator

2016-03-15 Thread FANG Colin
Hi All I found my self writing code like this a lot: x = get_a(...) if x != nothing y::A = x do_sth(y, ...) end In the above, I have to check for nothing first, and if it is not nothing, then I do a type assert to make sure the type is what I expected. Is there any function or macro

[julia-users] Re: Abstract typed array construction JIT performance

2016-03-03 Thread FANG Colin
All right that makes sense. On Thursday, March 3, 2016 at 1:50:09 PM UTC, Lutfullah Tomak wrote: > > Hi Colin, > I think if getindex inlined in vect it is not compiled seperately for your > second run. Check code generated with @code_* for youreself.

[julia-users] is Union type a preferred way in Julia?

2016-02-23 Thread FANG Colin
I know in F# people encourage Discriminated Unions, what about in Julia? I would like to do the following: immutable B end immutable C end typealias A Union{B,C} function A(x::Int) if x > 0 B() else C() end end But it doesn't work because I cannot add a constructor

[julia-users] Re: immutability, value types and reference types?

2016-01-21 Thread FANG Colin
My guess purely: I thought if a immutable type is big enough, it was implemented as a reference type. (Otherwise each time when it is passed to a function, a lot of memory copy is performed). immutable Big a1::Int a2::Int ... a1000::Int end On Thursday, January 21, 2016 at

[julia-users] Symbol & Expr

2015-11-04 Thread FANG Colin
Hi all I have got 2 questions: 1. I have a list, e.g. [:a, :(a + 1)], and I am not sure that type I should give to it. There are 3 possible solutions I can think of. A. Do we have something that can convert a Symbol to an Expr? B. Or, should I assign the list to be Union{Symbol, Expr}? C.

[julia-users] Re: typealias vs. const

2015-10-30 Thread FANG Colin
I have got the same confusion. Any ideas? I have even seen usage of A = T (no const) (http://docs.julialang.org/en/release-0.4/manual/types/#type-unions), is it supposed to be bad (slow) because it is a global variable? On Thursday, November 6, 2014 at 3:38:41 PM UTC, Steven G. Johnson

Re: [julia-users] Re: in place version of .* and .+ for matrix piecewise operation?

2015-10-28 Thread FANG Colin
Thanks for the tip, just about time I try out @devec. Right I forgot that I can make use of blas manually! On 28 October 2015 at 14:25, STAR0SS wrote: > You can try axpy! for the addition case, might be faster: > > >

[julia-users] in place version of .* and .+ for matrix piecewise operation?

2015-10-28 Thread FANG Colin
Hi all I am wondering if there exist the in place version of .* and .+, for matrix piecewise operation, so that it reduces memory allocation? Or is there a plan to add them? For the moment, (.*)(A::SparseMatrixCSC, B::Number) = SparseMatrixCSC(A.m, A.n, copy(A.colptr), copy(A.rowval),

[julia-users] Re: For loop = or in?

2015-10-27 Thread FANG Colin
es (i in mylist). But using 'in' for everything is > ok too. > > The '=' is there for familiarity with matlab. Remember that julia's syntax > was in part designed to be familiar to matlab users. > > On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote: >> >&

[julia-users] For loop = or in?

2015-10-26 Thread FANG Colin
Hi All I have got a stupid question: Are there any difference in "for i in 1:5" and "for i = 1:5"? Does the julia community prefer one to the other? I see use of both in the documentations and source code. Personally I haven't seen much use of "for i = 1:5" in other languages. Thanks.