[julia-users] Re: Weird Hygiene Issue

2016-02-14 Thread Julia Tylors
That is no solution to my problem, 
what if I want to do this
module Y
  using X
  function _ex_func() 
println("Y module st")
  end
   _1ex_func()# this  won't call  Y._ex_func()
end

and i can't keep generating the functions for every module. It would be 
tedious.
may be an AST node for module based look up for that fucntion would be 
awesome, or a remote call kind of thing would be useful.

On Sunday, February 14, 2016 at 1:54:06 PM UTC-8, Lutfullah Tomak wrote:
>
> Instead of 
>@eval @f ex_func
>
> this
> eval(Main, @f ex_func)
>
> might do that. I cannot test what you do with julia 0.5 because functions 
> are now very diferent internally.
> @eval @f ex_func
> will be X.eval(@f ex_func) thus there will be X namespace but not outside 
> of the module as shown from macroexpand.
>
>

[julia-users] Re: Error with Julia + Juno IDE bundle installation on Windows 10

2016-02-14 Thread Mike Kipling
Lutfullah,

The DOS command window created from the command  `Julia: open a new 
terminal repl` shows that the Julia version is 0.3.10, not the latest 
version 0.4.3

After issuing the Pkg.update() command I get the following error:

julia> Pkg.update()
INFO: Updating METADATA...
ERROR: chdir METADATA: no such file or directory (ENOENT)
 in cd at file.jl:11 (repeats 2 times)

Mike




On Saturday, February 13, 2016 at 4:57:53 PM UTC-6, Mike Kipling wrote:
>
> Hi, 
>
> I downloaded the juno-windows-x64.zip file and extracted the files. I do 
> not see a installer for Julia. When I run the Juno.exe file I get the 
> following messages: 
>
> ERROR: Requires not found 
> in require at loading.jl:47 
> in include at boot.jl:245 
> in include_from_node1 at loading.jl:128 
> in reload_path at loading.jl:152 
> in _require at loading.jl:67 
> in require at loading.jl:51 
> in include at boot.jl:245 
> in include_from_node1 at loading.jl:128 
> in process_options at client.jl:285 
> in _start at client.jl:354 
>
> I then downloaded the and executed the file julia-0.4.3-win64.exe . 
>
> When I run Juno again, I get the same error messages. 
>
> Mike



[julia-users] Re: Error with Julia + Juno IDE bundle installation on Windows 10

2016-02-14 Thread Lutfullah Tomak
Did you download from junolab.org? The latest verison(1.1.0) is at 

 https://junolab.s3.amazonaws.com/release/1.1.0/juno-windows-x64.zip

from julialang.org/downloads . It is bundled with all the required packages and 
julia 0.4.3 . Your downloaded Juno version seems old and it was not bundled 
with required packages for older versions. I suggest using new version if you 
do not need julia 0.3 .

If you willing you can also try Juno with Atom editor instead of Lightable 
derived one. New developmemt of Juno progresses around Atom editor. The link to 
the complete bundle is

https://github.com/JunoLab/atom/releases/download/0.3.0/JunoSetup.exe

from https://github.com/JunoLab/atom-julia-client/blob/master/README.md

[julia-users] Re: Weird Hygiene Issue

2016-02-14 Thread Lutfullah Tomak
It seems impossible then. What if _1ex_func has a fuction argument then you can 
pass _ex_func to _1ex_func or module as an argument and you call _ex_func from 
provided module?

[julia-users] ANN: CppWrapper C++ wrapping package

2016-02-14 Thread Bart Janssens
Hi all,

The CppWrapper package is meant to facilitate exposing C++ libraries to 
Julia, allowing library authors to write the wrapping code in C++ and 
import to Julia using a one-liner. I think I have now added most of the 
basic features needed to produce simple type wrappings. The detailed 
description can be found at:
https://github.com/barche/CppWrapper

For demonstration and performance-checking purposes, I have also wrapped a 
very limited part of the Eigen matrix library for some given fixed-size 
matrices:
https://github.com/barche/EigenCpp.jl

I'm thinking of submitting a presentation proposal for CppWrapper to 
JuliaCon, so comments and suggestions are most welcome.

Cheers,

Bart


[julia-users] Re: Weird Hygiene Issue

2016-02-14 Thread Lutfullah Tomak
Ok. If it helps there is

current_module()

that may help get arbitrary module you are calling _1ex_func from. if ex_func 
is in that module you can know which module ex_func is defined.

[julia-users] Weird Hygiene Issue

2016-02-14 Thread Lutfullah Tomak
Instead of 
@eval @f ex_func

this
eval(Main, @f ex_func)

might do that. I cannot test what you do with julia 0.5 because functions are 
now very diferent internally.
@eval @f ex_func
will be X.eval(@f ex_func) thus there will be X namespace but not outside of 
the module as shown from macroexpand.

[julia-users] Re: Weird Hygiene Issue

2016-02-14 Thread Julia Tylors
It should be possible, because i am doing it non-generated functions. this 
problem only occurs when i try to generate the function via a macro.

On Sunday, February 14, 2016 at 2:39:35 PM UTC-8, Lutfullah Tomak wrote:
>
> It seems impossible then. What if _1ex_func has a fuction argument then 
> you can pass _ex_func to _1ex_func or module as an argument and you call 
> _ex_func from provided module?



[julia-users] Weird Hygiene Issue

2016-02-14 Thread Julia Tylors
Hi fellows,


I was coding a macro, and I am having a prefix issue with functions.

basically the problem is: Every single one of  available functions 
(_ex_func) which i want to be globally accessible are prefixed with the 
name of the module(X)  in which the macro f is defined


Here is the code example:

julia> module X
export @f
macro f(x)
st = string("_",x)
sy = symbol(st)
esc(quote
function ($sy)()
println("st")
end

function ($(symbol(string("_1",x()
($sy)()
println("sty")
end
export $sy
export $(symbol(string("_1",x)))
end
)
end
@eval @f ex_func
   end
X

julia> using X

julia> _

_1ex_func  __precompile__  _ex_func
julia> _1ex_func.env.defs.func.code
AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin  # none, 
line 12:
*(X._ex_func)() # none, line 13: # i want this to be not prefixed 
by X*
return (X.println)("sty")
end)

julia> macroexpand(:(@f ex_func))
quote  # none, line 7:
function _ex_func() # none, line 8:
println("st")
end # none, line 11:
function _1ex_func() # none, line 12:
*_ex_func() # none, line 13: # it seems OK, here!!!*
println("sty")
end # none, line 15:
export _ex_func # none, line 16:
export _1ex_func
end

as you may see , I may well define _ex_func in other modules and use it 
from the function X._1ex_func().
But this prevents me doing it.

How can i solve this problem?

Thanks


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

2016-02-14 Thread Stefan Karpinski
Seems like a good idea. Thanks for looking into that.

On Sun, Feb 14, 2016 at 12:44 PM,  wrote:

> On Saturday, February 13, 2016 at 1:02:50 PM UTC, Stefan Karpinski wrote:
>>
>> Improvements are welcomed.
>
>
> Hey Stefan. Here's my suggestion:
>
> Until the Grand Overarching Documentation system is available, you could
> do worse than a custom Google search engine. This lets you add a few
> selected sites to index, and you don't therefore have to qualify the search
> with "julia" or "julialang" all the time. (Thus you won't have to keep
> visiting the pages of Julia Lang or seeing fractals all the time...)
>
> I'm not a big fan of the Google, but it doesn't work too bad and I can't
> see too many downsides with having something like this on the main Julia
> site for now.
>
> Here's a quick demo I mocked up. I'm sure someone could do something more
> impressive with the Google Search Engine API (
> https://developers.google.com/custom-search/docs/overview).
>
>
> 
>
>
> It's currently at http://steampiano.net/julia-search/index.html.
>
>


[julia-users] Re: convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread David van Leeuwen
Hello, 

You can use any convention you'd like.  A more type-stable solution is to 
use, e.g., the value `-1` for `something`, but you don't think that is 
elegant.  There is `nothing` (of type Void) but I am not sure that the 
intended use of that is to use as a default in function prototypes. 

---david

On Sunday, February 14, 2016 at 7:31:40 AM UTC+1, Tamas Papp wrote:
>
> Hi, 
>
> Suppose I have a function which reads rows from a file, with an argument 
> max_rows, which would limit the number of rows read, eg 
>
> function parse_file(io; max_rows=something) 
>   row_count = 0 
>   while !eof(io) (max_rows==something || row_count < max_rows) 
> row_count += 1 
> row = readline(io) 
> # ... parse line etc ... 
>   end 
> end 
>
> The question is what value to use for the case when this is not 
> specified, which would also be the default. false and nothing come to 
> mind, also -1 but it doesn't look so elegant. 
>
> R uses FALSE, NULL and sometimes NA for this (very inconsistently), in 
> Common Lisp the convention is to use nil--what's idiomatic for Julia? 
>
> Best, 
>
> Tamas 
>


Re: [julia-users] Re: convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread Tamas Papp
Thanks, I will experiment with nothing and false and see what I like
best. In many languages false is a good choice, for forms like

max && (count < max)

but in Julia this doesn't work, as Ints cannot be used in place of
booleans (which is fine and a sane design choice).

Maybe I misunderstand type stability, but I thought that as long as the
output _type_ is invariant to the argument, the code would be
type-stable. Eg it would not matter if the function reads 15 or 500
rows, if the type is the same.

Best,

Tamas

On Sun, Feb 14 2016, David van Leeuwen wrote:

> Hello, 
>
> You can use any convention you'd like.  A more type-stable solution is to 
> use, e.g., the value `-1` for `something`, but you don't think that is 
> elegant.  There is `nothing` (of type Void) but I am not sure that the 
> intended use of that is to use as a default in function prototypes. 
>
> ---david
>
> On Sunday, February 14, 2016 at 7:31:40 AM UTC+1, Tamas Papp wrote:
>>
>> Hi, 
>>
>> Suppose I have a function which reads rows from a file, with an argument 
>> max_rows, which would limit the number of rows read, eg 
>>
>> function parse_file(io; max_rows=something) 
>>   row_count = 0 
>>   while !eof(io) (max_rows==something || row_count < max_rows) 
>> row_count += 1 
>> row = readline(io) 
>> # ... parse line etc ... 
>>   end 
>> end 
>>
>> The question is what value to use for the case when this is not 
>> specified, which would also be the default. false and nothing come to 
>> mind, also -1 but it doesn't look so elegant. 
>>
>> R uses FALSE, NULL and sometimes NA for this (very inconsistently), in 
>> Common Lisp the convention is to use nil--what's idiomatic for Julia? 
>>
>> Best, 
>>
>> Tamas 
>>



Re: [julia-users] convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread Milan Bouchet-Valat
Le dimanche 14 février 2016 à 07:31 +0100, Tamas Papp a écrit :
> Hi,
> 
> Suppose I have a function which reads rows from a file, with an
> argument
> max_rows, which would limit the number of rows read, eg
> 
> function parse_file(io; max_rows=something)
>   row_count = 0
>   while !eof(io) (max_rows==something || row_count < max_rows)
> row_count += 1
> row = readline(io)
> # ... parse line etc ...
>   end
> end
> 
> The question is what value to use for the case when this is not
> specified, which would also be the default. false and nothing come to
> mind, also -1 but it doesn't look so elegant.
> 
> R uses FALSE, NULL and sometimes NA for this (very inconsistently),
> in Common Lisp the convention is to use nil--what's idiomatic for
> Julia?
Unfortunately there's no convention currently. I think the best
solution would be to use a Nullable. But this is currently quite
inconvenient, as you cannot pass an integer, but need to wrap it in a
Nullable. It's been discussed that keyword arguments should
automatically be converted, in which case one would be able to write
both:
parse_file(io; max_rows::Nullable{Int}=nothing)
and:
parse_file(io, max_rows=10)

For now, max_rows::Union{Int, Void}=nothing or a sentinel integer value
are two reasonable options. But that inconsistency in Julia APIs is
annoying...


Regards


Re: [julia-users] Re: sub-ranges within CartesianRange

2016-02-14 Thread Tim Holy
Ah, now I get what you're trying to do. Glad you figured it out!

Best,
--Tim

On Sunday, February 14, 2016 01:01:07 AM Greg Plowman wrote:
> I created a type that I think more or less works:
> 
> immutable CartesianSubRange{I<:CartesianIndex}
> range::CartesianRange{I}
> start::I
> stop::I
> done::I # one past stop
> 
> function CartesianSubRange(range::CartesianRange{I}, start::I, stop::I)
> item, done = next(range, stop)
> new(range, start, stop, done)
> end
> end
> 
> CartesianSubRange{I<:CartesianIndex}(range::CartesianRange{I}, start::I,
> stop::I) =
> CartesianSubRange{I}(range, start, stop)
> 
> CartesianSubRange{N}(dims::NTuple{N,Int}, start::NTuple{N,Int},
> stop::NTuple{N,Int}) =
> CartesianSubRange(CartesianRange(dims), CartesianIndex(start),
> CartesianIndex(stop))
> 
> Base.start(iter::CartesianSubRange) = iter.start
> Base.next{I}(iter::CartesianSubRange{I}, state::I) = next(iter.range, state)
> Base.done{I}(iter::CartesianSubRange{I}, state::I) = (state == iter.done)
> 
> 
> I can now do something like:
> 
> @everywhere function SubCycleSimulation(csr::CartesianSubRange)
> println(csr.start.I, " - ", csr.stop.I)
> for ci in csr
> #...
> end
> return length(csr)
> end
> 
> dims = (30,34,28,90,44)
> cr = CartesianRange(CartesianIndex(dims))
> cycle = length(cr)
> numSubCycles = nworkers()*10
> subCycleLength = div(cycle, numSubCycles)
> subRanges = Array{CartesianSubRange}(numSubCycles)
> 
> for subCycle = 1:numSubCycles
> cyclePosFrom = (subCycle - 1) * subCycleLength + 1
> cyclePosTo = (subCycle == numSubCycles) ? cycle : subCycle *
> subCycleLength
> start = CartesianIndex(ind2sub(dims, cyclePosFrom))
> stop = CartesianIndex(ind2sub(dims, cyclePosTo))
> subRanges[subCycle] = CartesianSubRange(cr, start, stop)
> end
> 
> results = pmap(SubCycleSimulation, subRanges)



Re: [julia-users] convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread Cedric St-Jean
To guarantee type stability, I sometimes use dynamic dispatch

function parse_file(io; max_rows=nothing)
  row_count = 0
  should_stop(rc, mr::Void) = false
  should_stop(rc, mr::Int) = row_count >= max_rows
  while !eof(io) && !should_stop(row_count, max_rows)
row_count += 1
row = readline(io)
# ... parse line etc ...
  end
end

It's more verbose, though... I suppose one could also use `isa(max_rows, 
Void) || row_count < max_rows`, and it would work as well.


On Sunday, February 14, 2016 at 12:26:20 PM UTC-5, Milan Bouchet-Valat 
wrote:
>
> Le dimanche 14 février 2016 à 07:31 +0100, Tamas Papp a écrit : 
> > Hi, 
> > 
> > Suppose I have a function which reads rows from a file, with an 
> > argument 
> > max_rows, which would limit the number of rows read, eg 
> > 
> > function parse_file(io; max_rows=something) 
> >   row_count = 0 
> >   while !eof(io) (max_rows==something || row_count < max_rows) 
> > row_count += 1 
> > row = readline(io) 
> > # ... parse line etc ... 
> >   end 
> > end 
> > 
> > The question is what value to use for the case when this is not 
> > specified, which would also be the default. false and nothing come to 
> > mind, also -1 but it doesn't look so elegant. 
> > 
> > R uses FALSE, NULL and sometimes NA for this (very inconsistently), 
> > in Common Lisp the convention is to use nil--what's idiomatic for 
> > Julia? 
> Unfortunately there's no convention currently. I think the best 
> solution would be to use a Nullable. But this is currently quite 
> inconvenient, as you cannot pass an integer, but need to wrap it in a 
> Nullable. It's been discussed that keyword arguments should 
> automatically be converted, in which case one would be able to write 
> both: 
> parse_file(io; max_rows::Nullable{Int}=nothing) 
> and: 
> parse_file(io, max_rows=10) 
>
> For now, max_rows::Union{Int, Void}=nothing or a sentinel integer value 
> are two reasonable options. But that inconsistency in Julia APIs is 
> annoying... 
>
>
> Regards 
>


Re: [julia-users] sub-ranges within CartesianRange

2016-02-14 Thread Tim Holy
On Sunday, February 14, 2016 12:55:42 AM Greg Plowman wrote:
> No, not "Cartesian" offsets, but "linear" offsets transformed to Cartesian
> equivalent.
> That's why I think I need the dimensions of the parent range.

You can't do that in general with a cartesian iterator using Julia's for-loop 
syntax. Consider the case where you're iterating over a 5x5 domain, and your 
starting index is 7. You can, however, do this manually using start, done, and 
next.

> As you point out, R here is effectively an empty iterator.
> However for my use, that same range R could be non-empty if it is a
> sub-range of a larger enclosing range.
> Say CartesianSubRange(CartesianRange((8,8,8)), I1, I2))
> So I want to iterate within the parent CartesianRange dimensions, from I1
> to I2.

I guess I don't understand. Can you be explicit about what range that would 
actually produce? I suspect that you're not interpreting I2 as the "stop 
index" but as something else, but I am not having much luck guessing what that 
is.

Best,
--Tim



Re: [julia-users] sub-ranges within CartesianRange

2016-02-14 Thread Tim Holy
The docs on SharedArrays give an example where you partition just over one 
axis (e.g., the 3rd axis). That's easy and tends to work well in many 
applications.

Best,
--Tim

On Sunday, February 14, 2016 12:38:55 AM Greg Plowman wrote:
> On Saturday, February 13, 2016 at 1:57:11 AM UTC+11, Stefan Karpinski wrote:
> > I'm kind of curious what the use case is. How are you using
> > CartesianRanges?
> 
> I want parallelise a simulation iterating over a CartesianRange.
> This entails partitioning the CartesianRange into sub-ranges and calling
> the sim function with each sub-range as an argument, using pmap.
> It's quite easy to use linear indexes to sub-divide into integer intervals,
> but then I need to use ind2sub or equivalent at each iteration, which I
> think is somewhat slower than iterating over a CartesianRange.



[julia-users] convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread Simon Danisch
Why not typemax(Int)? That's also equivalent to all rows, has the same type and 
you don't need to treat it in a special way...

Re: [julia-users] convention for unspecified argument (R's NULL and FALSE, Common Lisp nil)

2016-02-14 Thread Tamas Papp
Thas could work. But consider the signature

function parse_file(io; max_rows=something, sizehint=something)
  # ...
end

where the intention is that if sizehint is given, then use it, otherwise
not. For this typemax(Int) would not be a good choice.

Common Lisp allows a variable for checking if keyword arguments were
actually present, and that may be the cleanest solution, but in Julia
that is not offered. The only solution I see is to use an arbitrary
value (eg nothing, false, -1) and check for that; if there is no
convention at the moment I think I will settle for `nothing` or
`false`.

Best,

Tamas

On Sun, Feb 14 2016, Simon Danisch wrote:

> Why not typemax(Int)? That's also equivalent to all rows, has the same type 
> and you don't need to treat it in a special way...



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

2016-02-14 Thread cormullion
On Saturday, February 13, 2016 at 1:02:50 PM UTC, Stefan Karpinski wrote:
>
> Improvements are welcomed.


Hey Stefan. Here's my suggestion:

Until the Grand Overarching Documentation system is available, you could do 
worse than a custom Google search engine. This lets you add a few selected 
sites to index, and you don't therefore have to qualify the search with 
"julia" or "julialang" all the time. (Thus you won't have to keep visiting 
the pages of Julia Lang or seeing fractals all the time...)

I'm not a big fan of the Google, but it doesn't work too bad and I can't 
see too many downsides with having something like this on the main Julia 
site for now.

Here's a quick demo I mocked up. I'm sure someone could do something more 
impressive with the Google Search Engine API 
(https://developers.google.com/custom-search/docs/overview). 




It's currently at http://steampiano.net/julia-search/index.html.



[julia-users] Re: sub-ranges within CartesianRange

2016-02-14 Thread Greg Plowman
I created a type that I think more or less works:

immutable CartesianSubRange{I<:CartesianIndex}
range::CartesianRange{I}
start::I
stop::I
done::I # one past stop

function CartesianSubRange(range::CartesianRange{I}, start::I, stop::I)
item, done = next(range, stop)
new(range, start, stop, done)
end
end

CartesianSubRange{I<:CartesianIndex}(range::CartesianRange{I}, start::I, 
stop::I) =
CartesianSubRange{I}(range, start, stop)

CartesianSubRange{N}(dims::NTuple{N,Int}, start::NTuple{N,Int}, 
stop::NTuple{N,Int}) =
CartesianSubRange(CartesianRange(dims), CartesianIndex(start), 
CartesianIndex(stop))

Base.start(iter::CartesianSubRange) = iter.start
Base.next{I}(iter::CartesianSubRange{I}, state::I) = next(iter.range, state)
Base.done{I}(iter::CartesianSubRange{I}, state::I) = (state == iter.done)


I can now do something like:

@everywhere function SubCycleSimulation(csr::CartesianSubRange)
println(csr.start.I, " - ", csr.stop.I)
for ci in csr
#...
end
return length(csr)
end

dims = (30,34,28,90,44)
cr = CartesianRange(CartesianIndex(dims))
cycle = length(cr)
numSubCycles = nworkers()*10
subCycleLength = div(cycle, numSubCycles)
subRanges = Array{CartesianSubRange}(numSubCycles)

for subCycle = 1:numSubCycles
cyclePosFrom = (subCycle - 1) * subCycleLength + 1
cyclePosTo = (subCycle == numSubCycles) ? cycle : subCycle * 
subCycleLength
start = CartesianIndex(ind2sub(dims, cyclePosFrom))
stop = CartesianIndex(ind2sub(dims, cyclePosTo))
subRanges[subCycle] = CartesianSubRange(cr, start, stop)
end

results = pmap(SubCycleSimulation, subRanges)






Re: [julia-users] Strange failure running test/unicode/utf8code.jl

2016-02-14 Thread Mauro
Reported here https://github.com/JuliaLang/julia/issues/15072

On Sat, 2016-02-13 at 22:33, Scott Jones  wrote:
> I'm seeing a very strange failure recently (within the last week), where
> running "test/runtests.jl" seems to pass, but running the individual test 
> shows
> a very different result.
> I've reduced it to this, it seems to be a problem with the scope used for s in
> the third line.
>
> let s = "b\u0300lahβlahb\u0302láh",
>   g = ["b\u0300","l","a","h","β","l","a","h","b\u0302","l","á","h"]
>   g_ = map(s -> normalize_string(s, :NFC), g)
>   g0 = map(x -> normalize_string(x, :NFC), g)
>   println(g_)
>   println(g0)
> end
>
>
> I'm rather concerned, because this failure when running test/unicode.jl is
> masked when running test/runtests.jl - could other failures on master be
> getting masked?


Re: [julia-users] Adding a mtrix to the third dimension of a multi-dimensional array

2016-02-14 Thread Dan
>From the help for `cat`:
cat(dims, A...)

  Concatenate the input arrays along the specified dimensions in the 
iterable dims

And indeed, if 
size(M1)=(3,3,3) 
and 
size(M2)=(3,3)
Then,
size(cat(3,M1,M2)) = (3,3,4)

This method may not be efficient (though in terms of memory layout it could 
be).

On Saturday, February 13, 2016 at 1:06:02 PM UTC+2, Mauro wrote:
>
> I think this is not possible.  Instead use a Vector, append! to that and 
> then reshape in the end.  The reshape should result in a view and not a 
> copy, thus will be fast. 
>
> Mauro 
>
> On Sat, 2016-02-13 at 10:51, Vishnu Raj  > wrote: 
> > Hi, 
> > 
> > I have a three dimensional array (say 'z' ) like this : 
> > 
> > julia> z 
> > 4x3x3 Array{Int64,3}: 
> > [:, :, 1] = 
> >  1  5   9 
> >  2  6  10 
> >  3  7  11 
> >  4  8  12 
> > 
> > [:, :, 2] = 
> >  13  17  21 
> >  14  18  22 
> >  15  19  23 
> >  16  20  24 
> > 
> > [:, :, 3] = 
> >  25  29  33 
> >  26  30  34 
> >  27  31  35 
> >  28  32  36 
> > 
> > Now I have a matrix 'z1' as 
> > julia> z1 
> > 4x3 Array{Int64,2}: 
> >  37  41  45 
> >  38  42  46 
> >  39  43  47 
> >  40  44  48 
> > 
> > I want to put z1 at the end of third dimension of 'z'. So that the 
> output 
> > will be like 
> > julia> z[*:,:,4*] 
> > 4x3 Array{Int64,2}: 
> >  37  41  45 
> >  38  42  46 
> >  39  43  47 
> >  40  44  48 
> > 
> > I tried push!() and append!(), both gives me errors. 
> > 
> > Kindly suggest a way to do this. I want 'z' to grow in third dimension 
> as 
> > simulation progresses. 
>


Re: [julia-users] sub-ranges within CartesianRange

2016-02-14 Thread Greg Plowman

On Saturday, February 13, 2016 at 1:57:11 AM UTC+11, Stefan Karpinski wrote:
>
> I'm kind of curious what the use case is. How are you using 
> CartesianRanges?
>
>
I want parallelise a simulation iterating over a CartesianRange.
This entails partitioning the CartesianRange into sub-ranges and calling 
the sim function with each sub-range as an argument, using pmap.
It's quite easy to use linear indexes to sub-divide into integer intervals, 
but then I need to use ind2sub or equivalent at each iteration, which I 
think is somewhat slower than iterating over a CartesianRange.



Re: [julia-users] sub-ranges within CartesianRange

2016-02-14 Thread Greg Plowman
Thanks for your reply Tim.

Are x and y offsets with respect to the "parent" range cr? 
>
> If so, you can achieve this with a 1-liner, 
>
> CartesianRange(cr.start+x-1, cr.start+y-1) 
>

No, not "Cartesian" offsets, but "linear" offsets transformed to Cartesian 
equivalent. 
That's why I think I need the dimensions of the parent range.


julia> I1 = CartesianIndex((3,3,3)) 
> CartesianIndex{3}((3,3,3)) 
>
> julia> I2 = CartesianIndex((5,1,7)) 
> CartesianIndex{3}((5,1,7)) 
>
> julia> R = CartesianRange(I1, I2) 
> CartesianRange{CartesianIndex{3}}(CartesianIndex{3}((3,3,3)),CartesianIndex{3}
>  
>
> ((5,1,7))) 
>
 
As you point out, R here is effectively an empty iterator.
However for my use, that same range R could be non-empty if it is a 
sub-range of a larger enclosing range.
Say CartesianSubRange(CartesianRange((8,8,8)), I1, I2))
So I want to iterate within the parent CartesianRange dimensions, from I1 
to I2.