Re: [julia-users] repeat()'s docstring: maybe some clarification needed?

2014-06-17 Thread Bruno Rodrigues
For outer, I think that it would be clearer to say that it repeats (or 
clones?) the whole array along the specified dimensions. For inner, I think 
it's ok.

Looking at the tests for repeat, I think we could use this as an example:

As an illustrative example, let's consider array A:
A = [1 2;3 4]

2x2 Array{Int64,2}:
 1  2
 3  4

If you want to repeat array A along the second dimension:

repeat(A,inner=[1,1],outer=[1,2])
2x4 Array{Int64,2}:
 1  2  1  2
 3  4  3  4

You can also repeat the columns first:

repeat(A,inner=[1,2],outer=[1,1])
2x4 Array{Int64,2}:
 1  1  2  2
 3  3  4  4



You can also create a new array that repeats A along a third dimension:

repeat(A,inner=[1,1],outer=[1,1,2])
2x2x2 Array{Int64,3}:
[:, :, 1] =
 1  2
 3  4

[:, :, 2] =
 1  2
 3  4


Is there a limit on how a docstring can be? Could we add more examples?

On Thursday, June 12, 2014 4:59:14 PM UTC+2, John Myles White wrote:

 Rewriting the documentation for repeat would be great. I’m the guilty 
 party for that piece of documentation and agree that it’s not very good. 
 Rewriting it from scratch is probably a good idea.

 I’m not sure I think `tile` is much better than `outer`. Maybe we should 
 use something like `perelement` and `perslice` as the keywords? If we 
 revise the keywords, we should also find terms to describe one additional 
 piece of functionality I’d like to add to repeat: the ability to repeat 
 specific elements a distinct number of times. That’s the main thing that 
 repeat is missing that you’d get from R’s rep function.

 If you’re looking for good examples for the documentation, there are a 
 bunch of tests for `repeat` you could use as inspiration: 
 https://github.com/JuliaLang/julia/blob/b320b66db8fb97cc3b96fe4089b7b15528ab346c/test/arrayops.jl#L302

  — John

 On Jun 12, 2014, at 6:17 AM, Patrick O'Leary patrick...@gmail.com 
 javascript: wrote:

 On Thursday, June 12, 2014 7:57:03 AM UTC-5, Bruno Rodrigues wrote:

 repeat() is much more useful that Matlab's repmat(), but the docstring is 
 unclear, at least for me. Unfortunately, I don't have, right now, any 
 proposals to correct it. Could maybe an example be added to the docstring? 
 Maybe it could be clearer this way.


 I think an example would help make this immediately obvious. I also wonder 
 if the keyword arguments could be better--I don't have a good alternative 
 for inner, but tile seems like a good alternative to outer. That may 
 at least be useful in a rework of the doc.

 Note that you don't have to supply both keyword arguments, only one, so if 
 you're not using the feature of inner you can simply omit it. 




Re: [julia-users] Benchmarking study: C++ Fortran Numba Julia Java Matlab the rest

2014-06-17 Thread Bruno Rodrigues
Hi Pr. Villaverde, just wanted to say that it was your paper that made me 
try Julia. I must say that I am very happy with the switch! Will you 
continue using Julia for your research?


[julia-users] repeat()'s docstring: maybe some clarification needed?

2014-06-12 Thread Bruno Rodrigues
Hi, yesterday I asked for help in the channel to ask how I could achieve 
something like Matlab's repmat(): Julia also has a repmat() function, but 
only for two-dimensional arrays, whereas Matlab's implementation works for 
as many dimensions as you want. I found about repeat() but didn't 
understand the docstring (English is not my mother tongue, so that may be 
an important factor).

When I read the docstring, I was under the impression that repeat() would 
also only work for two dimensional arrays, which is actually not the case. 
Thanks to tkelman's help, I could replicate Matlab's repmat() behavior with 
repeat. 

Here is repeat()'s docstring:

Base.repeat(A, inner = Int[], outer = Int[])

   Construct an array by repeating the entries of A. The i-th
   element of inner specifies the number of times that the
   individual entries of the i-th dimension of A should be
   repeated. The i-th element of outer specifies the number of
   times that a slice along the i-th dimension of A should be
   repeated.


Here is an example of what I wanted to achieve:

Let's create an array first:

A= diagm([1,2,3,4,5])

Now I want to have this same array repeated along a third dimension. In 
Matlab, I'd do this:

repmat(A,1,1,3)

to have a new array with A repeated three times along the third axis. In 
Julia, this same command doesn't work. So the user has to use repeat():

repeat(A,inner=[1,1,1],outer=[1,1,3])

repeat() is much more useful that Matlab's repmat(), but the docstring is 
unclear, at least for me. Unfortunately, I don't have, right now, any 
proposals to correct it. Could maybe an example be added to the docstring? 
Maybe it could be clearer this way.



[julia-users] Element selection in an array, for all columns

2014-06-10 Thread Bruno Rodrigues
Hi, I have a question concerning element selection in an array. Suppose you 
have the following arrays:

B = [17 24 1 8 15; 23 5 7 14 16;4 6 13 20 22; 10 12 19 21 3;11 18 25 2 9]

E =[5 5 5 4 5 5 5 5 1 5]

If I type:

B[E]

I get:

11  11  11  10  11  11  11  11  17  11

The 5th element of B is 11, so since E  = 5, 5, 5... the first three 
elements of B[E] is 11 11 11. Now, comes my question: is there a way to do 
this for all columns of B? In Matlab, I would write something like: B(E,:) 
and get


 B(E,:)   

ans =

111825 2 9
111825 2 9
111825 2 9
10121921 3
111825 2 9
111825 2 9
111825 2 9
111825 2 9
1724 1 815
111825 2 9

but this doesn't work in Julia

B[E,:]
ERROR: no method getindex(Array{Int64,2}, Array{Int64,2}, UnitRange{Int64})

so I need to write a loop:

S = zeros(10,5)
x = [1 2 3 4 5]

for i in x
   S[:,i] = B[:,i][E[end,:]]
   end

Is there a way to avoid this loop?




[julia-users] Repeated array indexing

2014-06-10 Thread Bruno Rodrigues
Hi, I posted a first thread but can't find it anywhere, so I probably 
messed up somewhere. So here is my problem: let's say we have following 
arrays:

B = [17 24 1 8 15; 23 5 7 14 16;4 6 13 20 22; 10 12 19 21 3;11 18 25 2 9]

E =[5 5 5 4 5 5 5 5 1 5]

If we do this: 

B[E]

we get: 

B[E]
1x10 Array{Int64,2}:
 11  11  11  10  11  11  11  11  17  11

No problems. But how would I do that for all columns of B? In matlab, I'd 
do this: B(E,:) and get:

ans =

111825 2 9
111825 2 9
111825 2 9
10121921 3
111825 2 9
111825 2 9
111825 2 9
111825 2 9
1724 1 815
111825 2 9

In Julia I must do a loop:

S = zeros(10,5)
x = [1 2 3 4 5]

for i in x
   S[:,i] = B[:,i][E[end,:]]
   end


Is there a way to avoid this loop and obtain something like in Matlab using 
simple indexing notation?


[julia-users] Re: Repeated array indexing

2014-06-10 Thread Bruno Rodrigues
Great, thank you very much, it is indeed working as expected!

On Tuesday, June 10, 2014 3:52:50 PM UTC+2, Gunnar Farnebäck wrote:

 You can do B[E[:],:] or better write E as a vector (rather than a 1x10 
 array) directly:
 E = [5, 5, 5, 4, 5, 5, 5, 5, 1, 5]
 Then B[E,:] works as expected.