[julia-users] Re: small array/vector ops with broadcast and generators?

2016-09-25 Thread Jared Crean
Hello Steve,
  I'm not up to date on the new broadcast functionality, but I can say that 
the function norm does not heap allocate any memory, the heap allocation is 
coming from the x[p:p+2], which creates a new array of length 3 and copies 
the values from x into it.  There are a few solutions for creating 
sub-vectors that reference the existing array rather creating a new one. To 
do this without allocation, I use the `unsafe_view` from the ArrayViews 
package.  You can do `nr = norm(unsafe_view( x, p:p+2)).  The downside is 
there is no boundschecking with `unsafe_view`s, and you have to ensure a 
reference to the original array x exists somewhere (otherwise it might get 
garbage collected).  You can also use `view` from the same package, which 
does not have those downsides, but it does get heap allocated.  You can 
also use `sub` (renamed `view` in 0.5), which is part of Base, and works on 
any AbstractArray (ArrayViews only work on Arrays), but also gets heap 
allocated.

  Jared Crean

On Sunday, September 25, 2016 at 11:19:39 AM UTC-4, vav...@uwaterloo.ca 
wrote:
>
> My code has many operations on small matrices and vectors.  In Julia 0.4, 
> carrying these out with subvector operations causes a needless heap 
> allocation, so I've done them all with loops.  In other words, instead of 
> nr = norm(x[p:p+2])
>
> I write
>
> nr = 0.0
> for j = p : p + 2
> nr += x[j]^2
> end
> nr = sqrt(nr)
>
> I've also used the Einsum.jl macro package, which implicitly writes the 
> loops.
>
> My question is: do the new broadcast and generator-comprehension 
> operations available in 0.5 or 0.6 make it possible to accomplish these 
> small operations using one-line solutions that don't allocate heap memory? 
>
> Here are some other examples of operations for which I would like 
> efficient one-liners:
> 
>  t = dot(v[p:p+3], w[p:p+3]) 
>  c += A[p:p+2, q:q+2] * v[q:q+2]  # "gaxpy"; c is a length-3 vector
>
> Thanks,
> Steve Vavasis
>
>

Re: [julia-users] ANN: RawArray.jl

2016-09-25 Thread Isaiah Norton
Is there a reason to use this file format over NRRD [1]? To borrow a wise
phrasing: I wonder if the world needs another lightweight raw data format ;)

For what it's worth, NRRD is already supported by JuliaIO/Images.jl, and I
believe addresses the use-cases identified in your readme, but with a
number of technical and non-technical advantages (not least: a number of
independent implementations, and a substantial user base, at least as far
as these things go).

I say this -- very selfishly I admit -- as someone who has been on the
receiving end of far too many files in home-brewed formats.

[1] http://teem.sourceforge.net/nrrd/descformat.html

On Sunday, September 25, 2016, David Smith  wrote:

> Hi, all:
>
> I finally pushed this out, and it might satisfy some of your needs for a
> simple way to store N-d arrays to disk. Hope you enjoy it.
>
> RawArray (.ra) is a simple file format for storing n-dimensional arrays.
> RawArray was designed to be portable, fast, storage efficient, and future
> proof. Basically it writes the binary array data directly to disk with a
> short header that is used to recreate type and dimension information.
>
> RawArray is faster than HDF5 and supports complex numbers out of the box,
> which HDF5 does not. RawArray supports all basic `Int`, `UInt`, `Float`,
> and `Complex{}` types, and more can be easily added in the future, such as
> Rational or Big*. It can also handle derived types, but the serialization
> of them is currently left up to the user.
>
> A system of version numbers and flags are implemented to future-proof the
> data files as well, in case the implementation needs to change for some
> reason.
>
> You can grab it with `Pkg.add("RawArray")`. A minimum of Julia 0.4 is
> required.
>
> Repository: https://github.com/davidssmith/RawArray.jl
>
> Cheers,
> Dave
>


[julia-users] Re: Why was a fundamental indexing inconsistency introduced in 0.5?

2016-09-25 Thread Randy Zwitch
As someone who has never used repmat, I can't comment on that, but the 
"automatic squashing" makes perfect sense to me. The first syntax 
simplifies the structure down to a 1-D instead of a 2-D array with only one 
row (repmat aside, why would I want to keep the extra dimension if it 
doesn't contain any information?)


On Sunday, September 25, 2016 at 6:32:28 PM UTC-4, Joshua Jones wrote:
>
> The change to indexing within matrices in 0.5.0 is fundamentally 
> counterintuitive. For example:
>
> julia> frame32 = randn(16,7);
>
> julia> size(frame32[1,:])
> (7,)
>
> julia> size(frame32[1:1,:])
> (1,7)
>
> To be quite blunt, I think this is a terrible contradiction. It completely 
> breaks the repmat syntax that people have used in other languages for more 
> than 20 years. To obtain what my code *was* doing last week, I now need 
> to do one of:
> julia> repmat(frame32[1,:]', 16, 1)
> julia> repmat(frame32[1:1,:], 16, 1)
>
> In plain English, my code needs to take the transpose of an extracted row 
> for the result to be a row vector. Isn't this the very definition of 
> nonreflexive syntax?
>


Re: [julia-users] Why was a fundamental indexing inconsistency introduced in 0.5?

2016-09-25 Thread Mauro
This was discussed at length here:
https://github.com/JuliaLang/julia/issues/5949

And is featured in NEWS.md:
https://github.com/JuliaLang/julia/blob/master/NEWS.md#julia-v050-release-notes

Many languages do drop scalar-indexed dimensions, for instance
Python/Numpy.

On Mon, 2016-09-26 at 00:32, Joshua Jones  
wrote:
> The change to indexing within matrices in 0.5.0 is fundamentally
> counterintuitive. For example:
>
> julia> frame32 = randn(16,7);
>
> julia> size(frame32[1,:])
> (7,)
>
> julia> size(frame32[1:1,:])
> (1,7)
>
> To be quite blunt, I think this is a terrible contradiction. It completely
> breaks the repmat syntax that people have used in other languages for more
> than 20 years. To obtain what my code *was* doing last week, I now need to
> do one of:
> julia> repmat(frame32[1,:]', 16, 1)
> julia> repmat(frame32[1:1,:], 16, 1)
>
> In plain English, my code needs to take the transpose of an extracted row
> for the result to be a row vector. Isn't this the very definition of
> nonreflexive syntax?


Re: [julia-users] Is this a bug (related to scoping / nested macros)?

2016-09-25 Thread Yichao Yu
On Sep 25, 2016 6:57 PM, "Marius Millea"  wrote:
>
> I can't figure out why this doesn't work:
>
> julia> macro outer()
>quote
>macro inner()
>end
>@inner
>end
>end
>
>
> julia> @outer
> ERROR: UndefVarError: @inner not defined
>
>
>
> Could it be a bug (I'm on 0.5) or am I missing something about how macros
work?

It's not a bug, the whole expression needs to be expand we before it's
evaluate so the macro is not defined yet


[julia-users] Is this a bug (related to scoping / nested macros)?

2016-09-25 Thread Marius Millea
I can't figure out why this doesn't work:

julia> macro outer()
   quote
   macro inner()
   end
   @inner
   end
   end


julia> @outer
ERROR: UndefVarError: @inner not defined



Could it be a bug (I'm on 0.5) or am I missing something about how macros 
work?


[julia-users] Re: ASTs of complete modules/packages?

2016-09-25 Thread Cedric St-Jean
I faced very similar issues with ClobberingReload.jl. 
https://github.com/cstjean/ClobberingReload.jl/blob/master/src/ClobberingReload.jl
 Check 
out parse_file (courtesy of @stevengj), parse_module, and creload. I 
haven't "expanded" the includes, but it seems straight-forward to do with a 
comprehension.

On Saturday, September 24, 2016 at 1:30:31 AM UTC-4, Andreas Lobinger wrote:
>
> Hello colleagues,
>
> i'm playing around with some ideas for testing and i searching for 
> something like this:
>
> * read-in (from the original file or via name) a complete module (or 
> package)
> * transform/parse to AST
> * insert additional Expr/code in dedicated places (to count calls etc.)
> * eval, so the module exists with the orginal name, but with more 
> functionality
>
> Any pointer to read?
>
> Wishing a happy day,
>   Andreas
>


[julia-users] Re: Broadcast slices

2016-09-25 Thread Steven G. Johnson


On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor wrote:
>
> I guess, but I'm trying to write a generic program where I don't know the 
> size of the array? I'm trying to find Nash Equilibrium for an n dimensional 
> array, where the player strategies are along dimensions 1:n-1, and the 
> players are along dimension n. 
>

See http://julialang.org/blog/2016/02/iteration 


[julia-users] Why was a fundamental indexing inconsistency introduced in 0.5?

2016-09-25 Thread Joshua Jones
The change to indexing within matrices in 0.5.0 is fundamentally 
counterintuitive. For example:

julia> frame32 = randn(16,7);

julia> size(frame32[1,:])
(7,)

julia> size(frame32[1:1,:])
(1,7)

To be quite blunt, I think this is a terrible contradiction. It completely 
breaks the repmat syntax that people have used in other languages for more 
than 20 years. To obtain what my code *was* doing last week, I now need to 
do one of:
julia> repmat(frame32[1,:]', 16, 1)
julia> repmat(frame32[1:1,:], 16, 1)

In plain English, my code needs to take the transpose of an extracted row 
for the result to be a row vector. Isn't this the very definition of 
nonreflexive syntax?


[julia-users] Re: No operator overloading in DataFrames.jl?

2016-09-25 Thread John Myles White
Yes, this absence is intentional. This operation is far too magical.

 -- John

On Sunday, September 25, 2016 at 7:49:27 PM UTC+2, nuffe wrote:
>
> The ability to add, subtract (etc) dataframes with automatic index 
> alignment is one of the great features with Pandas. Currently this is not 
> implemented in DataFrames.jl. I was just wondering if this is intentional?
>
> I was thinking about attempting to create a Pull Request, but the way 
> Pandas implements this (
> https://github.com/pydata/pandas/blob/master/pandas/core/ops.py#L37) 
> looks pretty intimidating, and I don't know what the corresponding design 
> idiom would be in DataFrames.jl
>
> Thanks
>


Re: [julia-users] Generators vs Comprehensions, Type-stability?

2016-09-25 Thread Michele Zaffalon
In an email a few days back, Steven Johnson wrote: "We could use type
inference on the function t -> t^2 (which is buried in the generator) to
determine a more specific eltype." A feature request, maybe?

On Sun, Sep 25, 2016 at 11:29 PM, Christoph Ortner <
christophortn...@gmail.com> wrote:

>
> I didn't quite follow what the conclusion is: is it a bug that should be
> fixed (i.e. open an issue?), or is it expected behaviour and I should stop
> using generators when I need type inference?
>
> Thanks.
>


Re: [julia-users] Generators vs Comprehensions, Type-stability?

2016-09-25 Thread Christoph Ortner

I didn't quite follow what the conclusion is: is it a bug that should be 
fixed (i.e. open an issue?), or is it expected behaviour and I should stop 
using generators when I need type inference?

Thanks.


[julia-users] Re: problem when building julia 0.5 on plattform without indirect linking

2016-09-25 Thread Florian Oswald
see 

https://github.com/JuliaLang/julia/issues/18666

On Sunday, 25 September 2016 15:54:30 UTC+2, Florian Oswald wrote:
>
> hi,
>
> i am trying to build the julia release on a remote unix system and get 
> until this step:
>
> [uctpfos@jake julia]$ make
>
> *LINK* *usr/bin/julia*
>
> /opt/rh/devtoolset-3/root/usr/libexec/gcc/x86_64-redhat-linux/4.9.1/ld: 
> /opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.1/libstdc++_nonshared.a(system_error.o):
>  
> undefined reference to symbol '_ZTVSt14error_category@@GLIBCXX_3.4.11'
>
> /usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command 
> line
>
> collect2: error: ld returned 1 exit status
>
>
> [uctpfos@jake julia]$ echo $LD_LIBRARY_PATH
>
>
> /usr/lib64/libstdc++.so.6:/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.1
>
>
> I read here (
> http://stackoverflow.com/questions/24989432/linking-error-dso-missing-from-command-line)
>  
> that i should explicitly link to the missing library. how do i do this with 
> the julia makefile? what else needs to be on my LD_LBIRARY_PATH?
>
>
> thanks
>


[julia-users] Re: Broadcast slices

2016-09-25 Thread Davide Lasagna
Hi Brandon, 

you might find some inspiration from this package 
.

Davide

On Sunday, September 25, 2016 at 8:33:54 PM UTC+1, Dan wrote:
>
> Nice.
> It is easier when the payoffs are in vector form. My last iteration:
>
> is_nash_equilibrium(po) = 
> !reduce(|,falses(po[1]),(broadcast(<,po[i],mapslices(maximum,po[i],i)) for 
> i=1:length(po)))
>
> A one-liner :)
>
> On Sunday, September 25, 2016 at 2:25:45 PM UTC-4, Brandon Taylor wrote:
>>
>> Cool! The implementation I have is:
>>
>> equals_max(x) = x .== maximum(x)
>>
>> best_response_dimension(payoff_matrix, dimension) =
>> mapslices(equals_max, payoff_matrix, dimension)
>>
>> is_nash_equilibrium(payoffs) = @chain begin
>> payoffs
>> broadcast(best_response_dimension, _, 1:length(_) )
>> zip(_...)
>> map(all, _)
>> end
>>
>> On Sunday, September 25, 2016 at 11:57:47 AM UTC-4, Dan wrote:
>>>
>>> Oops, that `cat` code was supposed to be:
>>>
>>> cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)
>>>
>>> Mew!
>>>
>>> On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote:

 OK. So, to get the array to have the first dim as the player selector, 
 you can go:

 cat(1,map(x->reshape(1,size(x)),array_of_arrays)


 Anyway, keeping with the same payoff_matrix as before, I realized you 
 might just want a boolean array which is true if entry is a best response 
 (for the appropriate player according to last dim). It is the same flavor 
 of my previous one-liner, with `maximum` replacing `indmax` and a `.==`:

 isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),
 size(payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1
 :nplayers)...)

 Anyway, gotta go now. Have a good one.

 On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor 
 wrote:
>
> For now, I have an array of arrays. 1 payoff array for each player. 
> The arrays can be zipped to get the strategy profiles. It seems to work, 
> but having everything in 1 array just seems so much more neat. Which is 
> why 
> I was looking for a neat implementation of broadcast_slices to match.
>
> On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>>
>> Have you found the right implementation?
>>
>> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops 
>> would be the most efficient and probably the most understandable 
>> implementation.
>>
>> Also, would it not be easier to have the first index in the 
>> `payoff_matrix` determine which player's payoff are we using?
>>
>> Finally, following is an implementation using `mapslices` which seems 
>> to work:
>>
>> nplayers = last(size(payoff_matrix));
>>
>> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
>> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>> nplayers)...)
>>
>> The `bestresponse` array is the same shape as `payoff_matrix`, with 
>> each entry in `bestresponse[..,..,..,..,i]` denoting the strategy number 
>> which is a best response to the others choices for player `i` (chosen in 
>> the last index). The other player's strategies are determined by all the 
>> `..,...,..` indices before, with the choice of player `i` immaterial 
>> (since 
>> a single best response is chosen by the `indmax` function.
>>
>> This is a good exercise, perhaps another question on Stackoverflow 
>> would yield interesting variations.   
>>
>> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor 
>> wrote:
>>>
>>> Or I guess that should be
>>>
>>> broadcast_slices(best_response_dimension, player_dimension, 
>>> payoff_matrix, players)
>>>
>>> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
>>> wrote:

 I guess, but I'm trying to write a generic program where I don't 
 know the size of the array? I'm trying to find Nash Equilibrium for an 
 n 
 dimensional array, where the player strategies are along dimensions 
 1:n-1, 
 and the players are along dimension n. So:

 equals_max(x) = x .== maximum(x)

 best_response_dimension(payoff_matrix, dimension) =
 mapslices(equals_max, payoff_matrix, dimension)

 I'd want to do something like this:

 player_dimension = ndims(payoff_matrix)
 other_dimensions = repeat([1], inner = player_dimension - 1)
 number_of_players = size(payoff_matrix)[player_dimension]


 players = reshape(1:number_of_players, other_dimensions..., 
 number_of_players)

 broadcast_slices(best_response_dimension, payoff_matrix, players)

 On Thursday, September 22, 2016 at 9:00:51 

[julia-users] Re: Broadcast slices

2016-09-25 Thread Davide Lasagna
Hi Brandon, 

you might find some inspiration from this package 
.

Davide

On Sunday, September 25, 2016 at 8:33:54 PM UTC+1, Dan wrote:
>
> Nice.
> It is easier when the payoffs are in vector form. My last iteration:
>
> is_nash_equilibrium(po) = 
> !reduce(|,falses(po[1]),(broadcast(<,po[i],mapslices(maximum,po[i],i)) for 
> i=1:length(po)))
>
> A one-liner :)
>
> On Sunday, September 25, 2016 at 2:25:45 PM UTC-4, Brandon Taylor wrote:
>>
>> Cool! The implementation I have is:
>>
>> equals_max(x) = x .== maximum(x)
>>
>> best_response_dimension(payoff_matrix, dimension) =
>> mapslices(equals_max, payoff_matrix, dimension)
>>
>> is_nash_equilibrium(payoffs) = @chain begin
>> payoffs
>> broadcast(best_response_dimension, _, 1:length(_) )
>> zip(_...)
>> map(all, _)
>> end
>>
>> On Sunday, September 25, 2016 at 11:57:47 AM UTC-4, Dan wrote:
>>>
>>> Oops, that `cat` code was supposed to be:
>>>
>>> cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)
>>>
>>> Mew!
>>>
>>> On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote:

 OK. So, to get the array to have the first dim as the player selector, 
 you can go:

 cat(1,map(x->reshape(1,size(x)),array_of_arrays)


 Anyway, keeping with the same payoff_matrix as before, I realized you 
 might just want a boolean array which is true if entry is a best response 
 (for the appropriate player according to last dim). It is the same flavor 
 of my previous one-liner, with `maximum` replacing `indmax` and a `.==`:

 isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),
 size(payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1
 :nplayers)...)

 Anyway, gotta go now. Have a good one.

 On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor 
 wrote:
>
> For now, I have an array of arrays. 1 payoff array for each player. 
> The arrays can be zipped to get the strategy profiles. It seems to work, 
> but having everything in 1 array just seems so much more neat. Which is 
> why 
> I was looking for a neat implementation of broadcast_slices to match.
>
> On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>>
>> Have you found the right implementation?
>>
>> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops 
>> would be the most efficient and probably the most understandable 
>> implementation.
>>
>> Also, would it not be easier to have the first index in the 
>> `payoff_matrix` determine which player's payoff are we using?
>>
>> Finally, following is an implementation using `mapslices` which seems 
>> to work:
>>
>> nplayers = last(size(payoff_matrix));
>>
>> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
>> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>> nplayers)...)
>>
>> The `bestresponse` array is the same shape as `payoff_matrix`, with 
>> each entry in `bestresponse[..,..,..,..,i]` denoting the strategy number 
>> which is a best response to the others choices for player `i` (chosen in 
>> the last index). The other player's strategies are determined by all the 
>> `..,...,..` indices before, with the choice of player `i` immaterial 
>> (since 
>> a single best response is chosen by the `indmax` function.
>>
>> This is a good exercise, perhaps another question on Stackoverflow 
>> would yield interesting variations.   
>>
>> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor 
>> wrote:
>>>
>>> Or I guess that should be
>>>
>>> broadcast_slices(best_response_dimension, player_dimension, 
>>> payoff_matrix, players)
>>>
>>> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
>>> wrote:

 I guess, but I'm trying to write a generic program where I don't 
 know the size of the array? I'm trying to find Nash Equilibrium for an 
 n 
 dimensional array, where the player strategies are along dimensions 
 1:n-1, 
 and the players are along dimension n. So:

 equals_max(x) = x .== maximum(x)

 best_response_dimension(payoff_matrix, dimension) =
 mapslices(equals_max, payoff_matrix, dimension)

 I'd want to do something like this:

 player_dimension = ndims(payoff_matrix)
 other_dimensions = repeat([1], inner = player_dimension - 1)
 number_of_players = size(payoff_matrix)[player_dimension]


 players = reshape(1:number_of_players, other_dimensions..., 
 number_of_players)

 broadcast_slices(best_response_dimension, payoff_matrix, players)

 On Thursday, September 22, 2016 at 9:00:51 

[julia-users] HEADS-UP: breaking change in LightGraphs API

2016-09-25 Thread Seth


Sorry if this is not relevant to your use of LightGraphs, but I wanted to 
make sure everyone's aware of a change in the API for the 
`induced_subgraph()` function.


Starting in LightGraphs 0.7.1, `induced_subgraph()` will, in addition to 
the subgraph itself, return a mapping of the original vertex indices to the 
new ones. This will require code changes to ignore the new return value if 
you’re using this function.


If you’re using the `getindex` version of `induced_subgraph` (that is, 
`g[1:5]`), there will be no change.


Please feel free to file issues over at LightGraphs.jl if you run into 
problems.


[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
Nice.
It is easier when the payoffs are in vector form. My last iteration:

is_nash_equilibrium(po) = 
!reduce(|,falses(po[1]),(broadcast(<,po[i],mapslices(maximum,po[i],i)) for 
i=1:length(po)))

A one-liner :)

On Sunday, September 25, 2016 at 2:25:45 PM UTC-4, Brandon Taylor wrote:
>
> Cool! The implementation I have is:
>
> equals_max(x) = x .== maximum(x)
>
> best_response_dimension(payoff_matrix, dimension) =
> mapslices(equals_max, payoff_matrix, dimension)
>
> is_nash_equilibrium(payoffs) = @chain begin
> payoffs
> broadcast(best_response_dimension, _, 1:length(_) )
> zip(_...)
> map(all, _)
> end
>
> On Sunday, September 25, 2016 at 11:57:47 AM UTC-4, Dan wrote:
>>
>> Oops, that `cat` code was supposed to be:
>>
>> cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)
>>
>> Mew!
>>
>> On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote:
>>>
>>> OK. So, to get the array to have the first dim as the player selector, 
>>> you can go:
>>>
>>> cat(1,map(x->reshape(1,size(x)),array_of_arrays)
>>>
>>>
>>> Anyway, keeping with the same payoff_matrix as before, I realized you 
>>> might just want a boolean array which is true if entry is a best response 
>>> (for the appropriate player according to last dim). It is the same flavor 
>>> of my previous one-liner, with `maximum` replacing `indmax` and a `.==`:
>>>
>>> isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),
>>> size(payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>>> nplayers)...)
>>>
>>> Anyway, gotta go now. Have a good one.
>>>
>>> On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor wrote:

 For now, I have an array of arrays. 1 payoff array for each player. The 
 arrays can be zipped to get the strategy profiles. It seems to work, but 
 having everything in 1 array just seems so much more neat. Which is why I 
 was looking for a neat implementation of broadcast_slices to match.

 On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>
> Have you found the right implementation?
>
> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops 
> would be the most efficient and probably the most understandable 
> implementation.
>
> Also, would it not be easier to have the first index in the 
> `payoff_matrix` determine which player's payoff are we using?
>
> Finally, following is an implementation using `mapslices` which seems 
> to work:
>
> nplayers = last(size(payoff_matrix));
>
> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
> nplayers)...)
>
> The `bestresponse` array is the same shape as `payoff_matrix`, with 
> each entry in `bestresponse[..,..,..,..,i]` denoting the strategy number 
> which is a best response to the others choices for player `i` (chosen in 
> the last index). The other player's strategies are determined by all the 
> `..,...,..` indices before, with the choice of player `i` immaterial 
> (since 
> a single best response is chosen by the `indmax` function.
>
> This is a good exercise, perhaps another question on Stackoverflow 
> would yield interesting variations.   
>
> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor 
> wrote:
>>
>> Or I guess that should be
>>
>> broadcast_slices(best_response_dimension, player_dimension, 
>> payoff_matrix, players)
>>
>> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
>> wrote:
>>>
>>> I guess, but I'm trying to write a generic program where I don't 
>>> know the size of the array? I'm trying to find Nash Equilibrium for an 
>>> n 
>>> dimensional array, where the player strategies are along dimensions 
>>> 1:n-1, 
>>> and the players are along dimension n. So:
>>>
>>> equals_max(x) = x .== maximum(x)
>>>
>>> best_response_dimension(payoff_matrix, dimension) =
>>> mapslices(equals_max, payoff_matrix, dimension)
>>>
>>> I'd want to do something like this:
>>>
>>> player_dimension = ndims(payoff_matrix)
>>> other_dimensions = repeat([1], inner = player_dimension - 1)
>>> number_of_players = size(payoff_matrix)[player_dimension]
>>>
>>>
>>> players = reshape(1:number_of_players, other_dimensions..., 
>>> number_of_players)
>>>
>>> broadcast_slices(best_response_dimension, payoff_matrix, players)
>>>
>>> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. 
>>> Johnson wrote:

 At some point, it is simpler to just write loops than to try and 
 express a complicated operation in terms of higher-order functions 
 like 
 broadcast.

>>>

[julia-users] Re: Broadcast slices

2016-09-25 Thread Brandon Taylor
Cool! The implementation I have is:

equals_max(x) = x .== maximum(x)

best_response_dimension(payoff_matrix, dimension) =
mapslices(equals_max, payoff_matrix, dimension)

is_nash_equilibrium(payoffs) = @chain begin
payoffs
broadcast(best_response_dimension, _, 1:length(_) )
zip(_...)
map(all, _)
end

On Sunday, September 25, 2016 at 11:57:47 AM UTC-4, Dan wrote:
>
> Oops, that `cat` code was supposed to be:
>
> cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)
>
> Mew!
>
> On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote:
>>
>> OK. So, to get the array to have the first dim as the player selector, 
>> you can go:
>>
>> cat(1,map(x->reshape(1,size(x)),array_of_arrays)
>>
>>
>> Anyway, keeping with the same payoff_matrix as before, I realized you 
>> might just want a boolean array which is true if entry is a best response 
>> (for the appropriate player according to last dim). It is the same flavor 
>> of my previous one-liner, with `maximum` replacing `indmax` and a `.==`:
>>
>> isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),
>> size(payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>> nplayers)...)
>>
>> Anyway, gotta go now. Have a good one.
>>
>> On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor wrote:
>>>
>>> For now, I have an array of arrays. 1 payoff array for each player. The 
>>> arrays can be zipped to get the strategy profiles. It seems to work, but 
>>> having everything in 1 array just seems so much more neat. Which is why I 
>>> was looking for a neat implementation of broadcast_slices to match.
>>>
>>> On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:

 Have you found the right implementation?

 Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops 
 would be the most efficient and probably the most understandable 
 implementation.

 Also, would it not be easier to have the first index in the 
 `payoff_matrix` determine which player's payoff are we using?

 Finally, following is an implementation using `mapslices` which seems 
 to work:

 nplayers = last(size(payoff_matrix));

 bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
 payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
 nplayers)...)

 The `bestresponse` array is the same shape as `payoff_matrix`, with 
 each entry in `bestresponse[..,..,..,..,i]` denoting the strategy number 
 which is a best response to the others choices for player `i` (chosen in 
 the last index). The other player's strategies are determined by all the 
 `..,...,..` indices before, with the choice of player `i` immaterial 
 (since 
 a single best response is chosen by the `indmax` function.

 This is a good exercise, perhaps another question on Stackoverflow 
 would yield interesting variations.   

 On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor 
 wrote:
>
> Or I guess that should be
>
> broadcast_slices(best_response_dimension, player_dimension, 
> payoff_matrix, players)
>
> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
> wrote:
>>
>> I guess, but I'm trying to write a generic program where I don't know 
>> the size of the array? I'm trying to find Nash Equilibrium for an n 
>> dimensional array, where the player strategies are along dimensions 
>> 1:n-1, 
>> and the players are along dimension n. So:
>>
>> equals_max(x) = x .== maximum(x)
>>
>> best_response_dimension(payoff_matrix, dimension) =
>> mapslices(equals_max, payoff_matrix, dimension)
>>
>> I'd want to do something like this:
>>
>> player_dimension = ndims(payoff_matrix)
>> other_dimensions = repeat([1], inner = player_dimension - 1)
>> number_of_players = size(payoff_matrix)[player_dimension]
>>
>>
>> players = reshape(1:number_of_players, other_dimensions..., 
>> number_of_players)
>>
>> broadcast_slices(best_response_dimension, payoff_matrix, players)
>>
>> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. 
>> Johnson wrote:
>>>
>>> At some point, it is simpler to just write loops than to try and 
>>> express a complicated operation in terms of higher-order functions like 
>>> broadcast.
>>>
>>

Re: [julia-users] Is there a way to download a copy of Plots' documentation?

2016-09-25 Thread Tom Breloff
Also I'll state the obvious. The documentation is not a static reference.
If you take a snapshot of it then it'll get outdated.

On Sunday, September 25, 2016, Chris Rackauckas  wrote:

> You have to do what Sundara describes. This is a limitation of
> Documenter.jl with the mkdocs render. That would be a feature request for
> Documenter.jl . I think it's
> planned for the new native renderer, but I couldn't find the issue (and
> Plots would have to switch to the native renderer. It's not hard, but it's
> still a little bit of work).
>
> On Sunday, September 25, 2016 at 6:10:42 AM UTC-7, SundaraRaman R wrote:
>>
>> I don't know if the following is the best or easiest way, but:
>>
>> It appears the Plots.jl doc sources (https://github.com/JuliaPlots
>> /PlotDocs.jl) are in MkDocs format, which by itself only allows html
>> output; however, the author of MkDocs has released a Python package (
>> https://github.com/jgrassler/mkdocs-pandoc) which allows you to convert
>> the mkdocs-style sources into pandoc-style sources - which you can then
>> feed to pandoc, to get PDF, EPUB, etc.
>>
>> On Sunday, September 25, 2016 at 6:00:44 PM UTC+5:30, K leo wrote:
>>>
>>> in epub or even in pdf
>>>
>>


[julia-users] No operator overloading in DataFrames.jl?

2016-09-25 Thread nuffe
The ability to add, subtract (etc) dataframes with automatic index 
alignment is one of the great features with Pandas. Currently this is not 
implemented in DataFrames.jl. I was just wondering if this is intentional?

I was thinking about attempting to create a Pull Request, but the way 
Pandas implements this 
(https://github.com/pydata/pandas/blob/master/pandas/core/ops.py#L37) looks 
pretty intimidating, and I don't know what the corresponding design idiom 
would be in DataFrames.jl

Thanks


[julia-users] Re: Is there a way to download a copy of Plots' documentation?

2016-09-25 Thread Chris Rackauckas
You have to do what Sundara describes. This is a limitation of 
Documenter.jl with the mkdocs render. That would be a feature request for 
Documenter.jl . I think it's 
planned for the new native renderer, but I couldn't find the issue (and 
Plots would have to switch to the native renderer. It's not hard, but it's 
still a little bit of work).

On Sunday, September 25, 2016 at 6:10:42 AM UTC-7, SundaraRaman R wrote:
>
> I don't know if the following is the best or easiest way, but: 
>
> It appears the Plots.jl doc sources (
> https://github.com/JuliaPlots/PlotDocs.jl) are in MkDocs format, which by 
> itself only allows html output; however, the author of MkDocs has released 
> a Python package (https://github.com/jgrassler/mkdocs-pandoc) which 
> allows you to convert the mkdocs-style sources into pandoc-style sources - 
> which you can then feed to pandoc, to get PDF, EPUB, etc.
>
> On Sunday, September 25, 2016 at 6:00:44 PM UTC+5:30, K leo wrote:
>>
>> in epub or even in pdf
>>
>

Re: [julia-users] Minor troubles with quasiquoting syntax

2016-09-25 Thread Yichao Yu
On Sun, Sep 25, 2016 at 1:09 PM, Jamie Brandon
 wrote:
> Here is some code I just wrote this evening:
>
>   n = length(T.parameters)
>   index_types = typeof_index(T.parameters)
>   pushes = map(1:n) do i
> :(push!(columns[$i], $(Symbol("key_$i"
>   end
>   body = quote $(pushes...) end
>   for i in n:-1:1
> body = quote
>   $(Symbol("keys_$i")) = collect(keys($(Symbol("index_$i"
>   sort!($(Symbol("keys_$i")))
>   foreach($(Symbol("keys_$i"))) do $(Symbol("key_$i"))
> $(Symbol("index_$(i+1)")) =
> $(Symbol("index_$i"))[$(Symbol("key_$i"))]
> $body
>   end
> end
>   end
>   quote
> columns = tuple($([:(Vector{$(T.parameters[i])}()) for i in 1:n]...))
> index_1 = relation.unique
> $body
> columns
>   end
>
> It's split into multiple lines and there's only one comprehension, but it's
> still pretty hard to read and debug. (For example, the first time I ran it I
> got 'syntax: missing comma or ) in argument list' with no line number and
> hand to check each line by hand).

And by split into multiple lines I mean pulling out common parts.
There's no need to call `Symbol` that many times, you can simply do

`keys_names = [Symbol("keys_", i) for i in 1:n]` or `keys_names =
[gensym() for i in 1:n]`

and use  `keys_names[i]` everywhere.

There's also no need to use `key_$i`, simply `key` should be enough.

>
> Maybe I could improve the suffixes by writing a macro like:
>
> ip1 = i+1
> body = @suffix quote
>   keys_i = collect(keys(index_i))
>   sort!(keys_i)
>   foreach(keys_i) do key_i
> index_ip1 = index_1[key_i]
> $body
>   end
> end
>
> The macros in Base.Cartesian almost solve the comprehension problem too, if
> I make a version that can take arbitrary iters rather than just a number...
>
> On 25 September 2016 at 18:53, Yichao Yu  wrote:
>>
>> On Sun, Sep 25, 2016 at 12:39 PM, Jamie Brandon
>>  wrote:
>> > I'm doing a lot of code-generation. There are two patterns that come up
>> > all
>> > over the place - adding a suffix to a symbol and interpolating from an
>> > array
>> > comprehension. This is pretty verbose even in the simplest case:
>> >
>> > quote
>> >   ...
>> >   row = tuple($([:($(Symbol("val_$ix))) for ix in order]...))
>> >   ...
>> > end
>> >
>> > I spent a fair amount of time tracking down off-by-1-paren typos that
>> > don't
>> > show up until the code is run and behaves weirdly eg
>> > $(Symbol("foo_$ix()"))
>> > vs $(Symbol("foo_$x")()) vs $(Symbol("foo_$x"))()
>> >
>> > Is there a better way of handling this?
>>
>> Split the code into multiple lines.
>
>


Re: [julia-users] Minor troubles with quasiquoting syntax

2016-09-25 Thread Jamie Brandon
Here is some code I just wrote this evening:

  n = length(T.parameters)
  index_types = typeof_index(T.parameters)
  pushes = map(1:n) do i
:(push!(columns[$i], $(Symbol("key_$i"
  end
  body = quote $(pushes...) end
  for i in n:-1:1
body = quote
  $(Symbol("keys_$i")) = collect(keys($(Symbol("index_$i"
  sort!($(Symbol("keys_$i")))
  foreach($(Symbol("keys_$i"))) do $(Symbol("key_$i"))
$(Symbol("index_$(i+1)")) =
$(Symbol("index_$i"))[$(Symbol("key_$i"))]
$body
  end
end
  end
  quote
columns = tuple($([:(Vector{$(T.parameters[i])}()) for i in 1:n]...))
index_1 = relation.unique
$body
columns
  end

It's split into multiple lines and there's only one comprehension, but it's
still pretty hard to read and debug. (For example, the first time I ran it
I got 'syntax: missing comma or ) in argument list' with no line number and
hand to check each line by hand).

Maybe I could improve the suffixes by writing a macro like:

ip1 = i+1
body = @suffix quote
  keys_i = collect(keys(index_i))
  sort!(keys_i)
  foreach(keys_i) do key_i
index_ip1 = index_1[key_i]
$body
  end
end

The macros in Base.Cartesian almost solve the comprehension problem too, if
I make a version that can take arbitrary iters rather than just a number...

On 25 September 2016 at 18:53, Yichao Yu  wrote:

> On Sun, Sep 25, 2016 at 12:39 PM, Jamie Brandon
>  wrote:
> > I'm doing a lot of code-generation. There are two patterns that come up
> all
> > over the place - adding a suffix to a symbol and interpolating from an
> array
> > comprehension. This is pretty verbose even in the simplest case:
> >
> > quote
> >   ...
> >   row = tuple($([:($(Symbol("val_$ix))) for ix in order]...))
> >   ...
> > end
> >
> > I spent a fair amount of time tracking down off-by-1-paren typos that
> don't
> > show up until the code is run and behaves weirdly eg
> $(Symbol("foo_$ix()"))
> > vs $(Symbol("foo_$x")()) vs $(Symbol("foo_$x"))()
> >
> > Is there a better way of handling this?
>
> Split the code into multiple lines.
>


Re: [julia-users] Generators vs Comprehensions, Type-stability?

2016-09-25 Thread Michele Zaffalon
On Sat, Sep 24, 2016 at 8:54 PM, Steven G. Johnson 
wrote:

>
> julia> (begin;println(t);t^2;end for t=1:10)
>> Base.Generator{UnitRange{Int64},##37#38}(#37,1:10)
>>
>
> Julia knows that the input to the generator is a UnitRange{Int64}, i.e.
> 1:10, so the input elements are Int64.   It knows that the function being
> computed is t -> t^2.   The compiler is smart enough that it can figure out
> that if t is an Int64, then t^2 is an Int64 too, because that function is
> type stable.   So, it can figure out that the eltype of the output (i.e.
> the Generator) is Int64, all at compile time without actually evaluating
> the function.
>

It just feels like magic. Thank you for the explanation.


Re: [julia-users] Minor troubles with quasiquoting syntax

2016-09-25 Thread Yichao Yu
On Sun, Sep 25, 2016 at 12:39 PM, Jamie Brandon
 wrote:
> I'm doing a lot of code-generation. There are two patterns that come up all
> over the place - adding a suffix to a symbol and interpolating from an array
> comprehension. This is pretty verbose even in the simplest case:
>
> quote
>   ...
>   row = tuple($([:($(Symbol("val_$ix))) for ix in order]...))
>   ...
> end
>
> I spent a fair amount of time tracking down off-by-1-paren typos that don't
> show up until the code is run and behaves weirdly eg $(Symbol("foo_$ix()"))
> vs $(Symbol("foo_$x")()) vs $(Symbol("foo_$x"))()
>
> Is there a better way of handling this?

Split the code into multiple lines.


[julia-users] Minor troubles with quasiquoting syntax

2016-09-25 Thread Jamie Brandon
I'm doing a lot of code-generation. There are two patterns that come up all
over the place - adding a suffix to a symbol and interpolating from an
array comprehension. This is pretty verbose even in the simplest case:

quote
  ...
  row = tuple($([:($(Symbol("val_$ix))) for ix in order]...))
  ...
end

I spent a fair amount of time tracking down off-by-1-paren typos that don't
show up until the code is run and behaves weirdly eg $(Symbol("foo_$ix()"))
vs $(Symbol("foo_$x")()) vs $(Symbol("foo_$x"))()

Is there a better way of handling this?


Re: [julia-users] [ANN]: Deoplete-Julia: Fairly decent syntax completions in Neovim

2016-09-25 Thread El suisse
Cool!!! Thanks for sharing!!!

2016-09-25 12:15 GMT-03:00 Lyndon White :

> Ok, I've had this kicking around for months.
> It has taken me until now to get around to actually packaging it up so
> that anyone could use it.
>
> Check it out: https://github.com/JuliaEditorSupport/deoplete-julia
>
> It actually works pretty well (even if I can't write reasonable code in
> demos):
> https://asciinema.org/a/688g8iyhj1idrtz8ooptr6iso
>
> Neovim is very close to vim in functionality -- it
> can run all the same extensions etc.
> If you run vim, you should not really even notice the change to neovim, as
> a used.
> As a plug-in developer though, things have gotten way better.
> Writing a smart syntax completer for regular vim was historically nearly
> impossible, because vim didn't support background tasks.
> Neovim supports background takes out of the box, and these are used by 
> Deoplete
> completion engine,
> which this plugin extends.
>
>
> Syntax completion is loaded from what is exported from any modules you
> `using`,
> as well as from `Base` and `Core`.
> It also spits out help text, as it goes (as you can see in the demo)
>
>
> The way it works is a little bit (maybe a lot evil).
> `jltag` loads up every module you `using` and generates a semantic tagfile
> (technically a legal exuberant-ctags file even, I think).
> It uses reflection to dump out all kinds of useful info, like docstrings
> and constant values and a bunch of other stuff.
> It caches this in a file, which is then loaded by a small chunck of python
> code, that runs in deoplete.
> If your dependency modules change the cache is regenerated.
> `jltag`  and the files it generated could be ported to be used with
> another syntax completion engine.
> I think you could with only a little work, get normal Vim YouCompleteMe
> syntax completion working, by
> telling it to load from these tag files. but YCM has a terrifying codebase,
> and overall architecture.
> You could probably get a bunch of other syntax completers that accept tag
> files working too.
> (or you could use the ctagger from julialang/julia/contrib
>  to do that)
>
>
> Anyway,
> if you are a Vim user, I suggest grabbing Neovim, and Deoplete and then
> firing this up.
> Let me know what you think, and raise some issues over in the repo.
>
>
>


[julia-users] ANN: RawArray.jl

2016-09-25 Thread David Smith
Hi, all:

I finally pushed this out, and it might satisfy some of your needs for a 
simple way to store N-d arrays to disk. Hope you enjoy it.

RawArray (.ra) is a simple file format for storing n-dimensional arrays. 
RawArray was designed to be portable, fast, storage efficient, and future 
proof. Basically it writes the binary array data directly to disk with a 
short header that is used to recreate type and dimension information. 

RawArray is faster than HDF5 and supports complex numbers out of the box, 
which HDF5 does not. RawArray supports all basic `Int`, `UInt`, `Float`, 
and `Complex{}` types, and more can be easily added in the future, such as 
Rational or Big*. It can also handle derived types, but the serialization 
of them is currently left up to the user.

A system of version numbers and flags are implemented to future-proof the 
data files as well, in case the implementation needs to change for some 
reason.

You can grab it with `Pkg.add("RawArray")`. A minimum of Julia 0.4 is 
required.

Repository: https://github.com/davidssmith/RawArray.jl

Cheers,
Dave


[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
Oops, that `cat` code was supposed to be:

cat(1,map(x->reshape(x,1,size(x)...),array_of_array)...)

Mew!

On Sunday, September 25, 2016 at 11:54:43 AM UTC-4, Dan wrote:
>
> OK. So, to get the array to have the first dim as the player selector, you 
> can go:
>
> cat(1,map(x->reshape(1,size(x)),array_of_arrays)
>
>
> Anyway, keeping with the same payoff_matrix as before, I realized you 
> might just want a boolean array which is true if entry is a best response 
> (for the appropriate player according to last dim). It is the same flavor 
> of my previous one-liner, with `maximum` replacing `indmax` and a `.==`:
>
> isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),size
> (payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
> nplayers)...)
>
> Anyway, gotta go now. Have a good one.
>
> On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor wrote:
>>
>> For now, I have an array of arrays. 1 payoff array for each player. The 
>> arrays can be zipped to get the strategy profiles. It seems to work, but 
>> having everything in 1 array just seems so much more neat. Which is why I 
>> was looking for a neat implementation of broadcast_slices to match.
>>
>> On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>>>
>>> Have you found the right implementation?
>>>
>>> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops would 
>>> be the most efficient and probably the most understandable implementation.
>>>
>>> Also, would it not be easier to have the first index in the 
>>> `payoff_matrix` determine which player's payoff are we using?
>>>
>>> Finally, following is an implementation using `mapslices` which seems to 
>>> work:
>>>
>>> nplayers = last(size(payoff_matrix));
>>>
>>> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
>>> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>>> nplayers)...)
>>>
>>> The `bestresponse` array is the same shape as `payoff_matrix`, with each 
>>> entry in `bestresponse[..,..,..,..,i]` denoting the strategy number which 
>>> is a best response to the others choices for player `i` (chosen in the last 
>>> index). The other player's strategies are determined by all the `..,...,..` 
>>> indices before, with the choice of player `i` immaterial (since a single 
>>> best response is chosen by the `indmax` function.
>>>
>>> This is a good exercise, perhaps another question on Stackoverflow would 
>>> yield interesting variations.   
>>>
>>> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor 
>>> wrote:

 Or I guess that should be

 broadcast_slices(best_response_dimension, player_dimension, 
 payoff_matrix, players)

 On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
 wrote:
>
> I guess, but I'm trying to write a generic program where I don't know 
> the size of the array? I'm trying to find Nash Equilibrium for an n 
> dimensional array, where the player strategies are along dimensions 
> 1:n-1, 
> and the players are along dimension n. So:
>
> equals_max(x) = x .== maximum(x)
>
> best_response_dimension(payoff_matrix, dimension) =
> mapslices(equals_max, payoff_matrix, dimension)
>
> I'd want to do something like this:
>
> player_dimension = ndims(payoff_matrix)
> other_dimensions = repeat([1], inner = player_dimension - 1)
> number_of_players = size(payoff_matrix)[player_dimension]
>
>
> players = reshape(1:number_of_players, other_dimensions..., 
> number_of_players)
>
> broadcast_slices(best_response_dimension, payoff_matrix, players)
>
> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
> wrote:
>>
>> At some point, it is simpler to just write loops than to try and 
>> express a complicated operation in terms of higher-order functions like 
>> broadcast.
>>
>

[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
OK. So, to get the array to have the first dim as the player selector, you 
can go:

cat(1,map(x->reshape(1,size(x)),array_of_arrays)


Anyway, keeping with the same payoff_matrix as before, I realized you might 
just want a boolean array which is true if entry is a best response (for 
the appropriate player according to last dim). It is the same flavor of my 
previous one-liner, with `maximum` replacing `indmax` and a `.==`:

isbr = payoff_matrix .== cat(nplayers+1,(mapslices(x->fill(maximum(x),size(
payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:nplayers
)...)

Anyway, gotta go now. Have a good one.

On Sunday, September 25, 2016 at 11:46:26 AM UTC-4, Brandon Taylor wrote:
>
> For now, I have an array of arrays. 1 payoff array for each player. The 
> arrays can be zipped to get the strategy profiles. It seems to work, but 
> having everything in 1 array just seems so much more neat. Which is why I 
> was looking for a neat implementation of broadcast_slices to match.
>
> On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>>
>> Have you found the right implementation?
>>
>> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops would 
>> be the most efficient and probably the most understandable implementation.
>>
>> Also, would it not be easier to have the first index in the 
>> `payoff_matrix` determine which player's payoff are we using?
>>
>> Finally, following is an implementation using `mapslices` which seems to 
>> work:
>>
>> nplayers = last(size(payoff_matrix));
>>
>> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
>> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
>> nplayers)...)
>>
>> The `bestresponse` array is the same shape as `payoff_matrix`, with each 
>> entry in `bestresponse[..,..,..,..,i]` denoting the strategy number which 
>> is a best response to the others choices for player `i` (chosen in the last 
>> index). The other player's strategies are determined by all the `..,...,..` 
>> indices before, with the choice of player `i` immaterial (since a single 
>> best response is chosen by the `indmax` function.
>>
>> This is a good exercise, perhaps another question on Stackoverflow would 
>> yield interesting variations.   
>>
>> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor wrote:
>>>
>>> Or I guess that should be
>>>
>>> broadcast_slices(best_response_dimension, player_dimension, 
>>> payoff_matrix, players)
>>>
>>> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor 
>>> wrote:

 I guess, but I'm trying to write a generic program where I don't know 
 the size of the array? I'm trying to find Nash Equilibrium for an n 
 dimensional array, where the player strategies are along dimensions 1:n-1, 
 and the players are along dimension n. So:

 equals_max(x) = x .== maximum(x)

 best_response_dimension(payoff_matrix, dimension) =
 mapslices(equals_max, payoff_matrix, dimension)

 I'd want to do something like this:

 player_dimension = ndims(payoff_matrix)
 other_dimensions = repeat([1], inner = player_dimension - 1)
 number_of_players = size(payoff_matrix)[player_dimension]


 players = reshape(1:number_of_players, other_dimensions..., 
 number_of_players)

 broadcast_slices(best_response_dimension, payoff_matrix, players)

 On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
 wrote:
>
> At some point, it is simpler to just write loops than to try and 
> express a complicated operation in terms of higher-order functions like 
> broadcast.
>


[julia-users] Re: Broadcast slices

2016-09-25 Thread Brandon Taylor
For now, I have an array of arrays. 1 payoff array for each player. The 
arrays can be zipped to get the strategy profiles. It seems to work, but 
having everything in 1 array just seems so much more neat. Which is why I 
was looking for a neat implementation of broadcast_slices to match.

On Sunday, September 25, 2016 at 10:53:57 AM UTC-4, Dan wrote:
>
> Have you found the right implementation?
>
> Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops would 
> be the most efficient and probably the most understandable implementation.
>
> Also, would it not be easier to have the first index in the 
> `payoff_matrix` determine which player's payoff are we using?
>
> Finally, following is an implementation using `mapslices` which seems to 
> work:
>
> nplayers = last(size(payoff_matrix));
>
> bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
> payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:
> nplayers)...)
>
> The `bestresponse` array is the same shape as `payoff_matrix`, with each 
> entry in `bestresponse[..,..,..,..,i]` denoting the strategy number which 
> is a best response to the others choices for player `i` (chosen in the last 
> index). The other player's strategies are determined by all the `..,...,..` 
> indices before, with the choice of player `i` immaterial (since a single 
> best response is chosen by the `indmax` function.
>
> This is a good exercise, perhaps another question on Stackoverflow would 
> yield interesting variations.   
>
> On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor wrote:
>>
>> Or I guess that should be
>>
>> broadcast_slices(best_response_dimension, player_dimension, 
>> payoff_matrix, players)
>>
>> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor wrote:
>>>
>>> I guess, but I'm trying to write a generic program where I don't know 
>>> the size of the array? I'm trying to find Nash Equilibrium for an n 
>>> dimensional array, where the player strategies are along dimensions 1:n-1, 
>>> and the players are along dimension n. So:
>>>
>>> equals_max(x) = x .== maximum(x)
>>>
>>> best_response_dimension(payoff_matrix, dimension) =
>>> mapslices(equals_max, payoff_matrix, dimension)
>>>
>>> I'd want to do something like this:
>>>
>>> player_dimension = ndims(payoff_matrix)
>>> other_dimensions = repeat([1], inner = player_dimension - 1)
>>> number_of_players = size(payoff_matrix)[player_dimension]
>>>
>>>
>>> players = reshape(1:number_of_players, other_dimensions..., 
>>> number_of_players)
>>>
>>> broadcast_slices(best_response_dimension, payoff_matrix, players)
>>>
>>> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
>>> wrote:

 At some point, it is simpler to just write loops than to try and 
 express a complicated operation in terms of higher-order functions like 
 broadcast.

>>>

[julia-users] small array/vector ops with broadcast and generators?

2016-09-25 Thread vavasis
My code has many operations on small matrices and vectors.  In Julia 0.4, 
carrying these out with subvector operations causes a needless heap 
allocation, so I've done them all with loops.  In other words, instead of 
nr = norm(x[p:p+2])

I write

nr = 0.0
for j = p : p + 2
nr += x[j]^2
end
nr = sqrt(nr)

I've also used the Einsum.jl macro package, which implicitly writes the 
loops.

My question is: do the new broadcast and generator-comprehension operations 
available in 0.5 or 0.6 make it possible to accomplish these small 
operations using one-line solutions that don't allocate heap memory? 

Here are some other examples of operations for which I would like efficient 
one-liners:

 t = dot(v[p:p+3], w[p:p+3]) 
 c += A[p:p+2, q:q+2] * v[q:q+2]  # "gaxpy"; c is a length-3 vector

Thanks,
Steve Vavasis



[julia-users] [ANN]: Deoplete-Julia: Fairly decent syntax completions in Neovim

2016-09-25 Thread Lyndon White
Ok, I've had this kicking around for months.
It has taken me until now to get around to actually packaging it up so that 
anyone could use it.

Check it out: https://github.com/JuliaEditorSupport/deoplete-julia

It actually works pretty well (even if I can't write reasonable code in 
demos):
https://asciinema.org/a/688g8iyhj1idrtz8ooptr6iso

Neovim is very close to vim in functionality -- it can 
run all the same extensions etc.
If you run vim, you should not really even notice the change to neovim, as 
a used.
As a plug-in developer though, things have gotten way better.
Writing a smart syntax completer for regular vim was historically nearly 
impossible, because vim didn't support background tasks.
Neovim supports background takes out of the box, and these are used by Deoplete 
completion engine,
which this plugin extends.


Syntax completion is loaded from what is exported from any modules you 
`using`,
as well as from `Base` and `Core`.
It also spits out help text, as it goes (as you can see in the demo)


The way it works is a little bit (maybe a lot evil).
`jltag` loads up every module you `using` and generates a semantic tagfile 
(technically a legal exuberant-ctags file even, I think).
It uses reflection to dump out all kinds of useful info, like docstrings 
and constant values and a bunch of other stuff.
It caches this in a file, which is then loaded by a small chunck of python 
code, that runs in deoplete.
If your dependency modules change the cache is regenerated.
`jltag`  and the files it generated could be ported to be used with another 
syntax completion engine.
I think you could with only a little work, get normal Vim YouCompleteMe 
syntax completion working, by 
telling it to load from these tag files. but YCM has a terrifying codebase, 
and overall architecture.
You could probably get a bunch of other syntax completers that accept tag 
files working too.
(or you could use the ctagger from julialang/julia/contrib 
 to do that)


Anyway,
if you are a Vim user, I suggest grabbing Neovim, and Deoplete and then 
firing this up.
Let me know what you think, and raise some issues over in the repo.




[julia-users] Re: Broadcast slices

2016-09-25 Thread Dan
Have you found the right implementation?

Fiddling a bit, I tend to agree with Steven G. Johnson `for` loops would be 
the most efficient and probably the most understandable implementation.

Also, would it not be easier to have the first index in the `payoff_matrix` 
determine which player's payoff are we using?

Finally, following is an implementation using `mapslices` which seems to 
work:

nplayers = last(size(payoff_matrix));

bestresponse = cat(nplayers+1,(mapslices(x->fill(indmax(x),size(
payoff_matrix,i)), payoff_matrix[fill(:,nplayers)...,i],i) for i=1:nplayers
)...)

The `bestresponse` array is the same shape as `payoff_matrix`, with each 
entry in `bestresponse[..,..,..,..,i]` denoting the strategy number which 
is a best response to the others choices for player `i` (chosen in the last 
index). The other player's strategies are determined by all the `..,...,..` 
indices before, with the choice of player `i` immaterial (since a single 
best response is chosen by the `indmax` function.

This is a good exercise, perhaps another question on Stackoverflow would 
yield interesting variations.   

On Saturday, September 24, 2016 at 9:40:54 PM UTC-4, Brandon Taylor wrote:
>
> Or I guess that should be
>
> broadcast_slices(best_response_dimension, player_dimension, payoff_matrix, 
> players)
>
> On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor wrote:
>>
>> I guess, but I'm trying to write a generic program where I don't know the 
>> size of the array? I'm trying to find Nash Equilibrium for an n dimensional 
>> array, where the player strategies are along dimensions 1:n-1, and the 
>> players are along dimension n. So:
>>
>> equals_max(x) = x .== maximum(x)
>>
>> best_response_dimension(payoff_matrix, dimension) =
>> mapslices(equals_max, payoff_matrix, dimension)
>>
>> I'd want to do something like this:
>>
>> player_dimension = ndims(payoff_matrix)
>> other_dimensions = repeat([1], inner = player_dimension - 1)
>> number_of_players = size(payoff_matrix)[player_dimension]
>>
>>
>> players = reshape(1:number_of_players, other_dimensions..., 
>> number_of_players)
>>
>> broadcast_slices(best_response_dimension, payoff_matrix, players)
>>
>> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
>> wrote:
>>>
>>> At some point, it is simpler to just write loops than to try and express 
>>> a complicated operation in terms of higher-order functions like broadcast.
>>>
>>

Re: [julia-users] How to call macro stored in variable

2016-09-25 Thread Yichao Yu
On Sun, Sep 25, 2016 at 10:11 AM, Marius Millea  wrote:
> Ahh nice, thanks. Your macrocall suggestions reads cleanly too, I think it'd
> look something like this:
>
> julia> macro macrocall(mac,args...)
>Expr(:macrocall,esc(mac),map(esc,args)...)
>end
> @macrocall (macro with 1 method)
>
> julia> @macrocall idmacro 1+2
> 3
>
>
> What's the problem with local variables you mention though? I can't think of
> where this wouldn't work.

macrocall resolve the macro to be called in current **module** (i.e.
current global scope) since it runs in the parser and has no idea
about any local bindings.

This means that you might as well just assign the value to a global
starts with `@` and call it directly with normal macro syntax.

>
>
> On Sunday, September 25, 2016 at 2:08:46 PM UTC+2, Yichao Yu wrote:
>>
>> On Sun, Sep 25, 2016 at 7:25 AM, Marius Millea 
>> wrote:
>> > I can store a macro to a variable (let use the identity macro "id" as an
>> > example),
>> >
>> > julia> idmacro = macro id(ex)
>> >:($(esc(ex)))
>> >end
>> > @id (macro with 1 method)
>> >
>> >
>> > How can I use this macro now? I can *almost* do it by hand by passing an
>> > expression as an argument and eval'ing the result, but it doesn't work
>> > because there's esc's left,
>>
>> Assuming this is just for understanding how macros are implemented,
>> you can just construct a microcall expression
>>
>> julia> idmacro = macro id(ex)
>>esc(ex)
>>end
>> @id (macro with 1 method)
>>
>> julia> idmacro(:(1 + 2))
>> :($(Expr(:escape, :(1 + 2
>>
>> julia> eval(Expr(:macrocall, :idmacro, :(1 + 2)))
>> 3
>>
>> This is unlikely what you want to do in real code.
>>
>> Side notes,
>>
>> As shown above, you can just do `esc(ex)`, `:($foo)` is equivalent to
>> `foo`
>>
>> You can also use a variable name starts with `@` since that's the
>> syntax that triggers the parsing to a macrocall expression.
>>
>> julia> eval(:($(Symbol("@idmacro")) = idmacro))
>> @id (macro with 1 method)
>>
>> julia> @idmacro 1 + 2
>> 3
>>
>> julia> Meta.show_sexpr(:(@idmacro 1 + 2))
>> (:macrocall, Symbol("@idmacro"), (:call, :+, 1, 2))
>>
>>
>> You can do this transformation with a macro too (i.e. make @macrocall
>> idmacro 1 + 2 construct a macrocall expression) but it's not really
>> useful since you can't do this for a local variable, which is also why
>> I said don't do this in real code.
>>
>> >
>> > julia> @id 1+2
>> > 3
>> >
>> >
>> > julia> idmacro(:(1+2))
>> > :($(Expr(:escape, :(1 + 2
>> >
>> >
>> > julia> eval(idmacro(:(1+2)))
>> > ERROR: syntax: unhandled expr (escape (call + 1 2))
>> >  in eval(::Module, ::Any) at ./boot.jl:234
>> >  in eval(::Any) at ./boot.jl:233
>> >
>> >
>> >
>> > Does Julia provide a way to use such macros stored in variables? Thanks!


Re: [julia-users] How to call macro stored in variable

2016-09-25 Thread Marius Millea
Ahh nice, thanks. Your macrocall suggestions reads cleanly too, I think 
it'd look something like this:

julia> macro macrocall(mac,args...)
   Expr(:macrocall,esc(mac),map(esc,args)...)
   end
@macrocall (macro with 1 method)

julia> @macrocall idmacro 1+2
3


What's the problem with local variables you mention though? I can't think 
of where this wouldn't work. 


On Sunday, September 25, 2016 at 2:08:46 PM UTC+2, Yichao Yu wrote:
>
> On Sun, Sep 25, 2016 at 7:25 AM, Marius Millea  > wrote: 
> > I can store a macro to a variable (let use the identity macro "id" as an 
> > example), 
> > 
> > julia> idmacro = macro id(ex) 
> >:($(esc(ex))) 
> >end 
> > @id (macro with 1 method) 
> > 
> > 
> > How can I use this macro now? I can *almost* do it by hand by passing an 
> > expression as an argument and eval'ing the result, but it doesn't work 
> > because there's esc's left, 
>
> Assuming this is just for understanding how macros are implemented, 
> you can just construct a microcall expression 
>
> julia> idmacro = macro id(ex) 
>esc(ex) 
>end 
> @id (macro with 1 method) 
>
> julia> idmacro(:(1 + 2)) 
> :($(Expr(:escape, :(1 + 2 
>
> julia> eval(Expr(:macrocall, :idmacro, :(1 + 2))) 
> 3 
>
> This is unlikely what you want to do in real code. 
>
> Side notes, 
>
> As shown above, you can just do `esc(ex)`, `:($foo)` is equivalent to 
> `foo` 
>
> You can also use a variable name starts with `@` since that's the 
> syntax that triggers the parsing to a macrocall expression. 
>
> julia> eval(:($(Symbol("@idmacro")) = idmacro)) 
> @id (macro with 1 method) 
>
> julia> @idmacro 1 + 2 
> 3 
>
> julia> Meta.show_sexpr(:(@idmacro 1 + 2)) 
> (:macrocall, Symbol("@idmacro"), (:call, :+, 1, 2)) 
>
>
> You can do this transformation with a macro too (i.e. make @macrocall 
> idmacro 1 + 2 construct a macrocall expression) but it's not really 
> useful since you can't do this for a local variable, which is also why 
> I said don't do this in real code. 
>
> > 
> > julia> @id 1+2 
> > 3 
> > 
> > 
> > julia> idmacro(:(1+2)) 
> > :($(Expr(:escape, :(1 + 2 
> > 
> > 
> > julia> eval(idmacro(:(1+2))) 
> > ERROR: syntax: unhandled expr (escape (call + 1 2)) 
> >  in eval(::Module, ::Any) at ./boot.jl:234 
> >  in eval(::Any) at ./boot.jl:233 
> > 
> > 
> > 
> > Does Julia provide a way to use such macros stored in variables? Thanks! 
>


[julia-users] problem when building julia 0.5 on plattform without indirect linking

2016-09-25 Thread Florian Oswald
hi,

i am trying to build the julia release on a remote unix system and get 
until this step:

[uctpfos@jake julia]$ make

*LINK* *usr/bin/julia*

/opt/rh/devtoolset-3/root/usr/libexec/gcc/x86_64-redhat-linux/4.9.1/ld: 
/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.1/libstdc++_nonshared.a(system_error.o):
 
undefined reference to symbol '_ZTVSt14error_category@@GLIBCXX_3.4.11'

/usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command 
line

collect2: error: ld returned 1 exit status


[uctpfos@jake julia]$ echo $LD_LIBRARY_PATH

/usr/lib64/libstdc++.so.6:/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.1


I read here 
(http://stackoverflow.com/questions/24989432/linking-error-dso-missing-from-command-line)
 
that i should explicitly link to the missing library. how do i do this with 
the julia makefile? what else needs to be on my LD_LBIRARY_PATH?


thanks


[julia-users] "both DataArrays and StatsBase export "rle"; uses of it in module DataFrames must be qualified"

2016-09-25 Thread K leo
I get a few warning messages like this often.  Does it mean that DataFrames 
package need to be updated, or that I need to do something in my user code?


[julia-users] Re: Is there a way to download a copy of Plots' documentation?

2016-09-25 Thread SundaraRaman R
I don't know if the following is the best or easiest way, but: 

It appears the Plots.jl doc sources 
(https://github.com/JuliaPlots/PlotDocs.jl) are in MkDocs format, which by 
itself only allows html output; however, the author of MkDocs has released 
a Python package (https://github.com/jgrassler/mkdocs-pandoc) which allows 
you to convert the mkdocs-style sources into pandoc-style sources - which 
you can then feed to pandoc, to get PDF, EPUB, etc.

On Sunday, September 25, 2016 at 6:00:44 PM UTC+5:30, K leo wrote:
>
> in epub or even in pdf
>


[julia-users] Is there a way to download a copy of Plots' documentation?

2016-09-25 Thread K leo
in epub or even in pdf


Re: [julia-users] Re: LightXML Ubuntu 16.04 julia 0.4.5

2016-09-25 Thread Milan Bouchet-Valat
Le samedi 24 septembre 2016 à 06:17 -0700, Ján Adamčák a écrit :
> Thanks,
> 
> after installing 
> 
> sudo apt-get install libxml2-dev
> 
> is LightXML fully working.
Could you file an issue against LightXML.jl? It should be able to
install the package automatically, or could even work without it.


Regards


> I have another question: Why this dependency didn't resolved
> automatically by Pkg.add("LightXML") ?
> 
> 
> 
> > You might need the -dev version to get a plain "libxml2.so" in
> > addition to the version with an soname in it. I thought Julia
> > should be able to find the soname versions too, but maybe not?
> > 
> > 
> > > I tried sudo apt-get install libxml2, but I got answer from
> > > ubuntu:
> > > 
> > > libxml2 is already the newest version (2.9.3+dfsg 1-1ubuntu0.1).
> > > libxml2 is tagged as manually installed.
> > > 
> > > But from julia I got same answer:
> > > 
> > > ERROR: error compiling call: could not load library "libxml2"
> > > 
> > > 
> > > 
> > > > Try
> > > > 
> > > > sudo apt install libxml2
> > > > 
> > > > 
> > > > 
> > > > > Hi Guys,
> > > > > 
> > > > > I tried use LightXML on Ubuntu 16.04, but I got an error: 
> > > > > 
> > > > > ERROR: error compiling call: could not load library "libxml2"
> > > > > 
> > > > > Can You help me?
> > > > > 
> > > > > Thanks.
> > > > > 
> > > > > Log:
> > > > > 
> > > > >                  _
> > > > >   _       _ _(_)_     |  A fresh approach to technical
> > > > > computing
> > > > >  (_)     | (_) (_)    |  Documentation: http://docs.julialang
> > > > > .org
> > > > >   _ _   _| |_  __ _   |  Type "?help" for help.
> > > > >  | | | | | | |/ _` |  |
> > > > >  | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
> > > > > _/ |\__'_|_|_|\__'_|  |  
> > > > > |__/                   |  x86_64-linux-gnu
> > > > > 
> > > > > julia> Pkg.status()
> > > > > No packages installed
> > > > > 
> > > > > julia> Pkg.add("LightXML")
> > > > > INFO: Cloning cache of Compat from
> > > > > git://github.com/JuliaLang/Compat.jl.git
> > > > > INFO: Cloning cache of LightXML from
> > > > > git://github.com/JuliaIO/LightXML.jl.git
> > > > > INFO: Installing Compat v0.9.2
> > > > > INFO: Installing LightXML v0.4.0
> > > > > INFO: Building LightXML
> > > > > INFO: Package database updated
> > > > > INFO: METADATA is out-of-date — you may not have the latest
> > > > > version of LightXML
> > > > > INFO: Use `Pkg.update()` to get the latest versions of your
> > > > > packages
> > > > > 
> > > > > julia> Pkg.update()
> > > > > INFO: Updating METADATA...
> > > > > INFO: Computing changes...
> > > > > INFO: No packages to install, update or remove
> > > > > 
> > > > > julia> using LightXML
> > > > > INFO: Precompiling module LightXML...
> > > > > 
> > > > > julia> # create an empty XML document
> > > > >       xdoc = XMLDocument()
> > > > > ERROR: error compiling call: could not load library "libxml2"
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > 
> > > 
> > 


Re: [julia-users] How to call macro stored in variable

2016-09-25 Thread Yichao Yu
On Sun, Sep 25, 2016 at 7:25 AM, Marius Millea  wrote:
> I can store a macro to a variable (let use the identity macro "id" as an
> example),
>
> julia> idmacro = macro id(ex)
>:($(esc(ex)))
>end
> @id (macro with 1 method)
>
>
> How can I use this macro now? I can *almost* do it by hand by passing an
> expression as an argument and eval'ing the result, but it doesn't work
> because there's esc's left,

Assuming this is just for understanding how macros are implemented,
you can just construct a microcall expression

julia> idmacro = macro id(ex)
   esc(ex)
   end
@id (macro with 1 method)

julia> idmacro(:(1 + 2))
:($(Expr(:escape, :(1 + 2

julia> eval(Expr(:macrocall, :idmacro, :(1 + 2)))
3

This is unlikely what you want to do in real code.

Side notes,

As shown above, you can just do `esc(ex)`, `:($foo)` is equivalent to `foo`

You can also use a variable name starts with `@` since that's the
syntax that triggers the parsing to a macrocall expression.

julia> eval(:($(Symbol("@idmacro")) = idmacro))
@id (macro with 1 method)

julia> @idmacro 1 + 2
3

julia> Meta.show_sexpr(:(@idmacro 1 + 2))
(:macrocall, Symbol("@idmacro"), (:call, :+, 1, 2))


You can do this transformation with a macro too (i.e. make @macrocall
idmacro 1 + 2 construct a macrocall expression) but it's not really
useful since you can't do this for a local variable, which is also why
I said don't do this in real code.

>
> julia> @id 1+2
> 3
>
>
> julia> idmacro(:(1+2))
> :($(Expr(:escape, :(1 + 2
>
>
> julia> eval(idmacro(:(1+2)))
> ERROR: syntax: unhandled expr (escape (call + 1 2))
>  in eval(::Module, ::Any) at ./boot.jl:234
>  in eval(::Any) at ./boot.jl:233
>
>
>
> Does Julia provide a way to use such macros stored in variables? Thanks!


[julia-users] Re: How to call macro stored in variable

2016-09-25 Thread Marius Millea
Now that you mention it I'm not sure why I thought returning :($esc(ex)) 
was better than esc(ex), I think they give identical results in this case 
(maybe all cases?). 

But at any rate, that doesn't affect this problem since both do give the 
identical result. The problem seems to be that the returned expression in 
general might have esc's in it which ordinarily get taken out when invoking 
a macro the usual way, but don't get taken out in this case. 



On Sunday, September 25, 2016 at 1:49:41 PM UTC+2, Lutfullah Tomak wrote:
>
> It you should return just esc(ex). It seems :($(esc(ex))) makes it an 
> expression wrapping an expression.



[julia-users] How to call macro stored in variable

2016-09-25 Thread Lutfullah Tomak
It you should return just esc(ex). It seems :($(esc(ex))) makes it an 
expression wrapping an expression.

[julia-users] How to call macro stored in variable

2016-09-25 Thread Marius Millea
I can store a macro to a variable (let use the identity macro "id" as an 
example),

julia> idmacro = macro id(ex)
   :($(esc(ex)))
   end
@id (macro with 1 method)


How can I use this macro now? I can *almost* do it by hand by passing an 
expression as an argument and eval'ing the result, but it doesn't work 
because there's esc's left,

julia> @id 1+2
3


julia> idmacro(:(1+2))
:($(Expr(:escape, :(1 + 2


julia> eval(idmacro(:(1+2)))
ERROR: syntax: unhandled expr (escape (call + 1 2))
 in eval(::Module, ::Any) at ./boot.jl:234
 in eval(::Any) at ./boot.jl:233



Does Julia provide a way to use such macros stored in variables? Thanks!


[julia-users] Re: if-elseif-else programmatically

2016-09-25 Thread lapeyre . math122a
This is probably more efficient in high dimensions. I am thinking mostly 
about 1,2, and 3.  I have many routines and
want to avoid keeping three versions of each in sync. Your method will 
perform worse in 1D, and maybe 2D and 3D  too.
But, I'm starting to think that, for most of my applications, the 
performance hit may be worth the reduction in code complexity.
 

On Sunday, September 25, 2016 at 12:09:14 AM UTC+2, David P. Sanders wrote:
>
>
>
> El sábado, 24 de septiembre de 2016, 21:26:52 (UTC+2), 
> lapeyre@gmail.com escribió:
>>
>> I want to generate something like an if-elseif-else construct or 
>> switch-case programmatically.
>>
>> The use I have in mind is to write an expression for taking a step in a 
>> random walk in n dimensions,
>> so I need 2*n branches.
>>
>
> This is not a good way to solve this problem. Since you are in n 
> dimensions, just use a vector of length n,
> so that x[i] is the position in direction i (rather than generating a 
> variable called x1, another x2, etc.). Then do something like this:
>
> julia> n = 10
>
> julia> x = zeros(n)
>
> julia> direction = rand(1:n)
>
> julia> if rand() < 0.5
>  x[direction] += 1
>else
>  x[direction] -= 1
>end
>
>>
>>

[julia-users] Re: if-elseif-else programmatically

2016-09-25 Thread lapeyre . math122a
This is probably more efficient in high dimensions. I am thinking mostly 
about 1,2, and 3.  I have many routines and
want to avoid keeping three versions of each in sync. Your method will 
perform worse in 1D, and maybe 2D and 3D  too.
But, I'm starting to think that, for most of my applications, the 
performance hit may be worth the reduction in code complexity.
 

On Sunday, September 25, 2016 at 12:09:14 AM UTC+2, David P. Sanders wrote:
>
>
>
> El sábado, 24 de septiembre de 2016, 21:26:52 (UTC+2), 
> lapeyre@gmail.com escribió:
>>
>> I want to generate something like an if-elseif-else construct or 
>> switch-case programmatically.
>>
>> The use I have in mind is to write an expression for taking a step in a 
>> random walk in n dimensions,
>> so I need 2*n branches.
>>
>
> This is not a good way to solve this problem. Since you are in n 
> dimensions, just use a vector of length n,
> so that x[i] is the position in direction i (rather than generating a 
> variable called x1, another x2, etc.). Then do something like this:
>
> julia> n = 10
>
> julia> x = zeros(n)
>
> julia> direction = rand(1:n)
>
> julia> if rand() < 0.5
>  x[direction] += 1
>else
>  x[direction] -= 1
>end
>
>>
>>

[julia-users] Re: PkgDev.tag issues

2016-09-25 Thread Brandon Taylor
Ok, I deleted the extraneous tags, and retagged. Same thing messages about 
no changes to commit.

So I git added the new v0.1.0 folder and then committed manually.

Then I tried PkgDev.publish() and I got this:

ERROR: GitError(Code:EAUTH, Class:None, No errors)
 in macro expansion at .\libgit2\error.jl:99 [inlined]
 in #push#53(::Bool, ::Base.LibGit2.PushOptions, ::Function, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\libgit2\remote.jl:84
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\:0
 in #push#94(::String, ::String, ::Array{String,1}, ::Bool, 
::Nullable{Base.LibGit2.UserPasswordCredentials}, ::Function, 
::Base.LibGit2.GitRepo) at .\libgit2\libgit2.jl:185
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRepo) at .\:0
 in 
(::PkgDev.Entry.##6#11{Dict{String,Array{String,1}}})(::Base.LibGit2.GitRepo) 
at C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:114
 in with(::PkgDev.Entry.##6#11{Dict{String,Array{String,1}}}, 
::Base.LibGit2.GitRepo) at .\libgit2\types.jl:638
 in publish(::String, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:97
 in publish() at C:\Users\jsnot\.julia\v0.5\PkgDev\src\PkgDev.jl:70

So then I tried to checkout PkgDev as suggested here:
https://github.com/JuliaLang/PkgDev.jl/issues/69

and now I'm getting

INFO: Validating METADATA
INFO: Creating a personal access token for Julia Package Manager on GitHub.
You will be asked to provide credentials to your GitHub account.
Enter host password for user 'bramtayl':
INFO: Pushing ChainMap permanent tags: v0.1.0
INFO: Submitting METADATA changes
INFO: Forking JuliaLang/METADATA.jl to bramtayl
INFO: Pushing changes as branch pull-request/2ed12a90
ERROR: GitError(Code:ERROR, Class:Net, Remote error: access denied or 
repository not exported: /2/nw/29/05/c9/6106340/69147216.git)
 in macro expansion at .\libgit2\error.jl:99 [inlined]
 in #push#53(::Bool, ::Base.LibGit2.PushOptions, ::Function, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\libgit2\remote.jl:84
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\:0
 in #push#94(::String, ::String, ::Array{String,1}, ::Bool, 
::Nullable{Base.LibGit2.UserPasswordCredentials}, ::Function, 
::Base.LibGit2.GitRepo) at .\libgit2\libgit2.jl:185
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRepo) at .\:0
 in (::PkgDev.Entry.##2#3)(::Base.LibGit2.GitRepo) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:39
 in with(::PkgDev.Entry.##2#3, ::Base.LibGit2.GitRepo) at 
.\libgit2\types.jl:638
 in #pull_request#1(::String, ::String, ::String, ::Function, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:15
 in (::PkgDev.Entry.#kw##pull_request)(::Array{Any,1}, 
::PkgDev.Entry.#pull_request, ::String) at .\:0
 in publish(::String, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:121
 in publish() at C:\Users\jsnot\.julia\v0.5\PkgDev\src\PkgDev.jl:70


On Saturday, September 24, 2016 at 10:02:21 PM UTC-4, Tony Kelman wrote:
>
> You may have to remove the git tag from your local clone of the package 
> repo.