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
Typo, should be
module ...
ff(x::Type{Val{1}}) = 1
x = 1
a = ff(Val{x})
const y = 1
a = ff(Val{y})
end
>
>
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
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
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
> ...
>
>
>
Do we have a decomposition syntax or macro that simplifies this
a = x.a
b = x.b
c = x.c
...
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
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.
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.
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
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.
Thank you.
I used to use https://github.com/Mike43110/julia.vscode which unfortunately
doesn't provide the command for mark selection as comments.
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
Never mind, I get it.
On the third run, the `state` variable that `counter` modified is the one
from the second let block.
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() =
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
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
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
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
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
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
>
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
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?
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
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
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
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).
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++
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
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
(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
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)?
+ 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
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
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
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.
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
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
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.
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
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:
>
>
>
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),
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:
>>
>&
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.
44 matches
Mail list logo