Re: [julia-users] Cost of composite types / Help with an algorithm.

2015-03-08 Thread Mauro
Just use a 7x100 array? Otherwise, using an immutable instead of a type should be as efficient if it is a bits-type, i.e. isbits returns true. On Sun, 2015-03-08 at 19:52, Daniel Carrera wrote: > Hello everyone, > > I want to do n-body simulations with Julia. The number of particles is > small

Re: [julia-users] isa(eltype(X), T) versus iseltype(X, T)

2015-03-05 Thread Mauro
Consider julia> eltype(Array(Int,1))<:Integer true julia> isa(5, Number) true julia> isa(Int, Number) false julia> isa(Int, DataType) true isa tests whether something is an instance of a type. As Int is not an instance of Integer but a subtype isa(Int,Integer)==false. On Fri, 2015-03-06 at 0

Re: [julia-users] Re: convert composite type to a vector

2015-03-05 Thread Mauro
A bit more obfuscated (for immutable bittypes only): julia> immutable Foo{T} a::T b::T c::T end julia> x = Foo([1,2,3]...) Foo{Int64}(1,2,3) julia> reinterpret(Int, [x]) 3-element Array{Int64,1}: 1 2 3 On Thu, 2015-03-05 at 11:00, Simon Danisch wrote: >

Re: [julia-users] [code review] "atomic units" implementationf for AHN-algorithm.

2015-03-04 Thread Mauro
> I still don't have a clear picture of how to implement the other more > complex components: "compounds" and "mixtures". I'm experienced in Python > which leds me to think in terms inheritance for the concrete types, which > is the only part that is causing me troubles to grasp for now in Julia

Re: [julia-users] Re: General question about composite types

2015-03-03 Thread Mauro
hange it: > julia> x.x = 8.0 > 8.0 > > > # That change propagated to b: > julia> b > 2-element Array{B,1}: > B(8.0,5.0) > B(5.0,6.0) > > > On Tuesday, March 3, 2015 at 4:14:37 PM UTC-5, Mauro wrote: >> >> > If you're type has only concr

Re: [julia-users] Re: General question about composite types

2015-03-03 Thread Mauro
.0 5.0 6.0 julia> reinterpret(Float64,b) ERROR: cannot reinterpret Array of type B in reinterpret at array.jl:77 in reinterpret at array.jl:62 > On Tuesday, 3 March 2015 17:15:20 UTC, Mauro wrote: >> >> > Mauro, I do not quite understand what you're saying about densely

Re: [julia-users] Re: General question about composite types

2015-03-03 Thread Mauro
> Mauro, I do not quite understand what you're saying about densely packed > arrays, could you explain a bit more? Consider: julia> immutable A x::Float64 y::Float64 end julia> type B x::Float64 y::Float64 end julia> a = [A(4,5

Re: [julia-users] Re: General question about composite types

2015-03-03 Thread Mauro
> I believe if all your type fields are concrete (which they are in the case > of Float64), the performance should be the same as using Vector{Float64}. > This is really nice since you get to use code that is much more > understandable like state.x instead of state[1] for no penalty. I think to

Re: [julia-users] Making optional fields of unknown type more efficient

2015-02-24 Thread Mauro
Sorry my first sentence should have read: > Julia will *not* be able to produce specialised code for any non-concrete type > in your PhyNode. > It does not matter whether it's Any or some other > abstract/parameter-less type. At least that is how I read the docs: > http://docs.julialang.org/en/l

Re: [julia-users] Making optional fields of unknown type more efficient

2015-02-23 Thread Mauro
Julia will be able to produce specialised code for any non-concrete type in your PhyNode. It does not matter whether it's Any or some other abstract/parameter-less type. At least that is how I read the docs: http://docs.julialang.org/en/latest/manual/performance-tips/#type-declarations However,

Re: [julia-users] Re: Why does my Julia code run so slow?

2015-02-21 Thread Mauro
ll give you much if you were on the order of 100x slower to start >> with. >> >> -viral >> >> On Friday, February 20, 2015 at 8:19:50 PM UTC+5:30, Zhixuan Yang wrote: >>> >>> Mauro, Sean, and Tim, thanks for your help. >>> >>> Followi

Re: [julia-users] Question about type instability in simple function

2015-02-20 Thread Mauro
This might be something wrong in @code_warntype as @code_llvm and @code_native give the same output. On Fri, 2015-02-20 at 12:20, Kristoffer Carlsson wrote: > I had a type instability in my program and I condensed it down to this minimal > working example. > > Why is sqrt2 here unstable? The vari

Re: [julia-users] Why does my Julia code run so slow?

2015-02-19 Thread Mauro
Without having looked at your code too closely: Keyword arguments don't work that well. If I recall correctly, their type cannot be used inside the function body. How is performance if you don't use the keywords? (although they should not be impacting performance if not used in a particular cal

Re: [julia-users] working with immutable arrays

2015-02-18 Thread Mauro
That is an atrocious performance... Maybe one of the dirty tricks discussed in this thread could help: https://groups.google.com/d/msg/julia-users/A0DGzPVfiAI/0nYSjtC29eUJ Or, you could construct your type IM using a macro which would automatically also produce a @set_IM macro? On Wed, 2015-02-1

Re: [julia-users] working with immutable arrays

2015-02-18 Thread Mauro
There was this discussion: https://github.com/JuliaLang/julia/issues/3706 You could also use keyword constructors for the types. Although keyword functions are a performance bottleneck. Anyway, my solution to this problem was to use this function: @doc """ Make a new instance of a type with the

Re: [julia-users] why does findn for sparse matrices check for nzval != 0?

2015-02-12 Thread Mauro
There was some discussion about this in https://github.com/JuliaLang/julia/issues/9928 There are merits to both approaches: keeping zeros and purging them. On Fri, 2015-02-13 at 05:03, Zouhair Mahboubi wrote: > I'm trying to find the column indices of non-zero elements of a given row > in a sp

Re: [julia-users] can a julia script do multiple dispatch itself?

2015-02-12 Thread Mauro
You can get the signatures of the methods of the functions in your cell: for m in methods(sin) @show m.sig end Then figure out from there how to best call them. On Thu, 2015-02-12 at 06:12, Christian Peel wrote: > In Julia, if I have multiple functions with the same name but different >

Re: [julia-users] Local scope for function storage

2015-02-11 Thread Mauro
I can't quite tell: are you aware the `begin end` does not introduce a new scope? This (sans begin-end) produces 'long' local const aa = rand() test2() = aa::Float64 + aa::Float64 @code_native test2() and this short: const aa = rand() test2() = aa::Float64 + aa::Float64 @code_native test2() No

Re: [julia-users] Re: request for feature: modify field in immutable object in a container

2015-02-11 Thread Mauro
gt; mutate_immutable!(a,5) > c === a === 1 # true > > function mutate_immutable(x,y) ... end > On Tue, Feb 10, 2015 at 5:22 PM Mauro wrote: > >> @Stefan, thanks that was a good read. I liked the example. >> >> > The take away should be that you can't mutate an

Re: [julia-users] Quantitative Economics with Julia (great PDF doc)

2015-02-10 Thread Mauro
There is a HTML version too: http://quant-econ.net/jl/index.html On Wed, 2015-02-11 at 08:01, Arch Call wrote: > Quantitative Economics with Julia > > > Check out the PDF file in the link above. It has 396 pages of excellent > documentatio

Re: [julia-users] Re: request for feature: modify field in immutable object in a container

2015-02-10 Thread Mauro
c A(5) Which couldn't happen with an Int. > As Stefan just mentioned, we do need to add some mechanisms for more easily > creating them from existing ones. > On Tue, Feb 10, 2015 at 9:41 AM Mauro wrote: > >> Thanks Lex, Jameson and Michael for this interesting discuss

Re: [julia-users] Why do I get a no method exception for type parameters ?

2015-02-10 Thread Mauro
> Additionally it seems confusing that the new() method in in the constructor > does not call the zero parameter constructor, e.g. there is not constructor > chaining You can chain by calling the constructor again: immutable MT10{R<:Real} b::R c::R a::R MT10(b,c,a) = (@assert a

Re: [julia-users] Re: request for feature: modify field in immutable object in a container

2015-02-10 Thread Mauro
Thanks Lex, Jameson and Michael for this interesting discussion. I read it a few times but still cannot quite follow: Is the take-home that it is ok to mutate immutables? No repercussions from Julia itself, just confused library users? This is not what the manual suggests: http://docs.julialang

Re: [julia-users] Re: Locality of variables (loops)

2015-02-09 Thread Mauro
> numiters = 0 > for iter=1:maxiter >numiters = iter >update!(state) >check_termination(state) && break > end But that pattern would work just as well with the new scheme. What would not work anymore is the slightly shorter: iter = 0 for iter=1:maxiter update!(state) check_term

Re: [julia-users] Re: scope of variables when using "include"

2015-02-09 Thread Mauro
I think Jameson's solution would be best most of the time. Otherwise use a macro macro barfn() esc(quote function bar(y) return x + y end end) end function foo(value) x = value @barfn println(bar(10)) end On Mon, 2015-02-09 at 14:35, Chang Kw

Re: [julia-users] Re: request for feature: modify field in immutable object in a container

2015-02-09 Thread Mauro
So, this actually modifies an immutable, right? This doesn't seem right, aren't they supposed to be immutable? On Mon, 2015-02-09 at 14:29, Simon Danisch wrote: > You can actually modify immutables in an array directly. I actually > implemented this in GLAbstraction for my own usage. > I'm impl

Re: [julia-users] How to manipulate dimensions ?

2015-02-09 Thread Mauro
Use the ... julia> A = rand(4,5,6,7); B = rand(4,5,6); julia> C = zeros(eltype(A), size(A)[1:end-1]..., size(B)[2:end]...); On Mon, 2015-02-09 at 11:34, Yuuki Soho wrote: > I'm trying to do something very simple but I'm having no luck. > > I have to arrays A and B and I want to initialize an a

Re: [julia-users] request for feature: modify field in immutable object in a container

2015-02-08 Thread Mauro
Something along these lines is being implemented/discussed in https://github.com/JuliaLang/julia/pull/6122 https://github.com/JuliaLang/julia/issues/5333 Meanwhile, below function should work. Note that I did not write copyandmodify! as it makes a new instance and does not modify it in place. Wh

Re: [julia-users] Re: Locality of variables (loops)

2015-02-08 Thread Mauro
> Even more commonly, I want to know (and use) the value of the iteration > variable at the iteration that threw an error. Debugging errors in loops > would be more difficult without this ability. But that only works in the global scope in the REPL, right? So that is a pretty limited use, and

Re: [julia-users] Sundials set max. step size

2015-02-07 Thread Mauro
I used this to set another property, following their example (not the one with the simple interface): mem = Sundials.CVodeCreate(Sundials.CV_BDF, Sundials.CV_NEWTON) ... flag = Sundials.CVodeSetMaxNumSteps(mem, -1) ... I would think that adapting this to your case

Re: [julia-users] Re: Locality of variables (loops)

2015-02-07 Thread Mauro
> I would be ok with loop variables always being local to the loop so that > this would happen: > > julia> i = 0 > 0 > > julia> for i = 1:5 >println(i) >end > 1 > 2 > 3 > 4 > 5 > > julia> i > 0 > > > That would simplify the semantics of for loops at the cost of making it > harde

Re: [julia-users] Equivalent of Haskell's record wildcards?

2015-02-06 Thread Mauro
I agree there should be some standard way of doing this. Here were some discussions on how to pack/unpack parameters: https://groups.google.com/d/msg/julia-users/IQS2mT1ITwU/gEyj6JNJsuAJ https://groups.google.com/d/msg/julia-users/VOg7oew4rEM/YQrNoswKevgJ https://groups.google.com/d/msg/julia-user

Re: [julia-users] Anon functions and closures, is this the expect behavior?

2015-02-05 Thread Mauro
Yes, this is expected. Have a look at the scope section of the manual, it also has examples on how to get the behaviour (I suspect) you want. On Thu, 2015-02-05 at 16:26, Michael Francis wrote: > function test() > x = 2 > f = (()->x + 3) > println( f() ) # Prints 5 Yeh! > x = 4 >

Re: [julia-users] Back-converting IntSets to ints

2015-02-04 Thread Mauro
This is quite compact: julia> a=IntSet([1:10]) IntSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) julia> [a...] 10-element Array{Int64,1}: 1 2 3 4 5 6 7 8 9 10 Note that you can add a convert method for it yourself, which would work just as well as having one in Base. But of course maybe

Re: [julia-users] Save state in a function

2015-02-04 Thread Mauro
> I don't know why the word "functor" was originally used in Julia for > "function-like type", but it doesn't seem to have anything to do with the > functional programming / haskell / category theory functor (or any > particular relevance to monads). Might be a good idea to use a different > term s

Re: [julia-users] Allocate a Vector

2015-02-04 Thread Mauro
In 0.4, with call overloading, it would now be possible to have a constructor Vector(Int,5) (this is not possible in 0.3). You could submit a pull request to add that feature. On Wed, 2015-02-04 at 11:16, Kristoffer Carlsson wrote: > Ah, yes you are right about the Array{Int, 2} stuff. > > The r

Re: [julia-users] Re: [ANN] Differential Equation solver test suite

2015-02-04 Thread Mauro
ut all of this by rooting around in your > code, but I think it's going to be more efficient, if you have the time, to > simply ask for an explanation. No worries, you're welcome. Just ask if you got more questions. Mauro > Thanks a lot, > > Petr > > >

Re: [julia-users] Show method for types

2015-01-31 Thread Mauro
On Sat, 2015-01-31 at 04:53, i.costi...@me.com wrote: > I've got lots of multi-field types in a package I'm developing > and would like to > understand how I might best show() them optimally. The default method > applied to some types prin

Re: [julia-users] Re: [ANN] Differential Equation solver test suite

2015-01-30 Thread Mauro
This should include versions of the solver, IVPTestSuite and Julia. I could set up a ode-speed center, just like http://speed.julialang.org/ ;-) Glad you like it! M > Thanks again, > > Alex. > > On Friday, 30 January 2015 15:03:24 UTC+1, Mauro wrote: >> Hi all, >> &g

[julia-users] [ANN] Differential Equation solver test suite

2015-01-30 Thread Mauro
than DASSL, presumably because of its lower order. However, take those results with a grain of salt as I haven't spent too much time optimising yet. -- Mauro

Re: [julia-users] Adding Custom .jl through module calls

2015-01-27 Thread Mauro
alex.readcol() should work. Or alternatively export readcol from alex: modul Alex export readcol readcol() = 5 end The 'include' essentially just pasts the code of the file. That's why doing the include at the promt works, as then readcol is introduced into the top-level module (which is what y

Re: [julia-users] Writing Type-Stable Code in Julia - type stable version not that fast in 0.4

2015-01-26 Thread Mauro
This is a performance regression, also for 0.3.5. My timings for 0.3.5: julia> @time [sumofsins1(100_000) for i in 1:100]; elapsed time: 0.446675737 seconds (320109932 bytes allocated, 21.32% gc time) julia> @time [sumofsins2(100_000) for i in 1:100]; elapsed time: 0.115537618 seconds (896 byte

Re: [julia-users] Enums in Julia

2015-01-26 Thread Mauro
There is a FAQ entry on this which suggests not to use types each of elements of the enum (if I recall correctly). I recently did a enum like this: export nonstiff, mildlystiff, stiff abstract Enum immutable Stiff <: Enum val::Int function Stiff(i::Integer) @assert 0<=i<=2

Re: [julia-users] Re: Question about list of list; equivalent to Python's key paramater?

2015-01-26 Thread Mauro
This should work: help?> sort Base.sort(A, dim, [alg=,] [by=,] [lt=,] [rev=false]) Sort a multidimensional array "A" along the given dimension. julia> sort(Vector{Int}[[1,2], [1,2,3]], lt=(x,y)->(length(x)>length(y)) ) 2-element Array{Array{Int64,1},1}: [1,2,3] [1,2] Note, Josh's trick

Re: [julia-users] Re: Question on using sparse matrices

2015-01-25 Thread Mauro
After a warm-up I get this: julia> @time rand(200,100); elapsed time: 0.000471424 seconds (160160 bytes allocated) julia> @time sprand(200,100, 2500/100/201); elapsed time: 0.000616387 seconds (144984 bytes allocated) julia> 160160/144984 1.104673619157976 I think this means that your sparse ma

Re: [julia-users] convincing Julia that a function call (via a variable) has a stable return type

2015-01-20 Thread Mauro
Have a look at https://groups.google.com/d/msg/julia-dev/JEiH96ofclY/_amm9Cah6YAJ there are some hack-y solutions mentioned there. If I recall correctly, using a constructor instead of a function can solve the problem. On Tue, 2015-01-20 at 22:16, Keith Mason wrote: > I am trying to make use of

Re: [julia-users] Creating a type to store parameters in, and constructors with keyword arguments

2015-01-17 Thread Mauro
There is an issue for keyword constructors: https://github.com/JuliaLang/julia/issues/5333 and a related pull request: https://github.com/JuliaLang/julia/pull/6122 Anyway, it should be possible to make a macro for that but I'm not aware of an available one. Alternatively you can use a Dict. Also

Re: [julia-users] should I use types

2015-01-15 Thread Mauro
I don't think there is a simple tool. Have a look at https://software.intel.com/en-us/articles/vectorization-in-julia On Fri, 2015-01-16 at 06:03, tuguldu...@gmail.com wrote: > thanks a lot guys! > > just to clarify one thing, is there any tool where I can check whether if a > given type is SIMD

Re: [julia-users] Speed of Julia when a function is passed as an argument, and a different, but much faster coding.

2015-01-15 Thread Mauro
Have you read this recent thread and its examples? https://groups.google.com/d/msg/julia-dev/JEiH96ofclY/_amm9Cah6YAJ M On Thu, 2015-01-15 at 20:50, Petr Krysl wrote: > So the "call" syntax on a type works, but using the implementation > referenced above, it is SLOW. > > # Slow, function callba

Re: [julia-users] Speed of Julia when a function is passed as an argument, and a different, but much faster coding.

2015-01-15 Thread Mauro
> Is there an example of the use of this new syntax for 0.4? It's in the manual: http://docs.julialang.org/en/latest/stdlib/base/?highlight=call#Base.call http://docs.julialang.org/en/latest/manual/constructors/?highlight=call#constructors-call-and-conversion > Thanks, > > Petr > > On Sunday,

Re: [julia-users] Julia previous versions download

2015-01-15 Thread Mauro
Yep, it's hidden in the text. Maybe the link could be a bit more prominent? Maybe like so: https://github.com/JuliaLang/julialang.github.com/pull/195 On Thu, 2015-01-15 at 10:05, Elliot Saba wrote: > Ah, Mauro found them published! I didn't find that "old releases" pa

Re: [julia-users] Julia previous versions download

2015-01-15 Thread Mauro
I don't do stats but it looks like Rmath is still part of Julia, e.g.: https://github.com/JuliaLang/julia/issues/6131 but will be removed in the future. But I doubt that it will be kicked out without its functionality being replaced. Have you looked at https://github.com/JuliaStats ? Anyways, he

Re: [julia-users] Re: Later methods definition replaces the previous one?

2015-01-14 Thread Mauro
> and on other file maybe we can call the setx like: objC.setx(v) and this > would be a wrap to setx(objC, v). I know we can define a function into the > type ... but this probably will down the performance and will go to > different way for the multiple dispatch. > > PS:: again, s

Re: [julia-users] Re: Later methods definition replaces the previous one?

2015-01-13 Thread Mauro
> I would argue that this would be prohibited by the compiler as it could not > distinguish between > foo(x::Number) = 2 > and > foo(x::Float64) = 3 Yes it can: julia> foo(x::Number)=1 foo (generic function with 1 method) julia> foo(x::Float64)=2 foo (generic function with 2 methods) julia>

Re: [julia-users] Re: Later methods definition replaces the previous one?

2015-01-13 Thread Mauro
there > are no guarantees that the foo's are somehow related. They could still > implement entirely different (separate) concepts, which could both be > different from the concept that the original foo was designed to handle. > > P > > On Tuesday, January 13, 2015 at 1

Re: [julia-users] Re: Later methods definition replaces the previous one?

2015-01-13 Thread Mauro
>From a user point of view, if you mix and match very different packages, which may have or maybe will have name clashes in the future, you may want to consider to just import them and not 'using' them. And then fully qualify your functions. This is probably the prudent thing to do for larger cod

Re: [julia-users] Re: Later methods definition replaces the previous one?

2015-01-13 Thread Mauro
Is this problem not more related to issue https://github.com/JuliaLang/julia/issues/2327 ? The way it works is thus: If you make a method in a module, say module A export foo foo() = 1 end This will create a new generic function foo with one method in it. Now do the same in another module: mod

Re: [julia-users] How to define help text for a module function so that it displays in REPL

2015-01-09 Thread Mauro
A help/doc system is in place in 0.4 (unstable) which allows to do that (although no documentation about it yet...). It has not been backported to 0.3 (yet?). But I guess you could use Compat.jl and start documenting and have it all in place once 0.4 is released. On Fri, 2015-01-09 at 09:41, Ján

Re: [julia-users] Logical indexing with .≤ A bug?

2015-01-08 Thread Mauro
Looks like the parser does not bind the . to the ≤ julia> @which 5.≤a <=(x,y) at operators.jl:34 julia> @which 5.<=a .<=(A,B::AbstractArray{T,N}) at broadcast.jl:385 julia> @which 5≤a <=(x,y) at operators.jl:34 Can you check whether this has been filed and if not file an issue? On Thu, 2015-01

Re: [julia-users] Unexpected performance drop when passing functions

2015-01-07 Thread Mauro
The reason for the slowdown of case 4 is that Julia is not good at inferring the return types of functions passed as arguments to other functions. This shows up in a few places, for instance the `map` function has this problem too which I think has been partly hacked around. This is a bit of a bu

Re: [julia-users] warnings including module multiple times

2014-12-28 Thread Mauro
> Now the popular packages tend use include in a way that's fairly > harmless--i.e. to allow a lot of different symbols and functions to be > exported from a single module, without writing all the code in a single > giant file. But given that the good uses of include are pretty restricted, > I

Re: [julia-users] Multiple dispatch on values, not types

2014-12-26 Thread Mauro
How about making a type for your solver methods like so immutable Method{Name} para1::Int para2::Float64 ... end method_a = Method{:A}(p1, p2, ...) method_b = Method{:B}(p1, p2, ...) # Then the solve function could be function solve(data::DataFrame, method::Method{:A}) # comm

Re: [julia-users] Which licence to use for tutorial materials

2014-12-17 Thread Mauro
Wouldn't it be good if at least the code of tutorials is MIT licensed. That way it could be used in the mostly MIT licensed packages without hassle? On Wed, 2014-12-17 at 09:31, Stefan Karpinski wrote: > I'm not really sure. The Julia manual end up being MIT sort of by accident > just because it'

Re: [julia-users] Examples of integrating Fortran code in Julia

2014-12-16 Thread Mauro
I've posted the link to this blog post before, maybe it can help: http://maurow.bitbucket.org/notes/calling_fortran_from_misc.html On Tue, 2014-12-16 at 20:27, Isaiah Norton wrote: > With the following changes, your example works for me on mingw64: > > "-o" needs to be paired with a filename: > >

Re: [julia-users] Re: Article on finite element programming in Julia

2014-12-08 Thread Mauro
There was one talk about FEM at JuliaCon: https://www.youtube.com/watch?v=8wx6apk3xQs On Mon, 2014-12-08 at 04:48, Petr Krysl wrote: > Bit more optimization: > > Amuthan's code: 29 seconds > J FinEALE: 54 seconds > Matlab FinEALE: 810 seconds > > Petr > > > On Sunday, December 7, 2014 1:45:28 PM

Re: [julia-users] Inferring constructor parameters from parameters of arguments

2014-12-05 Thread Mauro
you have to provide an outer constructor as well when you define an inner one. This is a bit confusing, have a look at the manual & search the list. Here using your example using Arrays as I don't know Images: type TLPixel{T} data::T function TLPixel(img::Array{T}) new(img[1])

Re: [julia-users] removing function completely?

2014-11-30 Thread Mauro
> how do I delete just one dispatch binding then? You can't remove a method from a generic function. You can overwrite it though, for instance make it throw an error or point it to another method. > what is the equivalent of assigning "." or "undef" or "nothing" or > "Nothing" for removing just

Re: [julia-users] `methodswith` on `Union` types

2014-11-30 Thread Mauro
Yep, you should file an issue if one doesn't exist yet. On Sun, 2014-11-30 at 17:02, Ethan Anderes wrote: > I’m not sure if this is a bug or not but methodswith doesn’t seem to work > on Union types. > I came across this working with a linear fit in the GLM package > > using GLM, DataFrames > lm

Re: [julia-users] spzeros column vs row vector memory footprint

2014-11-30 Thread Mauro
In CSC sparse matrix format, each column will need a slot in colptr irrespective of whether it contains non-zeros or not. julia> spzeros(Float32, 1,4).colptr 5-element Array{Int64,1}: 1 1 1 1 1 julia> spzeros(Float32, 4,1).colptr 2-element Array{Int64,1}: 1 1 I think this is what makes th

Re: [julia-users] sortcols not working

2014-11-30 Thread Mauro
sortcols takes the whole colums and reorders them lexicographically (whereas sort(A,2) sorts each row separately). Thus sortcols will mostly sort according to the first row and only if entries are equal there will it take the next row into account. On Sun, 2014-11-30 at 08:49, Adriaan van Niekerk

Re: [julia-users] Efficient bytes to BitArray conversion

2014-11-29 Thread Mauro
are you looking for: help?> reinterpret Base.reinterpret(type, A) Change the type-interpretation of a block of memory. For example, "reinterpret(Float32, uint32(7))" interprets the 4 bytes corresponding to "uint32(7)" as a "Float32". For arrays, this constructs an array with the same

Re: [julia-users] Re: Julia and Microsoft Visual Studio

2014-11-28 Thread Mauro
Lighttable is now also MIT On Fri, 2014-11-28 at 14:28, Daniel Høegh wrote: > I think Julia would benefit from having a MIT licensed scientific IDE written > in Julia similar to the Spyder project in python. But in short term we maybe > could leverage the Spyder project, I have hacked a crude i

Re: [julia-users] Flexible construction of types

2014-11-26 Thread Mauro
> Thanks for your quick response! I have a couple questions/concerns about > your implementation: > > - MyType(1, [2, 3], "xyz") fails requirement #2 MyType{T1<:Real, T2<:Real}(x::T1, v::Vector{T2}, s::String) = (T=promote_type(T1,T2,Float64); MyType{T}(x, v, s)) If you want to keep Float16, et

Re: [julia-users] Flexible construction of types

2014-11-26 Thread Mauro
How about immutable MyType{T<:Real} x::T v::Vector{T} s::String function MyType(x, v, s) x = subtractpi(x) v = map(subtractpi, v) new(x, v, s) end end MyType{T1<:Real, T2<:Real}(x::T1, v::Vector{T2}, s::String) = (T=promote_type(T1,T2); MyType{T}(x, v,

Re: [julia-users] Overloading +=

2014-11-25 Thread Mauro
> Is it possible that + can be overloaded, but += cannot (but is derived from > +)? Yes, that is right. += is just sugar. There has been talk to make += stand on its own. > My context is this: > > I want to define some type, say `mytype` and allow the operation > A = mytype() > A[

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

2014-11-24 Thread Mauro
Pointer types will initialise to undef and any operation on them fails: julia> a = Array(ASCIIString, 5); julia> a[1] ERROR: access to undefined reference in getindex at array.jl:246 But you're right, for bits-types this is not an error an will just return whatever was there before. I think the

Re: [julia-users] impressions and questions from a Matlab user

2014-11-23 Thread Mauro
>> * At the matlab prompt, I can type 'str" then ctrl-P and it finds the >> most recent command in the history that starts with 'str' and puts it >> on my command line. I can then hit enter immediately and execute it. >> It appears that with the current Julia setup, one has to type ctrl-R >> to en

Re: [julia-users] Typeclass implementation

2014-11-21 Thread Mauro
-> a -> Bool, which would look like (a,a) --> Bool in the > proposed Julia function type syntax). The (/=) function has a default > implementation in terms of the (==) function, though you could define your > own for your own type if it were an instance of this typeclass. &g

Re: [julia-users] Typeclass implementation

2014-11-21 Thread Mauro
Sebastian, in Haskell, is there a way to get all functions which are constrained by one or several type classes? I.e. which functions are provided by a type-class? (as opposed to which functions need to be implemented to belong to a type-class) On Fri, 2014-11-21 at 16:54, Jiahao Chen wrote: >>

Re: [julia-users] Re: Simple Finite Difference Methods

2014-11-20 Thread Mauro
>> tutorials, I will make them available. >>Christoph >> >> >> On Thursday, 20 November 2014 19:29:34 UTC, Mauro wrote: >>> >>> The usual copyright issues apply here though: numgird and delsq are >>> copyrighted Matlab functions which you ar

Re: [julia-users] Re: Simple Finite Difference Methods

2014-11-20 Thread Mauro
The usual copyright issues apply here though: numgird and delsq are copyrighted Matlab functions which you are not allowed to copy and even less allowed post copied code. Best re-implement them without looking at the source code! Same goes for all of http://uk.mathworks.com/examples/matlab On Th

Re: [julia-users] Parameterized types with constraints on parameters

2014-11-19 Thread Mauro
> immutable Foo{T,M,N} # probably want an immutable here, so nobody swaps > # out the arrays behind your back. > x::Array{T,M} > y::Array{T,N} > function Foo(x,y) > @assert (M + 1) == N > new(x,y) > end > end > Foo{T, M, N}(x::Array{T,M}, y::Arr

Re: [julia-users] Parameterized types with constraints on parameters

2014-11-19 Thread Mauro
On Tue, 2014-11-18 at 22:06, David Smith wrote: > I would like to have a type such as this: > type foo{T,M,N} > x::Array{T,M} > y::Array{T,N} > end > > Where T and M can be anything, but N = M + 1. I know I can't write > > type foo{T,M} > x::Array{T,M} > y::Array{T,M+1} > e

Re: [julia-users] sum function return value type

2014-11-19 Thread Mauro
This is because Julia's type inference is not good in global scope and thus the list comprehension returns a Array{Any,1}. Wrap it in a function instead: julia> t = [1:2] 2-element Array{Int64,1}: 1 2 julia> s = [sum(t[1:i]) for i=1:length(t)] 2-element Array{Any,1}: 1 3 julia> zero(eltype(

Re: [julia-users] example for ccall use and fortran

2014-11-14 Thread Mauro
Maybe this can help too: http://maurow.bitbucket.org/notes/calling_fortran_from_misc.html By using bind(c) or iso_c_binding name mangling is turned off. On Fri, 2014-11-14 at 22:15, Luthaf wrote: > The first way to compile is the good one, but gfortran is slightly > changing the names of the fu

Re: [julia-users] Question on array behaviour

2014-11-14 Thread Mauro
On Fri, 2014-11-14 at 04:56, Amuthan A. Ramabathiran wrote: > Hello, > > I ran into this problem recently: > > julia> a = Array{Int,1}[] > 0-element Array{Array{Int64,1},1} > > julia> b = zeros(Int,2) > 2-element Array{Int64,1}: > 0 > 0 > > julia> b[1] = 1 > 1 > > julia> push!(a,b) > 1-elemen

Re: [julia-users] Questions. Abstract or composite with no fields

2014-11-11 Thread Mauro
Have a look at: http://docs.julialang.org/en/release-0.3/manual/types/ Abstract: - no instances - can be used as parents of other types type/immutable: - can create instances of them Both can be used for dispatch in functions. Best try it out. On Tue, 2014-11-11 at 17:13, Spencer Lyon wrote:

Re: [julia-users] Help optimizing sparse matrix code

2014-11-11 Thread Mauro
I didn't look at your code but it sounds like you are doing row wise operations. However, the sparse matrices in Julia (and in Matlab too, I think) are much faster at column-wise access: XX[:,i] is fast XX[i,:] is slow If you have to do both, then you can consider doing column-wise first then tr

Re: [julia-users] Re: -1^2

2014-10-23 Thread Mauro
Here are the operator precedence rules: http://docs.julialang.org/en/release-0.3/manual/mathematical-operations/?highlight=operators#operator-precedence so it's pretty clear that -1^2==-1 But for sure, it can be a bit confusing how the `-` is parsed: julia> -1*-1 1 is probably parsed as: julia

Re: [julia-users] Re: How can I get allocation information in Julia?

2014-10-22 Thread Mauro
This works for me: julia> function mindists_sq(pos, dists_min, Acp) for i in 1:size(pos, 2) dists_min[i] = Inf for j in 1:size(Acp, 2) t = 0.0 for k=1:size(pos,1) t += (pos[k, i]-Acp[k

Re: [julia-users] Re: catching an error in macro body

2014-10-22 Thread Mauro
I'm running into the problem in an example script, so Ivar's suggestion works perfectly. Mauro On Wed, 2014-10-22 at 12:11, Tim Holy wrote: > I frequently debug macros by writing them as functions that operate on > expressions, and then define the macro so it calls the fun

[julia-users] catching an error in macro body

2014-10-22 Thread Mauro
Is it possibly to catch an error happening during macro evaluation? Example: ``` macro a() error("error in marco itself") end macro b() :(error("error in marco generated code")) end # works: try @b end # still errors: try @a end ``` How to `try` the error in `@a`?

Re: [julia-users] Re: :(X<:Int) makes a :comparsion expression

2014-10-21 Thread Mauro
pressions, depending > on the context. Not sure what Jeff want to do, but it seems likely that we > ultimately would like to use the same expressions for the same syntactic > elements. > > Ivar > > > > kl. 12:54:43 UTC+2 tirsdag 21. oktober 2014 skrev Mauro følgende

Re: [julia-users] Re: :(X<:Int) makes a :comparsion expression

2014-10-21 Thread Mauro
s test > > I just get an AST error when trying to evaluate that expression, so it > can't be very usefull > > julia> eval(Expr(:<:, :Int64, :Int)) > ERROR: unsupported or misplaced expression <: > > We should probably consider erroring out when printing invalid exp

[julia-users] :(X<:Int) makes a :comparsion expression

2014-10-21 Thread Mauro
This seems a bit confusing: ``` julia> Expr(:<:, :X, :Int) :(X<:Int) julia> Expr(:<:, :X, :Int).head :<: julia> :(X<:Int) :(X <: Int) julia> :(X<:Int).head :comparison ``` Is this intentional? This also means that copy-pasting the string representation of `Expr(:<:, :X, :Int)` does not yield

Re: [julia-users] Re: is for iteration very expensive?

2014-10-20 Thread Mauro
e a look into Compressed Column Storage to understand what it does: https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_column_.28CSC_or_CCS.29 Generally if you have large and sparse matrices, then sparse-matrix formats are usually faster (but do profile). > On 2014年10月17日 15:03, Mauro w

Re: [julia-users] Selecting the right types

2014-10-17 Thread Mauro
>>> I am having some troubles understanding and selecting the right types. >>> >>> I have implemented an approximation of Lambert’s W function in two >>> versions: One for scalar input and one for array input. >>> >>> I’ve chosen the type Real for the scalar version and Array{Float64} for >>> th

Re: [julia-users] Re: is for iteration very expensive?

2014-10-17 Thread Mauro
The operation A[i] for a sparse matrix is quite a bit more expensive than for a dense array (where it is trivial). It first needs to convert [i] it to a [k,m] index and then look it up in the sparse matrix. See: https://github.com/JuliaLang/julia/blob/master/base/sparse/sparsematrix.jl#L841 How

Re: [julia-users] Modify immutable type inside function

2014-10-12 Thread Mauro
Here's the weapon to shoot yourself in the foot: ``` julia> immutable A a end julia> aa = A(5) A(5) julia> mutate!(a::A, val) = (global A; A.mutable = true; a.a=val; A.mutable = false; nothing) mutate! (generic function with 1 method) julia> mutate!(aa, 7) julia> aa A(7) ```

Re: [julia-users] Label vector components

2014-09-29 Thread Mauro
I haven't used it but I think DataFrames can do this http://juliastats.github.io/ On Mon, 2014-09-29 at 08:08, amik...@gmail.com wrote: > Dear all, > > I'm an absolute beginner in julia, I tried to read the relevant part of the > documentation but I'm still not quite sure how to solve my problem

<    1   2   3   4   5   6   7   8   >