Re: [julia-users] Question: Forcing readtable to create string type on import

2016-11-03 Thread Michael Borregaard
The result of CSV should be a DataFrame by default.  What return type do 
you get?


[julia-users] Re: Cost of @view and reshape

2016-10-30 Thread Michael Borregaard

You can reshape the view. This should be cheap.


Re: [julia-users] Re: so many plotting packages

2016-10-29 Thread Michael Borregaard
Independent approaches and a large number of largely experimental packages 
is the nature of open source development, yes, and may provide lots of 
creative new solutions. But to keep a technical language useful and 
attractive I think it is a very big advantage if there are defined 
standards, and that people generally favour collaboration over competition 
in development. This was discussed in the "Tower of Babel 
"
 
thread, which may be what Ben Arthur is referring to? I don't see how that 
would be achieved by putting them in the same organisation, what is 
required is coordination and agreement to contribute to a shared standard 
project.

I can understand if the julia maintainers would require a standard plotting 
package to be 1) written in Julia and 2) maintained by the larger 
community. Right now Gadfly fits that bill - the trouble is just that a lot 
of people (including myself) prefer Plots, which is neither 'pure' julia 
nor really a community effort, but IMHO a lot more user friendly. (Note 
though that it is not backend agnostic - it offers a handful of backends, 
but not others (e.g. Gadfly, Winston etc)). Plots also has the advantage 
that package developers can offer plotting functionality with Plots without 
having their package depend on it, which is a potential game changer.

I think it can be said that this is still very much in development, and my 
hope is that over time a standard will emerge that fits users, the core 
team and package developers alike. I definitely follow this with great 
interest.


[julia-users] Re: Which data structure do you suggest for handling this data?

2016-10-26 Thread Michael Borregaard
That depends a lot on what analyses you want to do with it afterwards - you 
could have an array (of species) of an array (of points) of tuples (the x 
and y), which is the most straigthforward thing. 

For must uses I would probably use a sparse Boolean matrix, e.g.
visits = [sparse([1,4,8], [3,5,9], true), sparse([4,2],[3,5], true)]




Re: [julia-users] Re: Julia and the Tower of Babel

2016-10-09 Thread Michael Borregaard

Great to see this brought up here, and to read the constructive and 
thought-provoking responses from members of the Julia community. I feel 
this is highly important and I have thougt a lot about it recently, as I am 
writing an invited guest editorial for a leading ecological journal about 
how transferring to julia as the lingua franca for ecological scientists 
may affect the way we do science and work together.

I come to this from a somewhat different angle, as the ecological community 
is almost 100% wedded to R – the use of R has practically exploded within 
the last 5 years alone. So when I came to julia I was struck by how 
structured the package ecosystem appears to be, yet, in spite of the 
micropackaging. This seems to me to be a huge advantage for collaboration, 
creativity and methods development, and IMHO this will in the end be a 
stronger argument for our community to make the transition than the speed 
of computation.

I think there are a number of reasons for this difference, but I also 
believe that a primary reason is the reliance on github for developing the 
package ecosystem from the bottom up, and the use of organizations. These 
organisations, like JuliaGeo, BioJulia etc in effect act like standard 
package distributions, both by facilitating communication within, but also 
by imposing a set of strict guidelines on code compatibility. Centrally, 
the organisations are really visible centers for where development in a 
given field takes place, and thus the culture encourages developers to 
contribute to existing packages and organisations rather than inventing new 
packages. In R that is not the case - instead most scientific packages are 
one-lab projects developed to serve a certain research program. 

I do hope that this can continue in the future, but one might worry: right 
now most julia developers are driven by a desire to help build the language 
itself, but when it grows over a certain size and becomes established this 
is sure to become less pronounced. Also, the current practice of software 
papers in scientific journals means that researchers get credit for 
developing new packages, but none for contributing to existing packages. 
This directly counteracts the best interests of the community.

It is a new situation to have a scientific language that is built openly 
and communally, yet with such a high degree of integration and 
communication. The solution must be culture, as written by Stefan and Tom, 
specifically to develop the community culture to keep communicating, 
discussing and agreeing upon standards. Also, for instance, organizations 
like the biojulia community are very good at identifying new ad-hoc 
packages coming out that relate to their work, and invite developers to 
join the communal effort and build the foundation of Julia in their field 
instead of creating lots of partial alternatives. I think this is key.

But perhaps this could be strengthened by being more explicit about 
building modular 'standard libraries', like in the respective 
organizations, but perhaps also for base (or statistics/numerical analysis, 
at least) that impose strict internal guidelines for conformance? These 
organizations, of course, would need mechanisms for ensuring renewal within 
the basic ideoms, so development does not die.

I for one will follow this development with keen interest.


Re: [julia-users] Is there a way to use values in a DataFrame directly in computation?

2016-10-05 Thread Michael Borregaard

This is good news, and I am holding my breath for this to be succesful! As 
someone from a data-rich science (Ecology), a really good way of 
interacting directly with data is the make-or-break for whether I will be 
able to persuade my colleagues to make the shift to julia.


[julia-users] Re: Maps in Julia?

2016-09-22 Thread Michael Borregaard

Yeesian, this looks really promising! It will be great to follow the 
progress of this.


[julia-users] julia installation broken

2016-09-16 Thread Michael Borregaard
Hi, Is this the right forum for troubleshooting / issues with my julia 
install?

I have kept having problems with packages giving error on precompile, 
rendering julia unusable. I then reinstalled julia-0.5-rc4, and removed my 
.julia folder from my home dir to do a fresh install. Now, Julia fails with 
an error message when I do Pkg.update():

julia> Pkg.update()
INFO: Initializing package repository /Users/michael/.julia/v0.5
INFO: Cloning METADATA from https://github.com/JuliaLang/METADATA.jl
ERROR: SystemError (with /Users/michael/.julia/v0.5/METADATA): rmdir: 
Directory not empty
 in #systemerror#51 at ./error.jl:34 [inlined]
 in (::Base.#kw##systemerror)(::Array{Any,1}, ::Base.#systemerror, 
::Symbol, ::Bool) at ./:0
 in #rm#7(::Bool, ::Bool, ::Function, ::String) at ./file.jl:125
 in #rm#7(::Bool, ::Bool, ::Function, ::String) at 
/Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in (::Base.Filesystem.#kw##rm)(::Array{Any,1}, ::Base.Filesystem.#rm, 
::String) at ./:0
 in init(::String, ::String) at ./pkg/dir.jl:62
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, 
::Vararg{Any,N}) at ./pkg/dir.jl:28
 in update() at ./pkg/pkg.jl:210

I assums that a completely clean install should work. Are there keys to 
delete etc that will give me a properly clean install? I am on Mac OS X 
(newest version).
Thanks!


Re: [julia-users] code design question – best ideomatic way to define nested types?

2016-09-13 Thread Michael Borregaard
Thanks for the enlightening discussion. The emerging consensus is to use 
example #2, but perhaps use macros to make the syntax easier to read and 
maintain. Alternatively, it looks like my idea with having a FoobarData 
object as a field would do the job (but would require 
foobar.foobardata.bazbaz syntax for accessing fields, of course).

It is also interesting to see that there are divergent views. It seems to 
me, for example, that Tom Breloff's macro syntax would subvert the 
inheritance design decision that Stefan Karpinski described, by combining 
the abstract type with the concrete type?


[julia-users] Re: Workflow question - reloading modules

2016-09-13 Thread Michael Borregaard
Maybe this is useful: 
https://github.com/JunoLab/atom-julia-client/blob/master/manual/workflow.md


[julia-users] Re: Slow Performance Compared to MATLAB

2016-09-13 Thread Michael Borregaard
That is a pretty massive script to ask people to look at for performance 
:-) Try profiling it and identify the most expensive code and post that, 
that will be much easier to give feedback on.


Re: [julia-users] code design question – best ideomatic way to define nested types?

2016-09-12 Thread Michael Borregaard
Thanks for the prompt response, I will go with that then :-) 

I actually thought later that I may avoid some of the clutter in approach 2 
by adding another level of indirection:

abstract AbstractFoo

type FooData
  bar
  baz
  #... several other fields
end

type FoobarData
  barbaz
  bazbaz
  #... several other fields

type Foo <: AbstractFoo
  foodata::FooData

  Foo(bar, baz) = new(FooData(bar, baz))
end

type Foobar <: AbstractFoo
  foodata::FooData
  foobardata::FoobarData

  Foobar(bar, baz, barbaz, bazbaz) = new(FooData(bar, baz), 
FooBarData(barbaz, bazbaz))
end

However I cannot say whether this is generally useful outside my use case.



[julia-users] code design question – best ideomatic way to define nested types?

2016-09-12 Thread Michael Borregaard
Hi,

I am defining a set of types to hold scientific data, and trying to get the 
best out of Julia's type system. The types in my example are 'nested' in 
the sense that each type will hold progressively more information and thus 
allow the user to do progressively more. Like this:

type Foo
  bar
  baz
end

type Foobar
  bar  # this
  baz  # and this are identical with Foo
  barbaz
  bazbaz
end


Thus, you can do anything with a Foobar object that you can with a Foo 
object, but not the other way around. The real example is much more 
complex, of course, with levels of nestedness and more fields of complex 
types.
There are several ways I could design this:

   1. I could make all objects be of type Foobar, but make the barbaz and 
   bazbaz fields Nullable. I don't think that is ideal, as I would like to use 
   dispatch to do things with object Foobar that I cannot do with Foo, instead 
   of constantly checking for isnull on specific fields.
   2. I could keep the above design, then define an abstract type 
   AbstractFoo and make both Foo and Foobar inherit from this. Then 
   AbstractFoo can be used to define functions for everything that can be done 
   with the fields that are in Foo objects. The downside is that the types 
   become really big and clunky, and especially that my constructors become 
   big and tricky to write.
   3. I could use composition to let Foobar contain a Foo object. But then 
   I will have to manually dispatch every method defined for Foo to the Foo 
   field of Foobar objects.To make it clear what I mean, here are the three 
   designs:

# Example 1:

type Foobar{T<:Any}
  bar
  baz
  barbaz::Nullable{T}
  bazbaz::Nullable{T}
end


# Example 2:

abstract AbstractFoo


type Foo <: AbstractFoo
  bar
  baz
end

type Foobar <: AbstractFoo
  bar
  baz
  barbaz
  bazbaz
end


# Example 3:

type Foo
  bar
  baz
end

type Foobar
  foo::Foo
  barbaz
  bazbaz
end

I do realize that the easy answer to this is "this depends on your use 
case, there are pros and cons for each method". However, I believe there 
must be a general ideomatic solution, as this issue arises from the design 
of the type system: because you cannot inherit from concrete types in 
Julia, and abstract types (which you can inherit from) cannot have fields. 
In C++, where you can inherit from concrete types, this would have an 
ideomatic solution as:


class Foo{
  protected:
int bar, baz;
};

class Foobar: public Foo{
  int barbaz, bazbaz;
};


I have been struggling for days with different redesigns of my code and I 
really cannot wrap my head around it. I appreciate the help!


[julia-users] Re: Maps in Julia?

2016-09-09 Thread Michael Borregaard
You can open esri shapefiles with shapefiles.jl. There is a plotting function 
for shapefiles in plotrecipes.jl. You can layer shapefiles to create vector 
maps. I am happy to help out if you want to use this.

Re: [julia-users] Re: How to shuffle the order of matrix by rows

2016-09-08 Thread Michael Borregaard
I would just

using StatsBase

function shufflerows(a::AbstractMatrix)
n = size(a, 1)
ord = sample(1:n, n, replace = false)
a[ord,:]
end

a = rand(5,5)
shufflerows(a)




Re: [julia-users] "Namespaces" for accessing fields of composite types

2016-09-05 Thread Michael Borregaard
> For a toy example like this, this is reasonable advice.

I know you were not after advice, but wanted to suggest a design change to 
Julia. I thought Yichao Yu gave a nice response to that, and I am looking 
forward to see the developments he promises. I just thought I would point 
out an ideomatic julian way of acheiving what it it is you want. 
Generally, of course, I can do no better than proposing a suggestion to 
solving the example you give. If your use case is different or more 
encompassing, you could try to describe it and I am sure the mailing list 
can give you some nice advice.

I don't see the issue with typos and copy-pasting. In your example, the 
normal approach would be to define a type CatData with all the fields and 
variables you feel a Cat needs, and then design all cats to contain this 
object. 


Re: [julia-users] "Namespaces" for accessing fields of composite types

2016-09-01 Thread Michael Borregaard
To do something like this in Julia, there are several possibilities, 
depending what you want to achieve. You could

abstract Cat # we decide hat cat will always have an age variable

type Tiger <: Cat
  age::Int
end

meow(c::Cat) = println(c.age)

# then you can
tigre = Tiger(5)
meow(tigre)




[julia-users] Re: JupyterLab

2016-08-23 Thread Michael Borregaard
They have updated to 0.2. It works fine for me, I just had to get used to 
that to start a julia notebook, I have to first open a new Notebook that 
opens with the Python2 kernel, and the 'switch kernel'.


[julia-users] Re: When can the broadcast dot (in 0.5) be used?

2016-08-18 Thread Michael Borregaard
Please ignore the erroneous first " in the last code line.



[julia-users] When can the broadcast dot (in 0.5) be used?

2016-08-18 Thread Michael Borregaard
I have a hard time figuring out what functions and types accept the 
broadcast dot in 0.5. E.g.,

is(1, 2)# false
is.([1, 2], 2)  # Bool[false, true]

is("a", "b")#false
is.("["a","b"], "b")#MethodError: no method matching size(::String)

Can anyone give me a hint?


[julia-users] Re: JupyterLab

2016-08-16 Thread Michael Borregaard
I could get a Julia 'console' working, which is like an IPython console, 
i.e. no graphics or markdown. It had an option to change kernel (for the 
notebook I assume) but I couldn't get it to work straight away. Other 
people might, or it will be working soon. In the presentation they stressed 
that it is very alpha-stage.


Re: [julia-users] Array of Strings

2016-08-12 Thread Michael Borregaard
So in answer to your question you would write

function hello_array{T<:AbstractString}(dat::Vector{T})
map(println, dat)
end




Re: [julia-users] precompiling all packages

2016-08-09 Thread Michael Borregaard
AFAIK none of these threads provided an easy and clear resolution. The 
latest I could find () ended up with a reques to define a 
`Pkg.precompile()` function, but I have not seen that anything new has 
happened since.


Re: [julia-users] R code to Julia Performance issues with pmap

2016-07-06 Thread Michael Borregaard
I am not seeing your speed-up in R? elapsed is less time, but user 
significantly more, and it is the sum that counts.
When executing in parallel the language needs to copy the data to the 
workers. If the matrices are large, that takes longer than the speedup of 
the parallel execution. See what happens with a smaller matrix and then 
repeating the operation on the workers.



[julia-users] Re: polynomial terms in formula specification

2016-06-27 Thread Michael Borregaard
Thanks for responding, both, it is particularly great to get an answer from 
the father of mixed models in R and julia!

I do have to say I find the functionality slightly disappointing, though. I 
had done what was in the suggested solution, but thought of it as an 
unpleasant workaround. Can anyone explain why Julia has chosen such an 
interface? I can think of no cases where it is a feature, and I see it as a 
problem in several ways, e.g. it does not generalize the functionality and 
the data as separate modular entities, which also means that the formula 
does not express the actual relationship modeled. Also, it does not allow a 
model object that can predict on the basis of a single input variable.

I realize the result will be the same, but in my experience julia is also 
concerned with elegance and intuitive specification. I will say I am really 
surprised. Is this just a matter of implementation, so a possible @formula 
macro planned for the future will restore this functionality?

I have no strong feelings about then '1 +' , it will require typing a few 
unneccesary extra characters, but perhaps there is a pedagogical gain from 
requiring people to specify that they want an intercept fitted as well.


[julia-users] polynomial terms in formula specification

2016-06-24 Thread Michael Borregaard
Sorry for asking a question that should be super-basic, but I have looked 
all over the internet for this for an hour now: How does one specify 
polynomial terms in glm models?

In R, I would:

y ~ x + I(x^2)

Thanks!


Michael


[julia-users] Re: Compose.jl animation

2016-06-11 Thread Michael Borregaard
It is not a full answer, but you should check ctxpromise() for the size. I 
think the distribution is because the canvas is not square and you use relative 
positions to specify circle centers. You can set the size parameters in the 
context call. Sorry I realise this is really useless in terms of help but may 
point you in the right direction. 

[julia-users] Re: ANN: DC.jl - automagical linked plots in your IJulia Notebook

2016-06-08 Thread Michael Borregaard

Love it, thanks.


[julia-users] How do I find out which package is causing problems running Pkg.update()

2016-06-07 Thread Michael Borregaard
Hi,
I cannot Pkg.update(), I get the error message:

ERROR: ASTInterpreter can't be installed because it has no versions that 
support 0.4.5 of julia. You may need to update METADATA by running 
`Pkg.update()`
 in error at error.jl:22
 in resolve at 
/Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in update at 
/Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in anonymous at pkg/dir.jl:31
 in cd at file.jl:22
 in cd at pkg/dir.jl:31
 in update at 
/Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib

I do not have ASTInterpreter installed, neither do I have Gallium, which 
apparently references it. I would like to know which package is causing the 
issue, so I can create an issue on their github or uninstall it. I 
downloaded the newest stable version of julia and installed it, but it did 
not help. 

The problem means that e.g. my Atom package is in an unstable state, so I 
cannot use my normal julia workflow. Please refer me to if this should be 
an issue somewhere else, but I guess the issue of finding out the criminal 
package (that tries to install ASTInterpreter) is general enough for this 
mailing list.


Thanks a lot,
Michael


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

2016-05-25 Thread Michael Borregaard
To me, the suggested change seems to conflict intuitively with julia 
syntax. When using Julia at the REPL all expressions return a value, which 
is confusing at first when coming from othe languages but quickly becomes a 
feature. That a function also returns the value of the last statement seems 
consistent with this. 
Also, a common use of multiple dispatch is to have methods that modify 
arguments then call another method of the same name defining the basic 
functionality. Eg.

function foo(x::SomeType)
...
end

function foo(x::SomeOtherType)
  y = dostufftogetsometype(x)
  foo(y)
end

where this syntax seems intuitive.


[julia-users] convert array elements

2016-05-12 Thread Michael Borregaard
I am trying to convert from R to Julia, as i really like Julia and the nice 
development going on here. But there are certain operations that are a lot 
more complicated to do in Julia, even though they are mainstay (I will do 
the several times every day). But I am in doubt if I just don't know hwo to 
do them properly in Julia. 
One of them is converting array elements - say for example I have sample 
plot names - often they are listed in data files as ASCIIString or 
UTF8String (depending on the nationality of collaborators), and often they 
are just integers. In R I would treat them all as string:
ID <- as.character(ID)

and get on with my life. In Julia this does not sound so easy - the 
'easiest' way of doing this is 
ID = [UTF8String("$x") for x in ID]

Are there ideomatic ways of converting array elements? I would believe so, 
as this is so often used by people who work with data.

Thanks!


Re: [julia-users] Re: Ambiguous method definitions

2016-04-20 Thread Michael Borregaard

There are many cases where it is convenient to be able to give 0 kwargs. Is 
it not better to test for 
isempty(a)
when the behavior is undefined for 0 arguments?


Re: [julia-users] Adding the same functionality / variables into many functions

2016-02-25 Thread Michael Borregaard
I am relieved to hear you what not use it in practice, I was trying really 
hard to grasp the utility of it :-) It is a very elegant piece of code, 
though.

Den torsdag den 25. februar 2016 kl. 01.18.16 UTC+1 skrev Tom Breloff:
>
> I think he was just referring to the fact that it's "one more thing to 
> remember".  For the record, I would never actually use this macro, for 
> reasons implied by Mauro, but there are other, similar uses that this 
> strategy could be benficial. The choice (IMO) should come down to which is 
> more intuitive. 
>
>
>

Re: [julia-users] Re: Googling the functions I need in Julia is hard

2016-02-12 Thread Michael Borregaard
Maybe a good time to repost this link: 
https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#improving-documentation
 


As I understand it, the julia documentation format is still an evolving 
entity. Google-searching in R works well because of the massive number of 
google searches / site visits to R pages. When I started using R, during my 
PhD in 2006, it was almost impossible to google R functions, and there were 
all kinds of (not very functional) search engines to bring up R results. 
Today everybody just googles it. I feel completely confident that julia 
will have the same development, and a lot faster.

Den fredag den 12. februar 2016 kl. 13.16.08 UTC+1 skrev J Luis:
>
> One main 'dislike' I find in the documentation is that, contrary to Matlab 
> and R examples that have one page for each function, in julia we have lots 
> of functions per page with short and often cryptic descriptions. Example
>
> std(*v*[, *region*])
>
> Compute the sample standard deviation of a vector or array v, optionally 
> along dimensions in region.
>
> To have longer and, VERY IMPORTANT, usage examples one need a per function 
> page manual.
>
> sexta-feira, 12 de Fevereiro de 2016 às 11:10:54 UTC, Milan Bouchet-Valat 
> escreveu:
>>
>> Le vendredi 12 février 2016 à 09:51 +0100, Michele Zaffalon a écrit : 
>> > But the original point is still valid: using the search box in the 
>> > official documentation page http://docs.julialang.org/en/release-0.4, 
>> > searching for "standard deviation" does not bring up any useful hit, 
>> > despite the fact that Base.std is fairly well documented and contains 
>> > the words standard deviation. 
>> > Is there a reason why it should work at the REPL but not in the 
>> > webpage? 
>> Searching for "deviation" works, so it's quite mysterious that 
>> "standard deviation" doesn't... Looks like a bug in the Sphinx search 
>> engine. 
>>
>> Google's behavior is really weird too. Even a query like "standard 
>> deviation julia site:docs.julialang.org" gives the manual page home for 
>> the standard library first (even if it doesn't contain "deviation"), as 
>> well as pages mentioning "standard error". Maybe some pages are not 
>> indexed at all? Could something be tweaked in the Sphinx configuration? 
>>
>>
>> Regards 
>>
>> > 
>> > On Fri, Feb 12, 2016 at 9:25 AM, Mauro  wrote: 
>> > > Also at the Julia REPL: 
>> > > 
>> > > julia> apropos("standard deviation") 
>> > > randn! 
>> > > stdm 
>> > > std 
>> > > randn 
>> > > 
>> > > help?> std 
>> > > search: std stdm STDIN STDOUT STDERR setdiff setdiff! hist2d 
>> > > hist2d! stride strides StridedArray StridedVector StridedMatrix 
>> > > StridedVecOrMat redirect_stdin 
>> > > 
>> > >   std(v[, region]) 
>> > > 
>> > >   Compute the sample standard deviation of a vector or array v, 
>> > > optionally along dimensions in region. The algorithm returns an 
>> > > estimator of the generative 
>> > >   distribution's standard deviation under the assumption that 
>> > > each entry of v is an IID drawn from that generative distribution. 
>> > > This computation is equivalent to 
>> > >   calculating sqrt(sum((v - mean(v)).^2) / (length(v) - 1)). 
>> > > Note: Julia does not ignore NaN values in the computation. For 
>> > > applications requiring the handling of 
>> > >   missing data, the DataArray package is recommended. 
>> > > 
>> > > Having said this, documentation always needs improvements and is 
>> > > certainly not on Matlab's level of completeness.  Please contribute 
>> > > where you find it lacking.  See 
>> > > https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#impr 
>> > > oving-documentation 
>> > > 
>> > > 
>> > > On Fri, 2016-02-12 at 09:18, NotSoRecentConvert  
>> > > wrote: 
>> > > > You can even download the entire thing as a PDF, HTML, or EPUB if 
>> > > you want 
>> > > > to highlight, annotate, or bookmark your most searched functions. 
>> > > Look in 
>> > > > the lower right of the page for "v: latest" and click it for more 
>> > > options. 
>> > > > 
>> > > > On Friday, February 12, 2016 at 8:03:27 AM UTC+1, Lutfullah Tomak 
>> > > wrote: 
>> > > >> 
>> > > >> There is this one 
>> > > >> 
>> > > >> http://docs.julialang.org/en/release-0.4/stdlib/math/#Base.std 
>> > > >> 
>> > > >> Instead of google, I use this manual for search. 
>> > > >> 
>> > > >> 
>> > > 
>>
>

Re: [julia-users] if .. else on a whole array

2016-02-11 Thread Michael Borregaard
Note that both of these versions will return an array, allowing for type 
stability

Den torsdag den 11. februar 2016 kl. 09.40.27 UTC+1 skrev Michael 
Borregaard:
>
> If you are worried about maintaining two versions, that can be solved 
> simply:
> function foo(x::Vector{bar})
>   #the main code of your function
> end
>
> function foo(x::bar)
>   foo([x])
> end
>
>
>
>

Re: [julia-users] if .. else on a whole array

2016-02-11 Thread Michael Borregaard
If you are worried about maintaining two versions, that can be solved 
simply:
function foo(x::Vector{bar})
  #the main code of your function
end

function foo(x::bar)
  foo([x])
end




Den onsdag den 10. februar 2016 kl. 13.15.30 UTC+1 skrev Ferran Mazzanti:
>
> Thanks Mauro...
>
> using two methods was the first thing I thought, but I strongly dislike 
> the idea because I'd have to maintain two different functions
> to do the same, which doubles the possibility of introducing bugs. I like 
> the idea of keeping the main function simple and unique,
> so if I change something the changes apply to all calculations in the same 
> way.
>
> Best regards,
>
> Ferran.
>
> On Wednesday, February 10, 2016 at 12:11:00 PM UTC+1, Mauro wrote:
>>
>> Probably cleanest would be to make two methods, one for scalars, one for 
>> arrays.  For the array one just loop. 
>>
>> This also works, but returns an array for scalar input (type inference 
>> should work once wrapped in a function): 
>>
>> julia> x = 5 
>> 5 
>>
>> julia> [ xi>5 ? 0:1 for xi in x] 
>> 1-element Array{Any,1}: 
>>  1 
>>
>> julia> x = 1:10 
>> 1:10 
>>
>> julia> [ xi>5 ? 0:blah for xi in x] 
>> 10-element Array{Any,1}: 
>>  1 
>>  1 
>>  1 
>>  1 
>>  1 
>>  0 
>>  0 
>>  0 
>>  0 
>>  0 
>>
>>
>> On Wed, 2016-02-10 at 11:58, Ferran Mazzanti  
>> wrote: 
>> > Hi folks, 
>> > 
>> > probably a stupid question but can't find the answer, so please help if 
>> you 
>> > can :) 
>> > I would like to evaluate a if.. else.. statement on a whole array. 
>> Actually 
>> > it's a bit more complicated, as I have a function that 
>> > previously was 
>> > 
>> > function u2(x) 
>> > return 0.5*(u2_0(x)+u2_0(Lbox-x))-u2_0(Lbox/2) 
>> > end; 
>> > 
>> > for some other defined function u2(x) and constant L_box. The thing is 
>> that 
>> > I could directly evaluate that on a scalar x and on an array. 
>> > Now I have to change it and check if x is smaller than Lbox/2, 
>> returning 
>> > the same as above if it is, or 0 otherwise. 
>> > I tried something of the form 
>> > 
>> > function u2(x) 
>> > return x.>Lbox/2 ? 0 : 0.5*(u2_0(x)+u2_0(Lbox-x))-u2_0(Lbox/2) 
>> > end; 
>> > 
>> > but that complains when x is an array. What would be the easiest way to 
>> > achieve this? It should work for both scalars and arrays... 
>> > 
>> > Best regards and thanks, 
>> > 
>> > Ferran. 
>>
>

Re: [julia-users] if .. else on a whole array

2016-02-11 Thread Michael Borregaard
Really sorry, just saw this is identical to Mauro's suggestion :-/

Michael

Den torsdag den 11. februar 2016 kl. 11.39.12 UTC+1 skrev Michael 
Borregaard:
>
> Thanks for clarifying that!
> So do you suggest
> [code]
> function foo(x::bar)
>   #the function body
> end
>
> function foo(x::AbstractVector{bar})
>   map(foo, x)
> end
> [/code]
>
> On Thu, Feb 11, 2016 at 10:33 AM, Tim Holy <tim.h...@gmail.com> wrote:
>
>> If the input is a scalar and the output is a scalar, that's also 
>> type-stable.
>> Type-stability is about "predictability of the output type, given the 
>> input
>> types," not "always returns the same type."
>>
>> Also, wrapping scalars in an array will have a significant performance 
>> cost.
>>
>> Best,
>> --Tim
>>
>> On Thursday, February 11, 2016 12:44:19 AM Michael Borregaard wrote:
>> > Note that both of these versions will return an array, allowing for type
>> > stability
>> >
>> > Den torsdag den 11. februar 2016 kl. 09.40.27 UTC+1 skrev Michael
>> >
>> > Borregaard:
>> > > If you are worried about maintaining two versions, that can be solved
>> > > simply:
>> > > function foo(x::Vector{bar})
>> > >
>> > >   #the main code of your function
>> > >
>> > > end
>> > >
>> > > function foo(x::bar)
>> > >
>> > >   foo([x])
>> > >
>> > > end
>>
>>
>

[julia-users] Re: Packaging Julia project for Open Respoducable Science

2016-02-11 Thread Michael Borregaard
In terms of scientific reproducibility, I do not think that saving a 
click-and-run package is necessarily the best way to further that. What 
about unstated assumptions in your code, or (shiver) bugs? IMHO, submitting 
human-readable (i.e. annotated) source code is a stronger way to ensure 
reproducibility (and what is just as important, transparency). I guess it 
should be simple just to .zip the source code of the Julia packages you 
depend on (and their dependencies) from your local library folder.



Den torsdag den 11. februar 2016 kl. 13.06.11 UTC+1 skrev Lyndon White:
>
> I just realized that not only am I dependent on Julia packages.
> but via PyCall, I am also dependent on python packages.
> How utterly terrifying packaging this will be.
>
> I suspect I will end up failing to meet the goal of a package anyone can 
> just click and run.
> But I can at least release all the code in a nice view-able form.
>
>

[julia-users] Re: Strange behaviour on type dependency of function

2016-01-05 Thread Michael Borregaard
And there was the error! SOLVED!
The problem was the keyword argument bIN::Array{Int64, 2} = zeros(1,1) , 
which should have been bIN::Array{Int64, 2} = zeros(Int, 1,1)

Best,
Michael


Den tirsdag den 5. januar 2016 kl. 10.33.32 UTC+1 skrev Michael Borregaard:
>
> I think maybe the issue is in the definition of the keyword arguments - 
> the full function definition starts thus:
> function MarginsRnd(SampN::Int64, rN::Vector{Int64}, cN::Vector{Int64}; wN
> ::Array{Float64, 2} = zeros(1,1), pflag::ASCIIString = "canfield", wflag::
> ASCIIString = "sinkhorn", cflag::ASCIIString = "descend", bIN::Array{Int64
> , 2} = zeros(1,1), doA = true)
>
>
>
>
> Den tirsdag den 5. januar 2016 kl. 09.59.35 UTC+1 skrev Michael Borregaard:
>>
>> The problem is - I never call __MarginsRnd#2__ ! I have no idea where 
>> that list of arguments may be coming from. I am sorry, but I do not even 
>> understand why I get an automatically created __MarginsRnd#2__ method when 
>> the MarginsRnd function only has 1 method?
>>
>

[julia-users] Re: Strange behaviour on type dependency of function

2016-01-05 Thread Michael Borregaard
The problem is - I never call __MarginsRnd#2__ ! I have no idea where that 
list of arguments may be coming from. I am sorry, but I do not even 
understand why I get an automatically created __MarginsRnd#2__ method when 
the MarginsRnd function only has 1 method?


[julia-users] Re: Strange behaviour on type dependency of function

2016-01-05 Thread Michael Borregaard
I think maybe the issue is in the definition of the keyword arguments - the 
full function definition starts thus:
function MarginsRnd(SampN::Int64, rN::Vector{Int64}, cN::Vector{Int64}; wN::
Array{Float64, 2} = zeros(1,1), pflag::ASCIIString = "canfield", wflag::
ASCIIString = "sinkhorn", cflag::ASCIIString = "descend", bIN::Array{Int64, 
2} = zeros(1,1), doA = true)




Den tirsdag den 5. januar 2016 kl. 09.59.35 UTC+1 skrev Michael Borregaard:
>
> The problem is - I never call __MarginsRnd#2__ ! I have no idea where that 
> list of arguments may be coming from. I am sorry, but I do not even 
> understand why I get an automatically created __MarginsRnd#2__ method when 
> the MarginsRnd function only has 1 method?
>


[julia-users] Re: multiple methods with keyword arguments?

2016-01-05 Thread Michael Borregaard
OK, so that is the long way to do it.
I just thought that, since multiple dispatch does not work on keyword 
arguments, they should by definition be the same for all methods, no? 
Otherwise you end up with keyword arguments throwing an error because the 
type of a different argument changing, an error that is hard to debug 
because the kwargs do not show up under a methods(foo) call. Seems to me 
such a potentially ripe source of bugs that julia would have an inbuilt (or 
at least recommended ideomatic) way of dealing with it.
Thanks,
Michael

Den onsdag den 6. januar 2016 kl. 00.09.10 UTC+1 skrev Jeffrey Sarnoff:
>
> If you want all methods to use the same keyword arguments, define each 
> method with the same keyword arguments.  You can declare keyword arguments' 
> types.
>
> function foo(a::Int; test::Bool = true)
>if test
>a
>else
>0
>end
> end
>
> function foo(a::AbstractFloat; test::Bool = true)
>if test
>a
>else
>100.0
>end
> end
>
> foo(1)
> 1
> foo(1,false)
> 0
> foo(1,"grue")
> ERROR
>
> foo(1.0)
> 1.0
> foo(1.0,false)
> 100.0
> foo(1.0,"grue")
> ERROR
>
>
>
> On Tuesday, January 5, 2016 at 4:30:14 PM UTC-5, Michael Borregaard wrote:
>>
>> Hi, sorry I have a simple question, I have tried to RTFM.
>>
>> If I have a function with multiple methods and keyword arguments, all 
>> methods should share the same keyword args, right? How do I write this?
>>
>> function foo(a::Int; test = true)
>> 2+a
>> end
>>
>> function foo(a::AbstractFloat #how do I continue this line?
>>
>> In my real-world example I have multiple methods and a long list of 
>> keyword arguments.
>>
>> Thanks!
>>
>

[julia-users] multiple methods with keyword arguments?

2016-01-05 Thread Michael Borregaard
Hi, sorry I have a simple question, I have tried to RTFM.

If I have a function with multiple methods and keyword arguments, all 
methods should share the same keyword args, right? How do I write this?

function foo(a::Int; test = true)
2+a
end

function foo(a::AbstractFloat #how do I continue this line?

In my real-world example I have multiple methods and a long list of keyword 
arguments.

Thanks!


[julia-users] Strange behaviour on type dependency of function

2016-01-04 Thread Michael Borregaard
Hi, I have a function MarginsRnd. When I try to use the function, it 
complains that the types are not correct - but I do not see why. Restarting 
Julia and reloading the function does not work. The problem seems to be in 
a strangely defined method. When I run whos() I get:
whos()
  Base  23988 KB Module : Base
   MarginsRnd   3405 bytes  Function : MarginsRnd
  Core   2832 KB Module : Core
  Main  26642 KB Module : Main
Switch 13 KB Module : Switch
 __MarginsRnd#2__ 21 KB Function : __MarginsRnd#2__
   __canonical#0__   1073 bytes  Function : __canonical#0__
   __canonical#1__ 11 KB Function : __canonical#1__
   ans 24 bytes  Tuple{DataType,DataType,
DataType} : (Int64,Array{Int64,1},Array{Int64,1})
 canonical   3383 bytes  Function : canonical
 p104 bytes  13-element Array{Int64,1} : [14
,13,14,10,12,2,10,1,10,11,6,2,17]
 q136 bytes  17-element Array{Int64,1} : [4,
4,11,10,10,8,9,10,8,9,3,10,4,7,9,3,3]

So the function seems to have a #2 method, but not a #0 method for some 
reason. When I run the codes I get error message:

julia> MarginsRnd(2,p,q)
ERROR: MethodError: `__MarginsRnd#2__` has no method matching 
__MarginsRnd#2__(::Array{Float64,2}, 
::ASCIIString, ::ASCIIString, ::ASCIIString, ::Array{Float64,2}, ::Bool, 
::Int64, ::Array{Int64,1}, ::Array{Int64,1})
Closest candidates are:
  __MarginsRnd#2__(::Array{AbstractFloat,2}, ::ASCIIString, ::ASCIIString, 
::AbstractString, ::Array{Int64,2}, ::Any, ::Int64, ::Array{Int64,1}, 
::Array{Int64,1})

I have no idea how the types of the candidates have appeared.
Simple querying shows:

julia> methods(MarginsRnd)
# 1 method for generic function "MarginsRnd":
MarginsRnd(N::Int64, r::Array{Int64,1}, c::Array{Int64,1}) at none:69

julia> map(typeof, (2, p, q))
(Int64,Array{Int64,1},Array{Int64,1})

Anyone who can give me an idea what is wrong here?
Thanks a lot!




[julia-users] track progress to 0.5

2015-11-04 Thread Michael Borregaard
I am using Julia 0.4, compiling from the release-0.4 branch on github. 
Considering using 'master' instead, but - is there somewhere that lists the 
planned and implemented changes to the dev version at once?


[julia-users] force recompilation of package at update

2015-11-04 Thread Michael Borregaard
Hi,
when I load a package that has been updated, it usually recompiles for a 
long time (e.g. Gadfly). I would like this time to be at the time of 
updating (where I am not actively working in Julia) rather than at 'using', 
where I am actively working. Is there a setting to automatically recompile 
all updated packages in the updating process?

thansk


[julia-users] fixing aspect ratio in Compose.jl

2015-09-28 Thread Michael Borregaard
Hi,
does anyone know how to fix the aspect ratio in a compose canvas? Gadfly 
can do it with ```coords.Cartesian(fixed = true)```, which uses Compose, 
but how to do it for that?

thanks,
M


[julia-users] return 2D (or nD) array from function

2015-09-15 Thread Michael Borregaard
Hi,
I am trying to migrate from R to julia. I am trying to wrap my head around:
In R, there are the apply functions - when used with, e.g. a function that 
returns a 1d array of constant length, they will return a 2d array with the 
results. In julia, using map() will return a Array{Array{T, 1}, 1} . What 
is the best, ideomatic way of building an Array{T, 2} from repeated runs of 
a function? A hcat() call at the end of a forloop? Initializing an array 
with the right dimensions with zeros(T, r, c) an indexing inside a for 
loop? Or is there something smarter/nicer/better?

Thanks,
Michael


[julia-users] constrain arguments in function

2015-09-15 Thread Michael Borregaard
Is there a way in julia to restrict the values of arguments to a function, 
eg to the contents of a certain vector?

So, e.g. method in the function 

function foo(x, method::String) ...

would be constrained to either "spearman", "pearson" or "kendall"?

Thanks


[julia-users] rownames in data matrices

2015-09-08 Thread Michael Borregaard
Hi, I am learning julia, and thought I would practice by migrating some of 
my code from R. I run into the problem that the data structures in julia 
does not seem to offer row names? I looked here in the forum and found a 2 
year old discussion, that seems to end of the, IMHO slightly imprecise 
opinion that rownames are a misfeature 
(https://groups.google.com/forum/#!searchin/julia-users/rownames$20matrix/julia-users/OFbnNLPdWOc/qTnhlm33YzMJ).
 
Of course, in DataFrame it is always possible to add another column with 
names, and use this by convention, though it does preclude the nice 
behaviour of automatically extracting a Named Array with appropriate names 
when extracting a column.

Worse is the case for data matrices, that do not support multiple types. 
Take for instance an ecological community matrix, that has species as 
columns, sites as rows, and is filled with integers counting the abundance 
of individuals. Subsetting a column gives the occupancy of a species, 
subsetting a row gives the species community in a site. Having row and 
column names, and being able to index into the array on names, is a really 
important feature!

How would this be implemented in julia? Is there still a conviction that 
row names are a misfeature, and why?

Thanks!


[julia-users] Strange behaviour when adding floating numbers

2015-09-03 Thread Michael Borregaard
Hi,
in the Julia documentation, I fell over this strange behaviour:

julia> 1.1 + 0.1
1.2002

I understand that this may make sense in the context of how floating 
numbers are implemented inside Julia - but I cannot think of a single 
situation in which the user would want this behaviour.
Can someone explain what is going on, and why this is not a bug?

Thanks,
Michael


[julia-users] Re: Strange behaviour when adding floating numbers

2015-09-03 Thread Michael Borregaard
OK, thanks - the website is really useful. I come from R, where the result 
is presented as 1.2 – I guess Julia is more low-level in its interface. 
(BTW I did of course search the forums before posting, but most have missed 
the question).

Den torsdag den 3. september 2015 kl. 09.45.18 UTC+2 skrev Michael 
Borregaard:
>
> Hi,
> in the Julia documentation, I fell over this strange behaviour:
>
> julia> 1.1 + 0.1
> 1.2002
>
> I understand that this may make sense in the context of how floating 
> numbers are implemented inside Julia - but I cannot think of a single 
> situation in which the user would want this behaviour.
> Can someone explain what is going on, and why this is not a bug?
>
> Thanks,
> Michael
>


[julia-users] julia in Sublime without IJulia functionality

2014-10-12 Thread Michael Borregaard
Hi,
I use Sublime, and am curious about Julia. I have installed the 
Sublime-IJulia package, and it works (OS X). But I find the notebook 'I' 
framework confusing, slow and clumsy. My mistake, I know, I am sure it 
works well for most people, but I prefer a workflow with a separate script 
and REPL console. Can I do that in Sublime, or is it necessary to go via 
the IJulia framework?
If somebody could pass me a really convincing link why the 'I' framework 
would be superior, I would read it with interest.