Re: [julia-users] type generation

2014-09-10 Thread Simon Kornblith
Yup. The reason this works when oVector is a Vector{Float64} is that Julia 
makes a copy in the process of converting it to a Vector{Int} when you 
construct the Cell.

Simon

On Thursday, September 11, 2014 12:53:52 AM UTC-4, John Myles White wrote:
>
> This sure looks like you're not making any copies when you seem to want 
> copies. 
>
> In particular, this line: 
>
> >   cellList[i] = Cell(i, oVector) 
>
> probably needs to be 
>
> >   cellList[i] = Cell(i, copy(oVector)) 
>
>  -- John 
>
> On Sep 10, 2014, at 6:41 PM, Andre Bieler  > wrote: 
>
> > can anyone tell me why the following code does not work as (I) expected? 
> > I have a simple type Cell which only has an index and a origin array. 
> > When creating multiple instances of this Cell type in a loop and 
> assigning 
> > different origin arrays to them, in the end all instances have the same 
> > origin array. I am using julia 0.3 
> > 
> > (It does work if the commented line is un-commented though..) 
> > 
> > 
> > type Cell 
> >   index::Int64 
> >   origin::Array{Int64,1} 
> > end 
> > 
> > nDim = int(3) 
> > nCells = int(2) 
> > 
> > cellList = Array(Cell, nCells) 
> > oVector = Array(Int64, nDim)   # does not work as expected 
> > #oVector = Array(Float64, nDim) # does work 
> > 
> > for i=1:nCells 
> >   for j=1:nDim 
> > oVector[j] = i 
> >   end 
> >   cellList[i] = Cell(i, oVector) 
> > end 
> > 
> > # after the loop, both cells have same origin... 
> > println(cellList[1].index, ": ", cellList[1].origin) 
> > println(cellList[2].index, ": ", cellList[2].origin) 
> > 
> > 
> > thanks in advance 
> > 
> > andre 
>
>

Re: [julia-users] type generation

2014-09-10 Thread John Myles White
This sure looks like you're not making any copies when you seem to want copies.

In particular, this line:

>   cellList[i] = Cell(i, oVector)

probably needs to be

>   cellList[i] = Cell(i, copy(oVector))

 -- John

On Sep 10, 2014, at 6:41 PM, Andre Bieler  wrote:

> can anyone tell me why the following code does not work as (I) expected?
> I have a simple type Cell which only has an index and a origin array.
> When creating multiple instances of this Cell type in a loop and assigning
> different origin arrays to them, in the end all instances have the same
> origin array. I am using julia 0.3
> 
> (It does work if the commented line is un-commented though..)
> 
> 
> type Cell
>   index::Int64
>   origin::Array{Int64,1}
> end
> 
> nDim = int(3)
> nCells = int(2)
> 
> cellList = Array(Cell, nCells)
> oVector = Array(Int64, nDim)   # does not work as expected
> #oVector = Array(Float64, nDim) # does work
> 
> for i=1:nCells
>   for j=1:nDim
> oVector[j] = i
>   end
>   cellList[i] = Cell(i, oVector)
> end
> 
> # after the loop, both cells have same origin...
> println(cellList[1].index, ": ", cellList[1].origin)
> println(cellList[2].index, ": ", cellList[2].origin)
> 
> 
> thanks in advance
> 
> andre



[julia-users] type generation

2014-09-10 Thread Andre Bieler
can anyone tell me why the following code does not work as (I) expected?
I have a simple type Cell which only has an index and a origin array.
When creating multiple instances of this Cell type in a loop and assigning
different origin arrays to them, in the end all instances have the same
origin array. I am using julia 0.3

(It does work if the commented line is un-commented though..)


type Cell
  index::Int64
  origin::Array{Int64,1}
end

nDim = int(3)
nCells = int(2)

cellList = Array(Cell, nCells)
oVector = Array(Int64, nDim)   # does not work as expected
#oVector = Array(Float64, nDim) # does work

for i=1:nCells
  for j=1:nDim
oVector[j] = i
  end
  cellList[i] = Cell(i, oVector)
end

# after the loop, both cells have same origin...
println(cellList[1].index, ": ", cellList[1].origin)
println(cellList[2].index, ": ", cellList[2].origin)


thanks in advance

andre


[julia-users] Rationale for colon quote syntax

2014-09-10 Thread Aubrey Barnard
Julia Users,

I am trying to find out what the rationale is for some of the Julia syntax 
choices, in particular the choice of colon as the quote character. (I think 
knowing the rationale can help those new to the language, like myself, come 
to grips with its syntax.) Is there some discussion or document that you 
can point me to? I searched the issues on GitHub, the julia-dev group, and 
the julia-users group but came back empty-handed.

Thanks for any information or pointers.

Aubrey


Re: [julia-users] Why do bools have functions like abs and sign defined?

2014-09-10 Thread John Myles White
Perhaps these help support the use of Bool as a mechanism for defining im?

 -- John

On Sep 10, 2014, at 8:20 PM, Dan Luu  wrote:

> In bool.jl, there are things like
> 
> signbit(x::Bool) = false
> sign(x::Bool) = x
> abs(x::Bool) = x
> abs2(x::Bool) = x
> 
> Are these because Bool is a subtype of something where you'd expect
> these to be defined, or are these useful in their own right, and if
> so, when would you use these?
> 
> 
> Thanks,
> Dan



[julia-users] Why do bools have functions like abs and sign defined?

2014-09-10 Thread Dan Luu
In bool.jl, there are things like

signbit(x::Bool) = false
sign(x::Bool) = x
abs(x::Bool) = x
abs2(x::Bool) = x

Are these because Bool is a subtype of something where you'd expect
these to be defined, or are these useful in their own right, and if
so, when would you use these?


Thanks,
Dan


Re: [julia-users] How to build Julia in a portable way (for compute farm deployment)?

2014-09-10 Thread Jameson Nash
openblas defaults to detecting the runtime system and picking the best code
to run for that computer.

The recommendation to remove `sys.so` has been deprecated. Setting ARCH /
MARCH is now the preferred solution. (note that core2 is not the least
common denominator, since there exist some AMD chips without some of the
core2 instructions – instead use x86_64 / x86-64)


On Wed, Sep 10, 2014 at 10:17 PM, Glen Hertz  wrote:

> Hi,
>
> I'm trying to deploy Julia to users in a compute farm environment with
> many machines running on different CPUs.  This has been discussed here:
>
>
> https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/make$20dist/julia-users/B8x6CYbFUNY/Ph5Cunhl5EwJ
>
> The recommendation was to use `make dist` which builds a tarball that
> doesn't include `sys.so` and you can move it to any machine.  With the 0.3
> release `make dist` builds `sys.so` so I removed it but the executable is
> still not portable.  What are the most likely steps to build Julia so it
> works on different hardware?  I did something like this (on a RHEL 5.5
> system):
>
> "Make.user":
> FC=gfortran44
> CC=gcc44
> CXX=g++44
> MARCH=core2
> OPENBLAS_TARGET_ARCH=CORE2
>
> (I updated binutils, python and patchelf).
>
> When I run `make dist` it crease a tarball with a `sys.so` so I deleted
> it.  It still segfaults.
>
> It doesn't seem like `OPENBLAS_TARGET_ARCH` is working since
> `versioninfo()` shows it was compiled for `Nehalem`.  Note, to rebuild I
> did:
>
> ```
> cp Make.user ..
> git clean -xdf
> cp ../Make.user .
> make dist
> ```
>
> Please let me know if there is something better I can try out and if I get
> something working I can update the documentation.
>
> Thanks,
>
> Glen
>
>


[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



On 09/10/2014 07:37 PM, Peter Colberg wrote:

On Wed, Sep 10, 2014 at 04:59:08PM -0500, Jimmie Houchin wrote:

After seeing Julia exceed expectations I went back to tests that Lua had
failed. Lua is constrained to a 1GB memory limit unless you do some memory
management via C in C code.


Not that it matters for this comparison, given that LuaJIT is a barebone
dynamically-compiled substitute for C while Julia is a complete solution
for numerical computing, but you can allocate arrays in the entire 64 bit
address space using malloc:

   local ffi = require("ffi")
   ffi.cdef[[
   void *malloc(size_t);
   void free(void *);
   ]]

   local function array(size)
 local x = ffi.cast("double *", ffi.C.malloc(size * ffi.sizeof("double")))
 if x == nil then return error("out of memory") end
 return ffi.gc(x, ffi.C.free)
   end

   local N = 1000
   local x = array(N)
   for i = 0, N-1 do x[i] = math.random() end

Peter


You said that better than I could. I knew it was possible from reading 
the mailing list and reading the docs. But I am not a C programmer, so 
in addition to learning Lua, I would need to learn C in order to do so.


Being a long time Smalltalker, I love rich, full featured environments. 
Lua is nice language but it doesn't have the rich, full featured 
environment (REPL) or an iLua notebook. I could easily use Lua if it 
were the best option. But everytime I open in up it just feels 
impoverished. It makes me sad. There are also language decisions in 
Julia that just feel nice.


It is very nice to reduce the number of times dropping down into C/C++ 
will be required. It is required any time you need to connect to a C/C++ 
library. But hopefully not as often if ever for performance or memory 
management.


Thanks for the info.

Jimmie



[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



On 09/10/2014 05:22 PM, Ivar Nesje wrote:

-Ofast is probably cheating your benchmark

> and doing much less work than what you want in real code.
> Floating point arithmetic is not associative,
> but -Ofast doesn't care, and rewrites
> n*=0.9;n*=0. to n*=(0.999*0.999)
> and precompute the constant.
> That gives a almost equal result much faster,
> but it means that you don't get the same value back.
> It also means that you might get a different result
> if you got 0.999 from a variable, rather than a constant.

I didn't know how exactly it would impact the code. But I wasn't 
planning on relying on it in real code in a real app without having 
sufficient knowledge that it did not negatively affect any of my apps 
operations.


That kind of speed is amazing to watch, but not a requirement for 
anything I am doing.


Julia's performance is more than sufficient with some liberty.

Jimmie




[julia-users] How to build Julia in a portable way (for compute farm deployment)?

2014-09-10 Thread Glen Hertz
Hi,

I'm trying to deploy Julia to users in a compute farm environment with many 
machines running on different CPUs.  This has been discussed here:

https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/make$20dist/julia-users/B8x6CYbFUNY/Ph5Cunhl5EwJ

The recommendation was to use `make dist` which builds a tarball that 
doesn't include `sys.so` and you can move it to any machine.  With the 0.3 
release `make dist` builds `sys.so` so I removed it but the executable is 
still not portable.  What are the most likely steps to build Julia so it 
works on different hardware?  I did something like this (on a RHEL 5.5 
system):

"Make.user":
FC=gfortran44
CC=gcc44
CXX=g++44
MARCH=core2
OPENBLAS_TARGET_ARCH=CORE2

(I updated binutils, python and patchelf).

When I run `make dist` it crease a tarball with a `sys.so` so I deleted it. 
 It still segfaults.  

It doesn't seem like `OPENBLAS_TARGET_ARCH` is working since 
`versioninfo()` shows it was compiled for `Nehalem`.  Note, to rebuild I 
did:

```
cp Make.user ..
git clean -xdf
cp ../Make.user .
make dist
```

Please let me know if there is something better I can try out and if I get 
something working I can update the documentation.  

Thanks,

Glen



Re: [julia-users] About OpenCV-Julia binding

2014-09-10 Thread Patrick O'Leary
I believe the Python dependency is just in wrapper generation--it wouldn't 
be in play at runtime.

On Wednesday, September 10, 2014 7:06:22 PM UTC-5, Max Suster wrote:
>
>
> +1  
>
> I agree that it would be better to have at least a wrapper available with 
> python dependency than none at all.  However, I am wondering though what is 
> the cost on speed of using this python dependency.  A major feature that 
> makes me interested in Julia is the speed over languages like Ruby, 
> especially necessary for real-time image processing applications (high 
> frame rates). 
>
>
> On Wednesday, September 10, 2014 6:09:34 PM UTC+2, Kevin Squire wrote:
>>
>> While I also hope that native Julia solutions move forward, I would also 
>> find the OpenCV bindings quite useful, so +1!  I also second the suggestion 
>> to use the existing python infrastructure. 
>>
>> Cheers,
>>   Kevin
>>
>> On Wednesday, September 10, 2014, Boxiang Sun  wrote:
>>
>>> Hi Jake,
>>>
>>> Thanks for your comment!
>>>
>>> Use the exist Python header parser could save a lot of work. I will be 
>>> glad to accept it. If other friends believe the dependency of Python is not 
>>> a problem, too. Then I will write the the type conversion first(Mat, etc), 
>>> like Java binding did(../modules/java/generator).
>>>
>>> Regards,
>>> Sun
>>>
>>> 在 2014年9月10日星期三UTC+8上午10时29分48秒,Jake Bolewski写道:

 Hi Boxiang,

 I'm excited that you are working on this.  The one comment I would have 
 is don't rewrite the custom header parser.  It is maintained as part of 
 the 
 official build system in OpenCV and will be maintained.  All the 
 "official" 
 OpenCV bindings depend on it.  It is awkward to write python code to emit 
 Julia code, but I feel you will save so much time in the end and have a 
 chance of getting it into OpenCV core in the future if you reuse their 
 infrastructure. 

 Best,
 Jake


 On Tuesday, September 9, 2014 10:08:43 PM UTC-4, Boxiang Sun wrote:
>
> Hi all,
>
> Before the Google Summer of Code 2014, I proposed a proposal about 
> OpenCV-Julia binding. But at last, I was accepted by another project. Now 
> I 
> am successfully accomplished the GSoC. With the help of Tim Holy, I am 
> restarted the OpenCV-Julia binding. Tim just send me a link: 
> https://github.com/JuliaLang/julia/issues/8288. And I think I need to 
> let people know there has a project about OpenCV-Julia binding.
>
> During the time that I talk to Tim Holy, and my own research. I have 
> some results, please allow me to introduce the status of the binding.
>
> I am wrapped some basic API manually and tested it. Try to find a 
> correct mechanism of the binding. Now my plan is like OpenCV-Python 
> binding 
> did: 
>
> *Extract OpenCV API, like the hdr_parser.py did in OpenCV-Python 
> binding. But rewrite the header parser with Julia(We don't want 
> OpenCV-Julia has dependency of Python, do we?). Another reason is the 
> output of hdr_parser.py is not perfect for Julia wrapper.
> *Write automatic generation tool to wrap OpenCV API base on the output 
> of header parser. Generate the wrapped API, the wrapped API could build a 
> shared lib, just like OpenCV-Python did.
>
> I will continue try to wrap more API manually today. Then try to write 
> the header parser in Julia. That is the recently plan.
>
> Some details, such as memory management, interactive between 
> OpenCV-Julia binding and Image/Array, and other things, not decide yet.
>
> Any comments or suggestions will be highly appreciated!
>
> Regards,
> Sun
>


Re: [julia-users] Re: Array Performance

2014-09-10 Thread Peter Colberg
On Wed, Sep 10, 2014 at 04:59:08PM -0500, Jimmie Houchin wrote:
> After seeing Julia exceed expectations I went back to tests that Lua had
> failed. Lua is constrained to a 1GB memory limit unless you do some memory
> management via C in C code.

Not that it matters for this comparison, given that LuaJIT is a barebone
dynamically-compiled substitute for C while Julia is a complete solution
for numerical computing, but you can allocate arrays in the entire 64 bit
address space using malloc:

  local ffi = require("ffi")
  ffi.cdef[[
  void *malloc(size_t);
  void free(void *);
  ]]

  local function array(size)
local x = ffi.cast("double *", ffi.C.malloc(size * ffi.sizeof("double")))
if x == nil then return error("out of memory") end
return ffi.gc(x, ffi.C.free)
  end

  local N = 1000
  local x = array(N)
  for i = 0, N-1 do x[i] = math.random() end

Peter


Re: [julia-users] About OpenCV-Julia binding

2014-09-10 Thread Max Suster

+1  

I agree that it would be better to have at least a wrapper available with 
python dependency than none at all.  However, I am wondering though what is 
the cost on speed of using this python dependency.  A major feature that 
makes me interested in Julia is the speed over languages like Ruby, 
especially necessary for real-time image processing applications (high 
frame rates). 


On Wednesday, September 10, 2014 6:09:34 PM UTC+2, Kevin Squire wrote:
>
> While I also hope that native Julia solutions move forward, I would also 
> find the OpenCV bindings quite useful, so +1!  I also second the suggestion 
> to use the existing python infrastructure. 
>
> Cheers,
>   Kevin
>
> On Wednesday, September 10, 2014, Boxiang Sun  > wrote:
>
>> Hi Jake,
>>
>> Thanks for your comment!
>>
>> Use the exist Python header parser could save a lot of work. I will be 
>> glad to accept it. If other friends believe the dependency of Python is not 
>> a problem, too. Then I will write the the type conversion first(Mat, etc), 
>> like Java binding did(../modules/java/generator).
>>
>> Regards,
>> Sun
>>
>> 在 2014年9月10日星期三UTC+8上午10时29分48秒,Jake Bolewski写道:
>>>
>>> Hi Boxiang,
>>>
>>> I'm excited that you are working on this.  The one comment I would have 
>>> is don't rewrite the custom header parser.  It is maintained as part of the 
>>> official build system in OpenCV and will be maintained.  All the "official" 
>>> OpenCV bindings depend on it.  It is awkward to write python code to emit 
>>> Julia code, but I feel you will save so much time in the end and have a 
>>> chance of getting it into OpenCV core in the future if you reuse their 
>>> infrastructure. 
>>>
>>> Best,
>>> Jake
>>>
>>>
>>> On Tuesday, September 9, 2014 10:08:43 PM UTC-4, Boxiang Sun wrote:

 Hi all,

 Before the Google Summer of Code 2014, I proposed a proposal about 
 OpenCV-Julia binding. But at last, I was accepted by another project. Now 
 I 
 am successfully accomplished the GSoC. With the help of Tim Holy, I am 
 restarted the OpenCV-Julia binding. Tim just send me a link: 
 https://github.com/JuliaLang/julia/issues/8288. And I think I need to 
 let people know there has a project about OpenCV-Julia binding.

 During the time that I talk to Tim Holy, and my own research. I have 
 some results, please allow me to introduce the status of the binding.

 I am wrapped some basic API manually and tested it. Try to find a 
 correct mechanism of the binding. Now my plan is like OpenCV-Python 
 binding 
 did: 

 *Extract OpenCV API, like the hdr_parser.py did in OpenCV-Python 
 binding. But rewrite the header parser with Julia(We don't want 
 OpenCV-Julia has dependency of Python, do we?). Another reason is the 
 output of hdr_parser.py is not perfect for Julia wrapper.
 *Write automatic generation tool to wrap OpenCV API base on the output 
 of header parser. Generate the wrapped API, the wrapped API could build a 
 shared lib, just like OpenCV-Python did.

 I will continue try to wrap more API manually today. Then try to write 
 the header parser in Julia. That is the recently plan.

 Some details, such as memory management, interactive between 
 OpenCV-Julia binding and Image/Array, and other things, not decide yet.

 Any comments or suggestions will be highly appreciated!

 Regards,
 Sun

>>>

[julia-users] Re: Array Performance

2014-09-10 Thread Ivar Nesje
-Ofast is probably cheating your benchmark and doing much less work than what 
you want in real code. Floating point arithmetic is not associative, but -Ofast 
doesn't care, and rewrites n*=0.9;n*=0. to n*=(0.999*0.999) 
and precompute the constant. That gives a almost equal result much faster, but 
it means that you don't get the same value back. It also means that you might 
get a different result if you got 0.999 from a variable, rather than a 
constant. 


[julia-users] ANN: ApproxFun v0.0.3 with general linear PDE solving on rectangles

2014-09-10 Thread Sheehan Olver

This is to announce a new version of ApproxFun 
(https://github.com/dlfivefifty/ApproxFun.jl), a package for approximating 
functions.  The biggest new feature is support for PDE solving.  The 
following lines solve Helmholtz equation u_xx + u_yy + 100 u = 0 with the 
solution held to be one on the boundary:

d=Interval()⊗Interval()# the domain to solve is a rectangle

u=[dirichlet(d),lap(d)+100I]\ones(4)   # first 4 entries are boundary 
conditions, further entries are assumed zero
contour(u) # contour plot of the solution, requires 
GadFly

PDE solving is based on a recent preprint with Alex Townsend 
(http://arxiv.org/abs/1409.2789).   Only splitting rank 2 PDEs are 
implemented at the moment.  Examples included are:

"examples/RectPDE Examples.ipynb": Poisson equation, Wave equation, 
linear KdV, semiclassical Schrodinger equation with a potential, and 
convection/convection-diffusion equations. 
"examples/Wave and Klein–Gordon equation on a square.ipynb": On-the-fly 
3D simulation of time-evolution PDEs on a square.  Requires GLPlot.jl 
(https://github.com/SimonDanisch/GLPlot.jl).   
"examples/Manipulate Helmholtz.upynb": On-the-fly variation of 
Helmholtz frequency.  Requires Interact.jl 
(https://github.com/JuliaLang/Interact.jl)

Another new feature is faster root finding, thanks to Alex.


[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



No I have not. I had read the mailing list and a fair portion of the 
website and knew that Julia had performance potential. I like what I saw 
in the language a lot.


I simply wanted to test it against the other tests that I had run to see 
if it was in the ballpark of my other dynamic language option Lua 
(Luajit). If it was, then I already had a preference toward the Julia 
language if the cost of using it wasn't to high.


My initial test put Julia way to expensive to use. I just thought I must 
be doing something no idiomatic to Julia but could not see what that 
was. So before I ruled Julia out, I wanted to give the community an 
opportunity to educate me if I had something wrong that would make Julia 
perform better.


They did, and it did. From my cursory look, Julia was a winner on so 
many other fronts that I was/am willing to take some performance hit if 
necessary. It should be well sufficient for the task.


After seeing Julia exceed expectations I went back to tests that Lua had 
failed. Lua is constrained to a 1GB memory limit unless you do some 
memory management via C in C code.


So far I have tested Julia with a 1 billion element array which used 
7.6GB of memory. It kept up with C++, no problem. The only cost above 
C++ was about 80mb of memory.


Now C++ runs away if I use the -Ofast flag during compilation. I haven't 
spent anytime looking at Julia's optimization abilities.


Lots of writing to say, no I haven't tried @inbounds yet.

No time to read the manual and the docs and learn Julia.

Thanks.

Jimmie


On 09/10/2014 04:33 PM, Emilio Silva wrote:

Did you try @inbounds?

On Wednesday, September 10, 2014 2:15:33 PM UTC-3, Jimmie Houchin wrote:

Hello,

Thanks for the rapid reply Stefan and Isaiah. Great community!!!

7.2million elements
Julia 0.3  18.9 seconds and 113mb ram
C++18.5 seconds, 58.6mb ram

100million elements
Julia 0.3 263.27 and 821mb ram
C++ -O3   264 seconds and 764mb ram
C++ -O3 -Ofast   17.3 seconds and 764mb ram

Wow!!! That is what I hoped for. Feels like a whole different test.

I believe I may have just found home. :)

 Another Big Snip -- see original post



On 09/10/2014 11:03 AM, Stefan Karpinski wrote:
 > Wrap it in a function – global scope is slow.
 >
 >> On Sep 10, 2014, at 5:55 PM, Jimmie Houchin
>
wrote:
 >>
 >>
 >> Big Snip -- see original post
 >> Jimmie








[julia-users] Re: Suprises with for loops

2014-09-10 Thread Wilfred Hughes
On Monday, 8 September 2014 14:54:50 UTC+1, Tony Fong wrote:
>
> @snotskie looped me into this discussion in the context of Lint
>
> I have updated Lint.jl (v0.1.1) to give warnings over
> * for-loop when the iterable is just a literal number
> * nested vcat, i.e.[[1,2],[3,4]]. Other array formats are unaffected since 
> their ASTs are distinct.
>
> Tony
>

That's a definite help. Would it be worth (or feasible) generalising to 
integer variables too? It wouldn't help in the sample function I gave, but 
you could catch cases like:

julia> function sumto(n :: Int)
   total = 0
   for i in n
   total = total + i
   end
   return total
   end

I'd be really interested in seeing an example where this behaviour makes 
code nicer. If an integer value can be seen as an array of length zero, is 
there something special about numeric arrays? Given an array of arbitrary 
type T, should a user always expect that values of type T are iterable?

If there's any interest, I'd be interested in writing a PR to change this 
behaviour, as an excuse to familiarise myself with Julia's internals.

Wilfred


[julia-users] Re: Array Performance

2014-09-10 Thread Emilio Silva
Did you try @inbounds?

On Wednesday, September 10, 2014 2:15:33 PM UTC-3, Jimmie Houchin wrote:
>
>
>
> Hello, 
>
> Thanks for the rapid reply Stefan and Isaiah. Great community!!! 
>
> 7.2million elements 
> Julia 0.3  18.9 seconds and 113mb ram 
> C++18.5 seconds, 58.6mb ram 
>
> 100million elements 
> Julia 0.3 263.27 and 821mb ram 
> C++ -O3   264 seconds and 764mb ram 
> C++ -O3 -Ofast   17.3 seconds and 764mb ram 
>
> Wow!!! That is what I hoped for. Feels like a whole different test. 
>
> I believe I may have just found home. :) 
>
> I am a long Python user(player). 
> I am also a long time Smalltalker (Squeak and Pharo). 
>
> Smalltalk has generally been my favorite language. I thought I was going 
> to have to drop to C++ for my app. I do need C++/C interop for libraries 
> to connect to the broker. I haven't learned C++ yet. I have only started 
> to learn. But I prefer a more dynamic environment to use and explore. 
>
> Julia's design goals is just the sweet spot for what I want. And as a 
> long time Smalltalker, 1 based arrays are just right. :) 
>
> The REPL provides nice functionality that I want for nice exploratory 
> environment. Not quite what I get in Smalltalk, but with iJulia it is 
> very nice. 
>
> Running this from the commandline via 
> julia -i julia_arraytest.jl 
>
> Runs the test just fine. But it does not leave up an interactive 
> session. It runs and closes. I don't know if I am doing something wrong 
> or if this is a known issue. I haven't looked. 
>
> Again thanks for the help and a great language. 
>
> Jimmie 
>
>
>
> On 09/10/2014 11:03 AM, Stefan Karpinski wrote: 
> > Wrap it in a function – global scope is slow. 
> > 
> >> On Sep 10, 2014, at 5:55 PM, Jimmie Houchin <
> jlhouchin-re5jqeeqqe8avxtiumw...@public.gmane.org > wrote: 
> >> 
> >> 
> >> Big Snip -- see original post 
> >> Jimmie 
>
>
>
>

Re: [julia-users] Best way to flatten an 2D array of Array{T, 2} into a single 2D array

2014-09-10 Thread Yuri Vishnevsky
Thanks for the recommendation. 

-- Yuri

On Wednesday, September 10, 2014 4:30:13 AM UTC-4, Tim Holy wrote:
>
> Your approach is fine, but maybe easier is to use ImageView's canvas grid, 
> and 
> then you can use write_to_png(cg, filename). 
>
> --Tim 
>
> On Tuesday, September 09, 2014 07:16:04 PM Yuri Vishnevsky wrote: 
> > Hi all, 
> > 
> > I'm writing code to take a bunch of images and concatenate them into one 
> > big image (you can see the attached picture for an example of what this 
> can 
> > look like). 
> > 
> > The code I wrote to generate the above picture is fairly hideous; I 
> arrived 
> > at it after trying a number of approaches that seemed more natural and 
> then 
> > giving up in despair. 
> > 
> > The code I initially wanted to write looked something like this: 
> > 
> > 
> > grid = Char[ 
> > 'A' 'B' 'C' 'D' 'E'; 
> > 'F' 'G' 'H' 'I' 'J'; 
> > 'K' 'L' 'M' 'N' 'O'; 
> > 'P' 'Q' 'R' 'S' 'T'; 
> > 'U' 'V' 'W' 'X' 'Y'; 
> > 'Z'  0   0   0   0 ; 
> > ] 
> > 
> > arr = map(c -> c == 0 ? zeros(Ufixed8, 64, 64) : convert(Array, 
> > imread("$prefix/sdf/$c.png")), grid) 
> > imwrite(arr, "$prefix/atlas.png") 
> > 
> > This approach fails in imwrite because the individual elements in the 
> array 
> > are themselves arrays, rather than numbers. I couldn't figure out a way 
> to 
> > flatten the resulting array-of-arrays into a single matrix and ended up 
> > writing code that preallocates a big matrix of the right output size and 
> > assigns to calculated subranges in a loop. 
> > 
> > My background is in user interface design and web programming, and right 
> > now I'm fairly new to writing matrix-manipulation code. If there's a 
> > natural way to express this computation in Julia I'd love to know. 
> > 
> > Cheers, 
> > Yuri 
>
>

Re: [julia-users] Re: [ANN] Yelp.jl package

2014-09-10 Thread Randy Zwitch
Ah, I missed that. You're certainly more elegant than I am in Julia. :)

On Wednesday, September 10, 2014 3:13:32 PM UTC-4, Jacob Quinn wrote:
>
> It does. See here 
> 
> .
> ​
>
> On Wed, Sep 10, 2014 at 2:35 PM, Randy Zwitch  > wrote:
>
>> Nice. Does Yelp not require sorting the parameters in alphabetical order 
>> like Twitter?
>>
>>
>> On Wednesday, September 10, 2014 1:57:43 PM UTC-4, Jacob Quinn wrote:
>>>
>>> Hey everyone,
>>>
>>> If anyone else needs access to the Yelp API, I put together a small 
>>> package that interfaces. It supports both the search and business version 
>>> 2.0 APIs. Feel free to check it out.
>>>
>>> A thanks to Randy Zwitch and his Twitter.jl package for the quick and 
>>> dirty OAuth code to get this up and running.
>>>
>>> https://github.com/quinnj/Yelp.jl
>>>
>>> -Jacob
>>>
>>
>

[julia-users] How to use plan_fft

2014-09-10 Thread Jim Christoff
I have used Jullia's default fft for several months and have had no 
problems. I recently decided to try  plan_fft to improve performance.
I seem to a problem using the plan_fft method. Any help would be 
appreciated.

data is a 2d complex Nu by Nt array
The following is one of many attempts:


p = plan_fft(data,Nu,Nt,MEASURE)
GG= p(data)


Re: [julia-users] Re: [ANN] Yelp.jl package

2014-09-10 Thread Jacob Quinn
It does. See here

.
​

On Wed, Sep 10, 2014 at 2:35 PM, Randy Zwitch 
wrote:

> Nice. Does Yelp not require sorting the parameters in alphabetical order
> like Twitter?
>
>
> On Wednesday, September 10, 2014 1:57:43 PM UTC-4, Jacob Quinn wrote:
>>
>> Hey everyone,
>>
>> If anyone else needs access to the Yelp API, I put together a small
>> package that interfaces. It supports both the search and business version
>> 2.0 APIs. Feel free to check it out.
>>
>> A thanks to Randy Zwitch and his Twitter.jl package for the quick and
>> dirty OAuth code to get this up and running.
>>
>> https://github.com/quinnj/Yelp.jl
>>
>> -Jacob
>>
>


[julia-users] Re: [ANN] Yelp.jl package

2014-09-10 Thread Randy Zwitch
Nice. Does Yelp not require sorting the parameters in alphabetical order 
like Twitter?

On Wednesday, September 10, 2014 1:57:43 PM UTC-4, Jacob Quinn wrote:
>
> Hey everyone,
>
> If anyone else needs access to the Yelp API, I put together a small 
> package that interfaces. It supports both the search and business version 
> 2.0 APIs. Feel free to check it out.
>
> A thanks to Randy Zwitch and his Twitter.jl package for the quick and 
> dirty OAuth code to get this up and running.
>
> https://github.com/quinnj/Yelp.jl
>
> -Jacob
>


[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



Thanks. That does exactly what I wanted.


On 09/10/2014 12:19 PM, g wrote:

I think you want julia -L julia_arraytest.jl if you want the REPL to
start in the state resulting from running the script.

On Wednesday, September 10, 2014 10:00:13 AM UTC-6, Jimmie Houchin wrote:

Big Snip -- see original post

Jimmie






[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



Thanks for the code. I see some new code to try.

Jimmie

On 09/10/2014 12:12 PM, Jay Kickliter wrote:

After wrapping your code
 in a
function, as Stefan suggested:

elapsed time: 20.622407406 seconds (91480 bytes allocated)

This is on a 2008 Mac Pro with an 8-core Xeon. It will probably
noticeably faster on your i7.


On Wednesday, September 10, 2014 10:00:13 AM UTC-6, Jimmie Houchin wrote:


> Big Snip -- see original post

Jimmie






Re: [julia-users] Failed attempt to publish a package

2014-09-10 Thread Ed Scheinerman
Thank you for these detailed instructions. I *think* I've done all the
steps correctly.

On Mon, Sep 8, 2014 at 4:32 PM, Isaiah Norton 
wrote:

>
> But I don't understand what to do or what this exactly means.
>
>
> I thought we had a guide for this somewhere, but I can't find it right
> now. So here is a quick shot at outlining the steps.
>
> Right now the git commit representing that "Tag 0.0.1" message in your
> output log only lives on your own computer. By "forking" the main METADATA
> repository, you can create a personal copy (of METADATA.jl) under your
> GitHub account. Once that copy exists, you can push your local changes to
> your copy (just like any other GitHub project). The trick is that GitHub
> keeps track of the difference between your fork and the master repository,
> and provides a nice button to make a request to merge your changes. That's
> all a pull request is. There are also some buttons for METADATA admins to
> merge those changes, which makes the workflow convenient all around and
> also facilitates some nice things like automatic testing integration.
>
> 1) go to http://github.com/JuliaLang/METADATA.jl and create your own fork:
>
> [image: Inline image 1]
> This will create a personal clone of the METADATA repository under your
> github account, so that you can commit to it.
>
> 2) add your fork as a remote repository for the METADATA repository on
> your local computer (in the terminal):
>
> # cd /Users/ers/.julia/METADATA
> # git remote add ers *https://github.com/scheinerman/METADATA.jl.git
> *
>
> 3) push your changes to your fork:
>
> # git push ers metadata-v2
>
> 4) If all of that works, then go back to the GitHub page for your fork,
> and click the "pull request" link:
>
> [image: Inline image 2]
>
> The next page should show a preview of the changes, which should only
> include the single commit with the message "Tag 0.0.1", and then a "Create
> Pull Request" button at the bottom on the page.
>
>
> On Mon, Sep 8, 2014 at 3:39 PM, Ed Scheinerman <
> edward.scheiner...@gmail.com> wrote:
>
>> I tried following the instructions here:
>> http://docs.julialang.org/en/release-0.3/manual/packages/#publishing-your-package
>> to publish my "Permutations" module (available here: 
>> https://github.com/scheinerman/Permutations.jl
>> )
>>
>> Here's the output I got:
>>
>> julia> Pkg.publish()
>> INFO: Validating METADATA
>> INFO: Pushing Permutations permanent tags: v0.0.1
>> Permission denied (publickey).
>> fatal: Could not read from remote repository.
>>
>> Please make sure you have the correct access rights
>> and the repository exists.
>> ERROR: failed process: Process(`git
>> --work-tree=/Users/ers/.julia/v0.3/Permutations
>> --git-dir=/Users/ers/.julia/v0.3/Permutations/.git push -q origin
>> refs/tags/v0.0.1:refs/tags/v0.0.1`, ProcessExited(128)) [128]
>>  in wait at
>> /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
>> (repeats 2 times)
>>  in wait at task.jl:48
>>  in sync_end at
>> /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
>>  in publish at pkg/entry.jl:319
>>  in anonymous at pkg/dir.jl:28
>>  in cd at
>> /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
>>  in __cd#227__ at
>> /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
>>  in publish at pkg.jl:57
>>
>> Help!? Thanks.
>>
>> PS I did read this on the Julia documentation page:
>>
>> For various reasons Pkg.publish() sometimes does not succeed. In those
>> cases, you may make a pull request on GitHub, which is not difficult.
>>
>> But I don't understand what to do or what this exactly means.
>>
>>
>>
>>
>


-- 
Ed Scheinerman (e...@scheinerman.net)


[julia-users] [ANN] Yelp.jl package

2014-09-10 Thread Jacob Quinn
Hey everyone,

If anyone else needs access to the Yelp API, I put together a small package 
that interfaces. It supports both the search and business version 2.0 APIs. 
Feel free to check it out.

A thanks to Randy Zwitch and his Twitter.jl package for the quick and dirty 
OAuth code to get this up and running.

https://github.com/quinnj/Yelp.jl

-Jacob


[julia-users] Re: help with bounds in NLopt

2014-09-10 Thread Jude
Thanks! 

On Wednesday, September 10, 2014 5:47:15 PM UTC+1, Steven G. Johnson wrote:
>
> On Wednesday, September 10, 2014 10:12:39 AM UTC-4, Jude wrote:
>>
>> In my model I iterate over a lot of different values and solve a 
>> constrained optimisation problem but for some values of my lower and upper 
>> bounds I get an error saying "invalid NLopt arguments". I am not sure why 
>> as my lower bound is < upper bound in all the iterations. I tried to 
>> understand this using a more simple example such as the following but even 
>> for this simple example if I set the bounds to (1,100) it's fine but if I 
>> use (2,100) I get the same error. Why is this?:
>>
>
>  You get an error with (2,100) because your initial guess (1) is outside 
> of the bounds.  As long as you have an initial guess that is inside the 
> bounds, your example code works for me.
>


[julia-users] Re: Array Performance

2014-09-10 Thread ggggg
I think you want julia -L julia_arraytest.jl if you want the REPL to start 
in the state resulting from running the script.

On Wednesday, September 10, 2014 10:00:13 AM UTC-6, Jimmie Houchin wrote:
>
> Hello, 
>
> I am working on an app which will be doing analysis on a lot of 
> numerical data. Julia seems perfect for the job. However I wanted to do 
> a simple test that I have run on a few languages to see where I wanted 
> to land. 
>
> Yes, I understand benchmarks, micro-benchmarks are evil. But I needed to 
> see a little on how the languages performed in cpu, time and memory. 
>
> Basically I have two almost identical test differing only in how large 
> the array is that I am operating over. One is 100million items, the 
> other 7.2million items. The reason for the two test is I am expecting at 
> the start the 7.2m to be more normative, but I want to test towards some 
> upper bounds. Some languages I can't do the 100m because the reach 
> memory constraints. 
>
> The array is simply populated with doubles or Float64 in Julia's case. 
>
> In the test I iterate over the array, do some calculations assign back 
> into the array. The calculations are simple calculations which can be 
> reasonably consistent across languages. I do this iteration over the 
> array 100 times. 
>
> Hardware, Laptop, 3rd Gen, i7, 12GB Ram 
> Lubuntu 14.10, running Openbox only, not Lubuntu DE 
>
> Julia  --  Version 0.3.1-pre+4720 
>
> a = Array(Float64, 720) 
>
> # populate array with some data 
> for i = 1:length(a) 
>n = i * 0.9 
>if n>100 
>  n-=(n-n/100.0) 
>end 
>a[i]= n*n*n 
> end 
>
> println("$(a[1]), $(a[end])") 
>
> for i = 1:100 
>t=time() 
>for j = 1:length(a) 
>  n = a[j] * 0.9 + (a[j]+1.0) / 0.999 
>  n*=0.9 
>  n*=0.9 
>  n*=0.9 
>  n/=0.999 
>  n/=0.999 
>  n/=0.999 
>  if n>100 
>n-=(n-n/100.0) 
>  end 
>  a[j]= n 
>end 
>println("loop number $i $(a[1]), $(a[end]), $(time()-t)") 
> end 
>
> With an array of 7.2m the test times are: 
> C++11 gcc4.9  18.5 seconds, 58.6mb ram 
> Java openjdk7 18.8 seconds, 77.5mb ram 
> Julia  0.3.1  675 seconds, 156mb ram 
> Luajit 5.122.3 seconds, 67mb ram 
>
> I didn't necessarily expect Julia to match or beat C++. But I did hope 
> it would be more comparable. 
>
> Am I doing something wrong? Is my code not good Julia or idiomatic 
> Julia. Or is this simply where Julia is at this point in time? 
>
> Any help, understanding or wisdom greatly appreciated. 
>
> Thanks. 
>
> Jimmie 
>
>

[julia-users] Re: Array Performance

2014-09-10 Thread Jimmie Houchin



Hello,

Thanks for the rapid reply Stefan and Isaiah. Great community!!!

7.2million elements
Julia 0.3  18.9 seconds and 113mb ram
C++18.5 seconds, 58.6mb ram

100million elements
Julia 0.3 263.27 and 821mb ram
C++ -O3   264 seconds and 764mb ram
C++ -O3 -Ofast   17.3 seconds and 764mb ram

Wow!!! That is what I hoped for. Feels like a whole different test.

I believe I may have just found home. :)

I am a long Python user(player).
I am also a long time Smalltalker (Squeak and Pharo).

Smalltalk has generally been my favorite language. I thought I was going 
to have to drop to C++ for my app. I do need C++/C interop for libraries 
to connect to the broker. I haven't learned C++ yet. I have only started 
to learn. But I prefer a more dynamic environment to use and explore.


Julia's design goals is just the sweet spot for what I want. And as a 
long time Smalltalker, 1 based arrays are just right. :)


The REPL provides nice functionality that I want for nice exploratory 
environment. Not quite what I get in Smalltalk, but with iJulia it is 
very nice.


Running this from the commandline via
julia -i julia_arraytest.jl

Runs the test just fine. But it does not leave up an interactive 
session. It runs and closes. I don't know if I am doing something wrong 
or if this is a known issue. I haven't looked.


Again thanks for the help and a great language.

Jimmie



On 09/10/2014 11:03 AM, Stefan Karpinski wrote:

Wrap it in a function – global scope is slow.


On Sep 10, 2014, at 5:55 PM, Jimmie Houchin 
 wrote:


Big Snip -- see original post
Jimmie






[julia-users] Re: Array Performance

2014-09-10 Thread Jay Kickliter
After wrapping your code 
 in a function, 
as Stefan suggested:

elapsed time: 20.622407406 seconds (91480 bytes allocated)

This is on a 2008 Mac Pro with an 8-core Xeon. It will probably noticeably 
faster on your i7. 


On Wednesday, September 10, 2014 10:00:13 AM UTC-6, Jimmie Houchin wrote:
>
> Hello, 
>
> I am working on an app which will be doing analysis on a lot of 
> numerical data. Julia seems perfect for the job. However I wanted to do 
> a simple test that I have run on a few languages to see where I wanted 
> to land. 
>
> Yes, I understand benchmarks, micro-benchmarks are evil. But I needed to 
> see a little on how the languages performed in cpu, time and memory. 
>
> Basically I have two almost identical test differing only in how large 
> the array is that I am operating over. One is 100million items, the 
> other 7.2million items. The reason for the two test is I am expecting at 
> the start the 7.2m to be more normative, but I want to test towards some 
> upper bounds. Some languages I can't do the 100m because the reach 
> memory constraints. 
>
> The array is simply populated with doubles or Float64 in Julia's case. 
>
> In the test I iterate over the array, do some calculations assign back 
> into the array. The calculations are simple calculations which can be 
> reasonably consistent across languages. I do this iteration over the 
> array 100 times. 
>
> Hardware, Laptop, 3rd Gen, i7, 12GB Ram 
> Lubuntu 14.10, running Openbox only, not Lubuntu DE 
>
> Julia  --  Version 0.3.1-pre+4720 
>
> a = Array(Float64, 720) 
>
> # populate array with some data 
> for i = 1:length(a) 
>n = i * 0.9 
>if n>100 
>  n-=(n-n/100.0) 
>end 
>a[i]= n*n*n 
> end 
>
> println("$(a[1]), $(a[end])") 
>
> for i = 1:100 
>t=time() 
>for j = 1:length(a) 
>  n = a[j] * 0.9 + (a[j]+1.0) / 0.999 
>  n*=0.9 
>  n*=0.9 
>  n*=0.9 
>  n/=0.999 
>  n/=0.999 
>  n/=0.999 
>  if n>100 
>n-=(n-n/100.0) 
>  end 
>  a[j]= n 
>end 
>println("loop number $i $(a[1]), $(a[end]), $(time()-t)") 
> end 
>
> With an array of 7.2m the test times are: 
> C++11 gcc4.9  18.5 seconds, 58.6mb ram 
> Java openjdk7 18.8 seconds, 77.5mb ram 
> Julia  0.3.1  675 seconds, 156mb ram 
> Luajit 5.122.3 seconds, 67mb ram 
>
> I didn't necessarily expect Julia to match or beat C++. But I did hope 
> it would be more comparable. 
>
> Am I doing something wrong? Is my code not good Julia or idiomatic 
> Julia. Or is this simply where Julia is at this point in time? 
>
> Any help, understanding or wisdom greatly appreciated. 
>
> Thanks. 
>
> Jimmie 
>
>

[julia-users] Re: dispatch based on expression head

2014-09-10 Thread Patrick O'Leary
On Wednesday, September 10, 2014 11:20:59 AM UTC-5, Gray Calhoun wrote:
>
> Hi everyone, I'm writing code using expressions fairly heavily (mainly as 
> a learning exercise), and am using lots of constructions like:
>

Not directly related to any of your questions, but there's a predicate form 
of head-checking in Base.Meta called `isexpr()`:

Meta.isexpr(key, :call) && return ...

It's exported from the Meta module, so you can use "using Meta" to avoid 
having to qualify the name.

Related, as a style matter, is that return is a statement as in C, not a 
function. This means that you don't need the parentheses, since it isn't a 
call--in the AST, the head is ":return" rather than ":call"

julia> :(return 5)
:(return 5)

julia> :(return(5))
:(return 5)

julia> Meta.show_sexpr(:(return 42))
(:return, 42)

julia> Meta.show_sexpr(:(fn(42)))
(:call, :fn, 42)


[julia-users] Re: dispatch based on expression head

2014-09-10 Thread Steven G. Johnson
On Wednesday, September 10, 2014 12:20:59 PM UTC-4, Gray Calhoun wrote: 
>
> Are there better ways to do this in general?
>

For this kind of expression-matching code, you may find the Match.jl 
package handy (https://github.com/kmsquire/Match.jl), to get ML- or 
Scala-like symbolic pattern-matching. 


Re: [julia-users] Help with Clang.jl for a C beginner

2014-09-10 Thread John Myles White
Sweet!

 -- John

On Sep 10, 2014, at 9:46 AM, Randy Zwitch  wrote:

> Jacob and I are now collaborating on wrapping the liboauth library, if anyone 
> else is interested:
> 
> https://github.com/randyzwitch/OAuth.jl
> 
> On Tuesday, September 9, 2014 8:41:49 AM UTC-4, Randy Zwitch wrote:
> Yes I do want to collaborate Jacob, because I probably need some of the 
> functionality too! I'll put it up when I get home tonight and add you to the 
> repo.
> 
> On Tuesday, September 9, 2014 8:32:41 AM UTC-4, Jacob Quinn wrote:
> Hey Randy,
> 
> Any update on the liboath wrapping? I'd be willing to help if you've started 
> as I need the functionality. Want to throw up what you have in a repo and 
> collaborate?
> 
> -Jacob
> 
> 
> On Monday, September 1, 2014 6:10:49 PM UTC-4, Randy Zwitch wrote:
> Kevin, adding const in front gave me this error:
> 
> type: ccall: expected Symbol, got Ptr{None} 
> while loading In[3], in expression starting on line 3
> 
> Luckily João, your code finally worked for me! So if I understand this 
> correctly, the problem was that we were originally passing a Ptr to ccall, 
> when all I should've been doing is passing a string declared as a constant?
> 
>  
> 
> On Monday, September 1, 2014 4:46:07 PM UTC-4, João Felipe Santos wrote:
> I'm sorry, there was a mistake in my example. The dlopen step should be used 
> just to check whether the file is accessible as a shared library. ccall 
> expects the full path to the .dylib file in case the library is not at a 
> "standard" location.
> 
> Do something like this instead:
> 
> const liboauth = "/path/to/liboauth"
> (dlopen_e(liboauth) == C_NULL) && error("Unable to load shared library at 
> the given path.")
> b64d = ccall((:oauth_sign_hmac_sha1, liboauth), Ptr{Uint8}, (Ptr{Uint8}, 
> Ptr{Uint8}), testurl, testkey)
> println(bytestring(b64d))
> 
> Note that you have to use bytestring and not string. string will create a 
> string from printing the pointer (which will show something like Ptr{Uint8} 
> @0x012345). bytestring converts a C string from a pointer to an 
> ASCIIString, which is what you want.
> 
> --
> João Felipe Santos
> 
> 
> On Mon, Sep 1, 2014 at 4:24 PM, Randy Zwitch  wrote:
> Thanks for the suggestions everyone. Unfortunately, neither the code from 
> Ivar nor João worked for me.
> 
> liboauth = dlopen("/usr/local/lib/liboauth.dylib")
> Out[8]:
> Ptr{Void} @0x7fdc665c5ca0
> In [9]:
>  
> 
> function oauth_sign_hmac_sha1(m::String,k::String)
> res = 
> ccall((:oauth_sign_hmac_sha1,liboauth),Ptr{Uint8},(Ptr{Uint8},Ptr{Uint8}),m,k)
> if res == C_NULL
> error("oauth_sign_hmac_sha1 failed")
> end
> return string(res)
> end
>  
> testurl = 
> "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"
> testkey = "kd94hf93k423kf44&pfkkdhi9sl3r4s00"
> oauth_sign_hmac_sha1(testurl, testkey)   
> type: oauth_sign_hmac_sha1: in ccall: first argument not a pointer or valid 
> constant expression, expected DataType, got Type{(Any...,)}
> while loading In[9], in expression starting on line 11
> 
>  in oauth_sign_hmac_sha1 at In[9]:2
> 
> 
> 
> testurl = 
> "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"
> testkey = "kd94hf93k423kf44&pfkkdhi9sl3r4s00"
> b64d = ccall((:oauth_sign_hmac_sha1, liboauth), Ptr{Uint8}, (Ptr{Uint8}, 
> Ptr{Uint8}), testurl, testkey)
> bytestring(b64d)
> type: anonymous: in ccall: first argument not a pointer or valid constant 
> expression, expected DataType, got Type{(Any...,)}
> while loading In[10], in expression starting on line 3
> 
>  in anonymous at no file
> 
> Does this mean I compiled the library wrong? When I did the 'make' step, 
> after it was complete, I did 'make installcheck' and the 3 tests reported 
> that they completed successfully.
> 
> At a higher level, I like Isaiah's suggestion of doing this process by hand 
> to really get to understanding what is going on. Is there an eaier external 
> library that one of you could suggest that I could use to walk through the 
> entire process? I've done the examples in the manual using :clock and :getenv 
> and understand what is going on, so now I want to work with a user-installed 
> library to make sure I really get the process. I started with OAuth to see if 
> I could make something usable to work with my Twitter package, but maybe it's 
> not the best starting place.
> 
> 
> On Monday, September 1, 2014 10:47:22 AM UTC-4, João Felipe Santos wrote:
> You need to do ccalls using Ptr{Uint8}. What you can do actually is wrap the 
> Clang.jl-generated 

[julia-users] Re: help with bounds in NLopt

2014-09-10 Thread Steven G. Johnson
On Wednesday, September 10, 2014 10:12:39 AM UTC-4, Jude wrote:
>
> In my model I iterate over a lot of different values and solve a 
> constrained optimisation problem but for some values of my lower and upper 
> bounds I get an error saying "invalid NLopt arguments". I am not sure why 
> as my lower bound is < upper bound in all the iterations. I tried to 
> understand this using a more simple example such as the following but even 
> for this simple example if I set the bounds to (1,100) it's fine but if I 
> use (2,100) I get the same error. Why is this?:
>

 You get an error with (2,100) because your initial guess (1) is outside of 
the bounds.  As long as you have an initial guess that is inside the 
bounds, your example code works for me.


Re: [julia-users] Help with Clang.jl for a C beginner

2014-09-10 Thread Randy Zwitch
Jacob and I are now collaborating on wrapping the liboauth library, if 
anyone else is interested:

https://github.com/randyzwitch/OAuth.jl

On Tuesday, September 9, 2014 8:41:49 AM UTC-4, Randy Zwitch wrote:
>
> Yes I do want to collaborate Jacob, because I probably need some of the 
> functionality too! I'll put it up when I get home tonight and add you to 
> the repo.
>
> On Tuesday, September 9, 2014 8:32:41 AM UTC-4, Jacob Quinn wrote:
>>
>> Hey Randy,
>>
>> Any update on the liboath wrapping? I'd be willing to help if you've 
>> started as I need the functionality. Want to throw up what you have in a 
>> repo and collaborate?
>>
>> -Jacob
>>
>>
>> On Monday, September 1, 2014 6:10:49 PM UTC-4, Randy Zwitch wrote:
>>>
>>> Kevin, adding const in front gave me this error:
>>>
>>> type: ccall: expected Symbol, got Ptr{None} 
>>>
>>> while loading In[3], in expression starting on line 3
>>>
>>> Luckily João, your code finally worked for me! So if I understand this 
>>> correctly, the problem was that we were originally passing a Ptr to ccall, 
>>> when all I should've been doing is passing a string declared as a constant?
>>>
>>>  
>>>
>>> On Monday, September 1, 2014 4:46:07 PM UTC-4, João Felipe Santos wrote:

 I'm sorry, there was a mistake in my example. The dlopen step should be 
 used just to check whether the file is accessible as a shared library. 
 ccall expects the full path to the .dylib file in case the library is not 
 at a "standard" location.

 Do something like this instead:
 
 const liboauth = "/path/to/liboauth"
 (dlopen_e(liboauth) == C_NULL) && error("Unable to load shared 
 library at the given path.")
 b64d = ccall((:oauth_sign_hmac_sha1, liboauth), Ptr{Uint8}, 
 (Ptr{Uint8}, Ptr{Uint8}), testurl, testkey)
 println(bytestring(b64d))

 Note that you have to use bytestring and not string. string will create 
 a string from printing the pointer (which will show something like 
 Ptr{Uint8} @0x012345). bytestring converts a C string from a pointer 
 to 
 an ASCIIString, which is what you want.

 --
 João Felipe Santos


 On Mon, Sep 1, 2014 at 4:24 PM, Randy Zwitch  
 wrote:

> Thanks for the suggestions everyone. Unfortunately, neither the code 
> from Ivar nor João worked for me.
>
>  liboauth = dlopen("/usr/local/lib/liboauth.dylib")
>
>  Out[8]:
>
> Ptr{Void} @0x7fdc665c5ca0
>
>  In [9]:
>
  
>>
>>>  function oauth_sign_hmac_sha1(m::String,k::String)
>
> res = 
> ccall((:oauth_sign_hmac_sha1,liboauth),Ptr{Uint8},(Ptr{Uint8},Ptr{Uint8}),m,k)
>
> if res == C_NULL
>
> error("oauth_sign_hmac_sha1 failed")
>
> end
>
> return string(res)
>
> end
>
>  
>
> testurl = 
> "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"
>
> testkey = "kd94hf93k423kf44&pfkkdhi9sl3r4s00"
>
> oauth_sign_hmac_sha1(testurl, testkey)   
>
>   type: oauth_sign_hmac_sha1: in ccall: first argument not a pointer or 
> valid constant expression, expected DataType, got Type{(Any...,)}
> while loading In[9], in expression starting on line 11
>
>  in oauth_sign_hmac_sha1 at In[9]:2
>
>
>
>
>  testurl = 
> "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"
>
> testkey = "kd94hf93k423kf44&pfkkdhi9sl3r4s00"
>
> b64d = ccall((:oauth_sign_hmac_sha1, liboauth), Ptr{Uint8}, (Ptr{Uint8}, 
> Ptr{Uint8}), testurl, testkey)
>
> bytestring(b64d)
>
>   type: anonymous: in ccall: first argument not a pointer or valid 
> constant expression, expected DataType, got Type{(Any...,)}
> while loading In[10], in expression starting on line 3
>
>  in anonymous at no file
>
>
> Does this mean I compiled the library wrong? When I did the 'make' 
> step, after it was complete, I did 'make installcheck' and the 3 tests 
> reported that they completed successfully.
>
> At a higher level, I like Isaiah's suggestion of doing this process by 
> hand to really get to understanding what is going on. Is there an eaier 
> external library that one of you could suggest that I could use to walk 
> through the entire process? I've done the examples in the manual using 
> :clock and :getenv and understand what is going on, so now I want to work 
> with a user-installed 

Re: [julia-users] dispatch based on expression head

2014-09-10 Thread Gray Calhoun
Oh, cool. I'll have to read it carefully, but that looks very helpful. 
Thanks!

On Wednesday, September 10, 2014 11:24:58 AM UTC-5, John Myles White wrote:
>
> You can make parametric types that depend on symbols. Read the code in 
> Calculus.jl for examples: 
> https://github.com/johnmyleswhite/Calculus.jl/blob/master/src/symbolic.jl
>


Re: [julia-users] help with bounds in NLopt

2014-09-10 Thread Jude
Thanks, I'll do that so.

On Wednesday, September 10, 2014 5:11:22 PM UTC+1, Kevin Squire wrote:
>
> Hi Jude,
>
> You may get an answer here, but if you don't soon, check on the julia-opt 
> google group. 
>
> Cheers,
>Kevin 
>
> On Wednesday, September 10, 2014, Jude > 
> wrote:
>
>> Hi,
>>
>> In my model I iterate over a lot of different values and solve a 
>> constrained optimisation problem but for some values of my lower and upper 
>> bounds I get an error saying "invalid NLopt arguments". I am not sure why 
>> as my lower bound is < upper bound in all the iterations. I tried to 
>> understand this using a more simple example such as the following but even 
>> for this simple example if I set the bounds to (1,100) it's fine but if I 
>> use (2,100) I get the same error. Why is this?:
>>
>> using NLopt
>> function simpleopt(lbA1, ubA1)
>>
>> z=1
>>
>> function test_max(x,z)
>> x[1]^2 + z 
>> end
>>
>> count = 0 
>>
>> function func(x::Vector, grad::Vector)
>>global count +=1
>> println("f_$count($x)")
>>  test_max(x[1],z)
>> end
>>
>> opt = Opt(:LN_SBPLX,1)
>> lower_bounds!(opt, [lbA1])
>> upper_bounds!(opt, [ubA1])
>> min_objective!(opt, func)
>>
>> (minf,minx,ret)=optimize(opt,[1])
>>
>> println("got $minf at $minx after $count iterations (returned $ret)")
>> end
>>
>

Re: [julia-users] dispatch based on expression head

2014-09-10 Thread John Myles White
Gray,

You can make parametric types that depend on symbols. Read the code in 
Calculus.jl for examples: 
https://github.com/johnmyleswhite/Calculus.jl/blob/master/src/symbolic.jl

 -- John

On Sep 10, 2014, at 9:20 AM, Gray Calhoun  wrote:

> Hi everyone, I'm writing code using expressions fairly heavily (mainly as a 
> learning exercise), and am using lots of constructions like:
> 
> function haskey(df::MyDataType, key::Expr)
> key.head == :call  && return(all([haskey(df, x) for x in 
> key.args[2:end]]))
> key.head == :(=)   && return(haskey(df, key.args[2]))
> key.head == :block && return(all([haskey(df, x) for x in key.args]))
> key.head == :line  && return(true)
> warn("Didn't expect to get here...")
> false
> end
> 
> Some quick questions:
> 
> 1) Is there a way of mimicking Expr subtypes that I'm not aware of that would 
> let me rewrite this as several different methods? Are there better ways to do 
> this in general?
> 
> 2) Is there a list anywhere of the different possible values for Expr.head? 
> (I don't see it in the metaprogramming section of the manual, but may have 
> missed it.)
> 
> 3) How much of Julia would it break or slow down to make Expr an abstract 
> type with the contents of "head" implemented as different subtypes? (This 
> last one is mostly just asked out of curiosity.)
> 
> Thanks!



[julia-users] dispatch based on expression head

2014-09-10 Thread Gray Calhoun
Hi everyone, I'm writing code using expressions fairly heavily (mainly as a 
learning exercise), and am using lots of constructions like:

function haskey(df::MyDataType, key::Expr)
key.head == :call  && return(all([haskey(df, x) for x in key.args[2:end
]]))
key.head == :(=)   && return(haskey(df, key.args[2]))
key.head == :block && return(all([haskey(df, x) for x in key.args]))
key.head == :line  && return(true)
warn("Didn't expect to get here...")
false
end

Some quick questions:

1) Is there a way of mimicking Expr subtypes that I'm not aware of that 
would let me rewrite this as several different methods? Are there better 
ways to do this in general?

2) Is there a list anywhere of the different possible values for Expr.head? 
(I don't see it in the metaprogramming section of the manual, but may have 
missed it.)

3) How much of Julia would it break or slow down to make Expr an abstract 
type with the contents of "head" implemented as different subtypes? (This 
last one is mostly just asked out of curiosity.)

Thanks!


Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Kevin Squire
You also might want to check out
http://julia.readthedocs.org/en/latest/manual/packages/#package-development

Cheers,
   Kevin

On Wednesday, September 10, 2014, Bill Hart 
wrote:

> Thanks very much for the information. I might have additional specific
> questions along the way, but this definitely helps massively for now.
>
> On Wednesday, 10 September 2014 16:26:10 UTC+2, Isaiah wrote:
>>
>>
>> This was what I thought of trying first. But I couldn't figure out how it
>>> worked out what GitHub repository to associate this with, or whether it
>>> would try to create one, possibly scrubbing my existing nemo repository on
>>> GitHub. Obviously I don't want to lose my commit history.
>>
>>
>> For Pkg manager purposes, the association will be created later (when you
>> register the package).
>>
>> It also isn't clear where Julia creates the empty git repository. In the
>>> current directory? Or in some subdirectory of the Julia source tree?
>>
>>
>> Under `$HOME/.julia/v0.3` (or v0.4 if you are on git master)
>>
>> For the most part I can just run configure, make, make install for now
>>> and set some library paths (if I can figure out what kind of system I am
>>> on).
>>
>>
>> There are some macros to help with this: @osx, @linux, @unix (both), and
>> @windows. There is also a variable called OS_NAME with a platform-specific
>> value (:Windows, :Linux, etc.) See:
>> http://docs.julialang.org/en/release-0.3/manual/calling-c-
>> and-fortran-code/#handling-platform-variations
>>
>>
>>
>> On Wed, Sep 10, 2014 at 10:18 AM, Bill Hart 
>> wrote:
>>
>>>
>>>
>>> On Wednesday, 10 September 2014 15:57:56 UTC+2, Isaiah wrote:

 Is there documentation somewhere explaining how to do the latter? Or
> can someone help me with doing the latter?


 You could run `Pkg.generate("Nemo")` and then copy and commit (some of)
 the resulting files in your own Nemo git tree; there aren't very many.

>>>
>>> This was what I thought of trying first. But I couldn't figure out how
>>> it worked out what GitHub repository to associate this with, or whether it
>>> would try to create one, possibly scrubbing my existing nemo repository on
>>> GitHub. Obviously I don't want to lose my commit history.
>>>
>>> It also isn't clear where Julia creates the empty git repository. In the
>>> current directory? Or in some subdirectory of the Julia source tree?
>>>
>>>
 I can't find any documentation explaining where to put the commands in
> a Pkg to actually git clone flint, build it, install it and set up paths
> for Nemo. Given the complexities of installing flint for the user, I'd 
> like
> to have the Julia package manager do this automatically if at all 
> possible.
> And I see it does seem to be possible. I just can't figure out how.
>

 The Pkg manager will look for a file called `MYPKG/deps/build.jl` and
 run that if it exists. That's just a Julia file, so you can do whatever you
 want there (shell out, etc.).

>>>
>>> Perfect. For the most part I can just run configure, make, make install
>>> for now and set some library paths (if I can figure out what kind of system
>>> I am on).
>>>
>>> Finding the Julia installation on the system in order to link against
>>> the gmp/mpfr might be slightly more difficult.
>>>
>>>
 One option is to use the BinDeps package which provides primitives for
 interacting with various package managers and build systems:

 https://github.com/JuliaLang/BinDeps.jl

 A very advanced and fully-developed usage example can be found in the
 Cairo package, which has Autotools, Apt, Yum, and several other targets:

 https://github.com/JuliaLang/Cairo.jl/blob/master/deps/build.jl

 There are a number of other examples to draw from. Hopefully the above
 links will give you a sense of where to start. I can help out on Linux and
 Windows (@ihnorton on github).

>>>
>>> Thanks.
>>>
>>> Bill.
>>>
>>>


 On Wed, Sep 10, 2014 at 9:31 AM, Bill Hart 
 wrote:

> Hi,
>
> I have been writing a new Julia package, which I have called Nemo
> (it's essentially a limited computer algebra system).
>
> I have two specific problems:
>
> 1) The git and GitHub repository for Nemo already exists, but I
> haven't created a Julia Pkg yet.
>
> https://github.com/wbhart/nemo
>
> The documentation on creating a Julia Pkg seems to assume you are
> going to start with the Pkg then commit code to the git repository that it
> creates, not create a git/github project and then add the necessary stuff
> to turn it into a Julia package.
>
> Is there documentation somewhere explaining how to do the latter? Or
> can someone help me with doing the latter?
>
> (I have a couple of small build issues to fix in order for flint to
> work on Windows 64 before it will work there. But I will be working on
> those right away.

Re: [julia-users] help with bounds in NLopt

2014-09-10 Thread Kevin Squire
Hi Jude,

You may get an answer here, but if you don't soon, check on the julia-opt
google group.

Cheers,
   Kevin

On Wednesday, September 10, 2014, Jude  wrote:

> Hi,
>
> In my model I iterate over a lot of different values and solve a
> constrained optimisation problem but for some values of my lower and upper
> bounds I get an error saying "invalid NLopt arguments". I am not sure why
> as my lower bound is < upper bound in all the iterations. I tried to
> understand this using a more simple example such as the following but even
> for this simple example if I set the bounds to (1,100) it's fine but if I
> use (2,100) I get the same error. Why is this?:
>
> using NLopt
> function simpleopt(lbA1, ubA1)
>
> z=1
>
> function test_max(x,z)
> x[1]^2 + z
> end
>
> count = 0
>
> function func(x::Vector, grad::Vector)
>global count +=1
> println("f_$count($x)")
>  test_max(x[1],z)
> end
>
> opt = Opt(:LN_SBPLX,1)
> lower_bounds!(opt, [lbA1])
> upper_bounds!(opt, [ubA1])
> min_objective!(opt, func)
>
> (minf,minx,ret)=optimize(opt,[1])
>
> println("got $minf at $minx after $count iterations (returned $ret)")
> end
>


Re: [julia-users] About OpenCV-Julia binding

2014-09-10 Thread Kevin Squire
While I also hope that native Julia solutions move forward, I would also
find the OpenCV bindings quite useful, so +1!  I also second the suggestion
to use the existing python infrastructure.

Cheers,
  Kevin

On Wednesday, September 10, 2014, Boxiang Sun  wrote:

> Hi Jake,
>
> Thanks for your comment!
>
> Use the exist Python header parser could save a lot of work. I will be
> glad to accept it. If other friends believe the dependency of Python is not
> a problem, too. Then I will write the the type conversion first(Mat, etc),
> like Java binding did(../modules/java/generator).
>
> Regards,
> Sun
>
> 在 2014年9月10日星期三UTC+8上午10时29分48秒,Jake Bolewski写道:
>>
>> Hi Boxiang,
>>
>> I'm excited that you are working on this.  The one comment I would have
>> is don't rewrite the custom header parser.  It is maintained as part of the
>> official build system in OpenCV and will be maintained.  All the "official"
>> OpenCV bindings depend on it.  It is awkward to write python code to emit
>> Julia code, but I feel you will save so much time in the end and have a
>> chance of getting it into OpenCV core in the future if you reuse their
>> infrastructure.
>>
>> Best,
>> Jake
>>
>>
>> On Tuesday, September 9, 2014 10:08:43 PM UTC-4, Boxiang Sun wrote:
>>>
>>> Hi all,
>>>
>>> Before the Google Summer of Code 2014, I proposed a proposal about
>>> OpenCV-Julia binding. But at last, I was accepted by another project. Now I
>>> am successfully accomplished the GSoC. With the help of Tim Holy, I am
>>> restarted the OpenCV-Julia binding. Tim just send me a link:
>>> https://github.com/JuliaLang/julia/issues/8288. And I think I need to
>>> let people know there has a project about OpenCV-Julia binding.
>>>
>>> During the time that I talk to Tim Holy, and my own research. I have
>>> some results, please allow me to introduce the status of the binding.
>>>
>>> I am wrapped some basic API manually and tested it. Try to find a
>>> correct mechanism of the binding. Now my plan is like OpenCV-Python binding
>>> did:
>>>
>>> *Extract OpenCV API, like the hdr_parser.py did in OpenCV-Python
>>> binding. But rewrite the header parser with Julia(We don't want
>>> OpenCV-Julia has dependency of Python, do we?). Another reason is the
>>> output of hdr_parser.py is not perfect for Julia wrapper.
>>> *Write automatic generation tool to wrap OpenCV API base on the output
>>> of header parser. Generate the wrapped API, the wrapped API could build a
>>> shared lib, just like OpenCV-Python did.
>>>
>>> I will continue try to wrap more API manually today. Then try to write
>>> the header parser in Julia. That is the recently plan.
>>>
>>> Some details, such as memory management, interactive between
>>> OpenCV-Julia binding and Image/Array, and other things, not decide yet.
>>>
>>> Any comments or suggestions will be highly appreciated!
>>>
>>> Regards,
>>> Sun
>>>
>>


Re: [julia-users] Array Performance

2014-09-10 Thread Isaiah Norton
http://docs.julialang.org/en/release-0.3/manual/performance-tips/

On Wed, Sep 10, 2014 at 11:55 AM, Jimmie Houchin 
wrote:

> Hello,
>
> I am working on an app which will be doing analysis on a lot of numerical
> data. Julia seems perfect for the job. However I wanted to do a simple test
> that I have run on a few languages to see where I wanted to land.
>
> Yes, I understand benchmarks, micro-benchmarks are evil. But I needed to
> see a little on how the languages performed in cpu, time and memory.
>
> Basically I have two almost identical test differing only in how large the
> array is that I am operating over. One is 100million items, the other
> 7.2million items. The reason for the two test is I am expecting at the
> start the 7.2m to be more normative, but I want to test towards some upper
> bounds. Some languages I can't do the 100m because the reach memory
> constraints.
>
> The array is simply populated with doubles or Float64 in Julia's case.
>
> In the test I iterate over the array, do some calculations assign back
> into the array. The calculations are simple calculations which can be
> reasonably consistent across languages. I do this iteration over the array
> 100 times.
>
> Hardware, Laptop, 3rd Gen, i7, 12GB Ram
> Lubuntu 14.10, running Openbox only, not Lubuntu DE
>
> Julia  --  Version 0.3.1-pre+4720
>
> a = Array(Float64, 720)
>
> # populate array with some data
> for i = 1:length(a)
>   n = i * 0.9
>   if n>100
> n-=(n-n/100.0)
>   end
>   a[i]= n*n*n
> end
>
> println("$(a[1]), $(a[end])")
>
> for i = 1:100
>   t=time()
>   for j = 1:length(a)
> n = a[j] * 0.9 + (a[j]+1.0) / 0.999
> n*=0.9
> n*=0.9
> n*=0.9
> n/=0.999
> n/=0.999
> n/=0.999
> if n>100
>   n-=(n-n/100.0)
> end
> a[j]= n
>   end
>   println("loop number $i $(a[1]), $(a[end]), $(time()-t)")
> end
>
> With an array of 7.2m the test times are:
> C++11 gcc4.9  18.5 seconds, 58.6mb ram
> Java openjdk7 18.8 seconds, 77.5mb ram
> Julia  0.3.1  675 seconds, 156mb ram
> Luajit 5.122.3 seconds, 67mb ram
>
> I didn't necessarily expect Julia to match or beat C++. But I did hope it
> would be more comparable.
>
> Am I doing something wrong? Is my code not good Julia or idiomatic Julia.
> Or is this simply where Julia is at this point in time?
>
> Any help, understanding or wisdom greatly appreciated.
>
> Thanks.
>
> Jimmie
>
>


Re: [julia-users] Array Performance

2014-09-10 Thread Stefan Karpinski
Wrap it in a function – global scope is slow.

> On Sep 10, 2014, at 5:55 PM, Jimmie Houchin  wrote:
> 
> Hello,
> 
> I am working on an app which will be doing analysis on a lot of numerical 
> data. Julia seems perfect for the job. However I wanted to do a simple test 
> that I have run on a few languages to see where I wanted to land.
> 
> Yes, I understand benchmarks, micro-benchmarks are evil. But I needed to see 
> a little on how the languages performed in cpu, time and memory.
> 
> Basically I have two almost identical test differing only in how large the 
> array is that I am operating over. One is 100million items, the other 
> 7.2million items. The reason for the two test is I am expecting at the start 
> the 7.2m to be more normative, but I want to test towards some upper bounds. 
> Some languages I can't do the 100m because the reach memory constraints.
> 
> The array is simply populated with doubles or Float64 in Julia's case.
> 
> In the test I iterate over the array, do some calculations assign back into 
> the array. The calculations are simple calculations which can be reasonably 
> consistent across languages. I do this iteration over the array 100 times.
> 
> Hardware, Laptop, 3rd Gen, i7, 12GB Ram
> Lubuntu 14.10, running Openbox only, not Lubuntu DE
> 
> Julia  --  Version 0.3.1-pre+4720
> 
> a = Array(Float64, 720)
> 
> # populate array with some data
> for i = 1:length(a)
> n = i * 0.9
> if n>100
>   n-=(n-n/100.0)
> end
> a[i]= n*n*n
> end
> 
> println("$(a[1]), $(a[end])")
> 
> for i = 1:100
> t=time()
> for j = 1:length(a)
>   n = a[j] * 0.9 + (a[j]+1.0) / 0.999
>   n*=0.9
>   n*=0.9
>   n*=0.9
>   n/=0.999
>   n/=0.999
>   n/=0.999
>   if n>100
> n-=(n-n/100.0)
>   end
>   a[j]= n
> end
> println("loop number $i $(a[1]), $(a[end]), $(time()-t)")
> end
> 
> With an array of 7.2m the test times are:
> C++11 gcc4.9  18.5 seconds, 58.6mb ram
> Java openjdk7 18.8 seconds, 77.5mb ram
> Julia  0.3.1  675 seconds, 156mb ram
> Luajit 5.122.3 seconds, 67mb ram
> 
> I didn't necessarily expect Julia to match or beat C++. But I did hope it 
> would be more comparable.
> 
> Am I doing something wrong? Is my code not good Julia or idiomatic Julia. Or 
> is this simply where Julia is at this point in time?
> 
> Any help, understanding or wisdom greatly appreciated.
> 
> Thanks.
> 
> Jimmie
> 


[julia-users] Array Performance

2014-09-10 Thread Jimmie Houchin

Hello,

I am working on an app which will be doing analysis on a lot of 
numerical data. Julia seems perfect for the job. However I wanted to do 
a simple test that I have run on a few languages to see where I wanted 
to land.


Yes, I understand benchmarks, micro-benchmarks are evil. But I needed to 
see a little on how the languages performed in cpu, time and memory.


Basically I have two almost identical test differing only in how large 
the array is that I am operating over. One is 100million items, the 
other 7.2million items. The reason for the two test is I am expecting at 
the start the 7.2m to be more normative, but I want to test towards some 
upper bounds. Some languages I can't do the 100m because the reach 
memory constraints.


The array is simply populated with doubles or Float64 in Julia's case.

In the test I iterate over the array, do some calculations assign back 
into the array. The calculations are simple calculations which can be 
reasonably consistent across languages. I do this iteration over the 
array 100 times.


Hardware, Laptop, 3rd Gen, i7, 12GB Ram
Lubuntu 14.10, running Openbox only, not Lubuntu DE

Julia  --  Version 0.3.1-pre+4720

a = Array(Float64, 720)

# populate array with some data
for i = 1:length(a)
  n = i * 0.9
  if n>100
n-=(n-n/100.0)
  end
  a[i]= n*n*n
end

println("$(a[1]), $(a[end])")

for i = 1:100
  t=time()
  for j = 1:length(a)
n = a[j] * 0.9 + (a[j]+1.0) / 0.999
n*=0.9
n*=0.9
n*=0.9
n/=0.999
n/=0.999
n/=0.999
if n>100
  n-=(n-n/100.0)
end
a[j]= n
  end
  println("loop number $i $(a[1]), $(a[end]), $(time()-t)")
end

With an array of 7.2m the test times are:
C++11 gcc4.9  18.5 seconds, 58.6mb ram
Java openjdk7 18.8 seconds, 77.5mb ram
Julia  0.3.1  675 seconds, 156mb ram
Luajit 5.122.3 seconds, 67mb ram

I didn't necessarily expect Julia to match or beat C++. But I did hope 
it would be more comparable.


Am I doing something wrong? Is my code not good Julia or idiomatic 
Julia. Or is this simply where Julia is at this point in time?


Any help, understanding or wisdom greatly appreciated.

Thanks.

Jimmie



Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Bill Hart
Thanks very much for the information. I might have additional specific 
questions along the way, but this definitely helps massively for now.

On Wednesday, 10 September 2014 16:26:10 UTC+2, Isaiah wrote:
>
>
> This was what I thought of trying first. But I couldn't figure out how it 
>> worked out what GitHub repository to associate this with, or whether it 
>> would try to create one, possibly scrubbing my existing nemo repository on 
>> GitHub. Obviously I don't want to lose my commit history.
>
>
> For Pkg manager purposes, the association will be created later (when you 
> register the package).
>
> It also isn't clear where Julia creates the empty git repository. In the 
>> current directory? Or in some subdirectory of the Julia source tree?
>
>
> Under `$HOME/.julia/v0.3` (or v0.4 if you are on git master)
>
> For the most part I can just run configure, make, make install for now and 
>> set some library paths (if I can figure out what kind of system I am on).
>
>
> There are some macros to help with this: @osx, @linux, @unix (both), and 
> @windows. There is also a variable called OS_NAME with a platform-specific 
> value (:Windows, :Linux, etc.) See:
>
> http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#handling-platform-variations
>
>  
>
> On Wed, Sep 10, 2014 at 10:18 AM, Bill Hart  > wrote:
>
>>
>>
>> On Wednesday, 10 September 2014 15:57:56 UTC+2, Isaiah wrote:
>>>
>>> Is there documentation somewhere explaining how to do the latter? Or can 
 someone help me with doing the latter?
>>>
>>>
>>> You could run `Pkg.generate("Nemo")` and then copy and commit (some of) 
>>> the resulting files in your own Nemo git tree; there aren't very many.
>>>
>>
>> This was what I thought of trying first. But I couldn't figure out how it 
>> worked out what GitHub repository to associate this with, or whether it 
>> would try to create one, possibly scrubbing my existing nemo repository on 
>> GitHub. Obviously I don't want to lose my commit history.
>>  
>> It also isn't clear where Julia creates the empty git repository. In the 
>> current directory? Or in some subdirectory of the Julia source tree?
>>
>>
>>> I can't find any documentation explaining where to put the commands in a 
 Pkg to actually git clone flint, build it, install it and set up paths for 
 Nemo. Given the complexities of installing flint for the user, I'd like to 
 have the Julia package manager do this automatically if at all possible. 
 And I see it does seem to be possible. I just can't figure out how.

>>>
>>> The Pkg manager will look for a file called `MYPKG/deps/build.jl` and 
>>> run that if it exists. That's just a Julia file, so you can do whatever you 
>>> want there (shell out, etc.). 
>>>
>>
>> Perfect. For the most part I can just run configure, make, make install 
>> for now and set some library paths (if I can figure out what kind of system 
>> I am on).
>>
>> Finding the Julia installation on the system in order to link against the 
>> gmp/mpfr might be slightly more difficult.
>>  
>>
>>> One option is to use the BinDeps package which provides primitives for 
>>> interacting with various package managers and build systems:
>>>
>>> https://github.com/JuliaLang/BinDeps.jl
>>>
>>> A very advanced and fully-developed usage example can be found in the 
>>> Cairo package, which has Autotools, Apt, Yum, and several other targets:
>>>
>>> https://github.com/JuliaLang/Cairo.jl/blob/master/deps/build.jl
>>>
>>> There are a number of other examples to draw from. Hopefully the above 
>>> links will give you a sense of where to start. I can help out on Linux and 
>>> Windows (@ihnorton on github). 
>>>
>>
>> Thanks.
>>
>> Bill.
>>  
>>
>>>
>>>
>>> On Wed, Sep 10, 2014 at 9:31 AM, Bill Hart  
>>> wrote:
>>>
 Hi,

 I have been writing a new Julia package, which I have called Nemo (it's 
 essentially a limited computer algebra system).

 I have two specific problems:

 1) The git and GitHub repository for Nemo already exists, but I haven't 
 created a Julia Pkg yet.

 https://github.com/wbhart/nemo

 The documentation on creating a Julia Pkg seems to assume you are going 
 to start with the Pkg then commit code to the git repository that it 
 creates, not create a git/github project and then add the necessary stuff 
 to turn it into a Julia package.

 Is there documentation somewhere explaining how to do the latter? Or 
 can someone help me with doing the latter?

 (I have a couple of small build issues to fix in order for flint to 
 work on Windows 64 before it will work there. But I will be working on 
 those right away. I have managed to get it to work with Julia there, just 
 not hacked the fixes into the flint build system yet. Other than this 
 minor 
 thing, I am quite ready to publish Nemo as a package right away (well, 
 apart from a horrible 3x slowdown and excessive memor

Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Isaiah Norton
> This was what I thought of trying first. But I couldn't figure out how it
> worked out what GitHub repository to associate this with, or whether it
> would try to create one, possibly scrubbing my existing nemo repository on
> GitHub. Obviously I don't want to lose my commit history.


For Pkg manager purposes, the association will be created later (when you
register the package).

It also isn't clear where Julia creates the empty git repository. In the
> current directory? Or in some subdirectory of the Julia source tree?


Under `$HOME/.julia/v0.3` (or v0.4 if you are on git master)

For the most part I can just run configure, make, make install for now and
> set some library paths (if I can figure out what kind of system I am on).


There are some macros to help with this: @osx, @linux, @unix (both), and
@windows. There is also a variable called OS_NAME with a platform-specific
value (:Windows, :Linux, etc.) See:
http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#handling-platform-variations



On Wed, Sep 10, 2014 at 10:18 AM, Bill Hart 
wrote:

>
>
> On Wednesday, 10 September 2014 15:57:56 UTC+2, Isaiah wrote:
>>
>> Is there documentation somewhere explaining how to do the latter? Or can
>>> someone help me with doing the latter?
>>
>>
>> You could run `Pkg.generate("Nemo")` and then copy and commit (some of)
>> the resulting files in your own Nemo git tree; there aren't very many.
>>
>
> This was what I thought of trying first. But I couldn't figure out how it
> worked out what GitHub repository to associate this with, or whether it
> would try to create one, possibly scrubbing my existing nemo repository on
> GitHub. Obviously I don't want to lose my commit history.
>
> It also isn't clear where Julia creates the empty git repository. In the
> current directory? Or in some subdirectory of the Julia source tree?
>
>
>> I can't find any documentation explaining where to put the commands in a
>>> Pkg to actually git clone flint, build it, install it and set up paths for
>>> Nemo. Given the complexities of installing flint for the user, I'd like to
>>> have the Julia package manager do this automatically if at all possible.
>>> And I see it does seem to be possible. I just can't figure out how.
>>>
>>
>> The Pkg manager will look for a file called `MYPKG/deps/build.jl` and run
>> that if it exists. That's just a Julia file, so you can do whatever you
>> want there (shell out, etc.).
>>
>
> Perfect. For the most part I can just run configure, make, make install
> for now and set some library paths (if I can figure out what kind of system
> I am on).
>
> Finding the Julia installation on the system in order to link against the
> gmp/mpfr might be slightly more difficult.
>
>
>> One option is to use the BinDeps package which provides primitives for
>> interacting with various package managers and build systems:
>>
>> https://github.com/JuliaLang/BinDeps.jl
>>
>> A very advanced and fully-developed usage example can be found in the
>> Cairo package, which has Autotools, Apt, Yum, and several other targets:
>>
>> https://github.com/JuliaLang/Cairo.jl/blob/master/deps/build.jl
>>
>> There are a number of other examples to draw from. Hopefully the above
>> links will give you a sense of where to start. I can help out on Linux and
>> Windows (@ihnorton on github).
>>
>
> Thanks.
>
> Bill.
>
>
>>
>>
>> On Wed, Sep 10, 2014 at 9:31 AM, Bill Hart 
>> wrote:
>>
>>> Hi,
>>>
>>> I have been writing a new Julia package, which I have called Nemo (it's
>>> essentially a limited computer algebra system).
>>>
>>> I have two specific problems:
>>>
>>> 1) The git and GitHub repository for Nemo already exists, but I haven't
>>> created a Julia Pkg yet.
>>>
>>> https://github.com/wbhart/nemo
>>>
>>> The documentation on creating a Julia Pkg seems to assume you are going
>>> to start with the Pkg then commit code to the git repository that it
>>> creates, not create a git/github project and then add the necessary stuff
>>> to turn it into a Julia package.
>>>
>>> Is there documentation somewhere explaining how to do the latter? Or can
>>> someone help me with doing the latter?
>>>
>>> (I have a couple of small build issues to fix in order for flint to work
>>> on Windows 64 before it will work there. But I will be working on those
>>> right away. I have managed to get it to work with Julia there, just not
>>> hacked the fixes into the flint build system yet. Other than this minor
>>> thing, I am quite ready to publish Nemo as a package right away (well,
>>> apart from a horrible 3x slowdown and excessive memory usage caused by gc,
>>> but I think I've given up on solving that problem for now).)
>>>
>>> 2) Nemo relies on mpir (or GMP), mpfr and flint, which are large
>>> external C/assembly libraries which need to get built or be available to
>>> run Nemo. I understand Julia has its own GMP and MPFR which I can probably
>>> link to if they are recent enough.
>>>
>>> Flint needs to be built when the p

Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Bill Hart


On Wednesday, 10 September 2014 15:57:56 UTC+2, Isaiah wrote:
>
> Is there documentation somewhere explaining how to do the latter? Or can 
>> someone help me with doing the latter?
>
>
> You could run `Pkg.generate("Nemo")` and then copy and commit (some of) 
> the resulting files in your own Nemo git tree; there aren't very many.
>

This was what I thought of trying first. But I couldn't figure out how it 
worked out what GitHub repository to associate this with, or whether it 
would try to create one, possibly scrubbing my existing nemo repository on 
GitHub. Obviously I don't want to lose my commit history.
 
It also isn't clear where Julia creates the empty git repository. In the 
current directory? Or in some subdirectory of the Julia source tree?


> I can't find any documentation explaining where to put the commands in a 
>> Pkg to actually git clone flint, build it, install it and set up paths for 
>> Nemo. Given the complexities of installing flint for the user, I'd like to 
>> have the Julia package manager do this automatically if at all possible. 
>> And I see it does seem to be possible. I just can't figure out how.
>>
>
> The Pkg manager will look for a file called `MYPKG/deps/build.jl` and run 
> that if it exists. That's just a Julia file, so you can do whatever you 
> want there (shell out, etc.). 
>

Perfect. For the most part I can just run configure, make, make install for 
now and set some library paths (if I can figure out what kind of system I 
am on).

Finding the Julia installation on the system in order to link against the 
gmp/mpfr might be slightly more difficult.
 

> One option is to use the BinDeps package which provides primitives for 
> interacting with various package managers and build systems:
>
> https://github.com/JuliaLang/BinDeps.jl
>
> A very advanced and fully-developed usage example can be found in the 
> Cairo package, which has Autotools, Apt, Yum, and several other targets:
>
> https://github.com/JuliaLang/Cairo.jl/blob/master/deps/build.jl
>
> There are a number of other examples to draw from. Hopefully the above 
> links will give you a sense of where to start. I can help out on Linux and 
> Windows (@ihnorton on github). 
>

Thanks.

Bill.
 

>
>
> On Wed, Sep 10, 2014 at 9:31 AM, Bill Hart  > wrote:
>
>> Hi,
>>
>> I have been writing a new Julia package, which I have called Nemo (it's 
>> essentially a limited computer algebra system).
>>
>> I have two specific problems:
>>
>> 1) The git and GitHub repository for Nemo already exists, but I haven't 
>> created a Julia Pkg yet.
>>
>> https://github.com/wbhart/nemo
>>
>> The documentation on creating a Julia Pkg seems to assume you are going 
>> to start with the Pkg then commit code to the git repository that it 
>> creates, not create a git/github project and then add the necessary stuff 
>> to turn it into a Julia package.
>>
>> Is there documentation somewhere explaining how to do the latter? Or can 
>> someone help me with doing the latter?
>>
>> (I have a couple of small build issues to fix in order for flint to work 
>> on Windows 64 before it will work there. But I will be working on those 
>> right away. I have managed to get it to work with Julia there, just not 
>> hacked the fixes into the flint build system yet. Other than this minor 
>> thing, I am quite ready to publish Nemo as a package right away (well, 
>> apart from a horrible 3x slowdown and excessive memory usage caused by gc, 
>> but I think I've given up on solving that problem for now).)
>>
>> 2) Nemo relies on mpir (or GMP), mpfr and flint, which are large external 
>> C/assembly libraries which need to get built or be available to run Nemo. I 
>> understand Julia has its own GMP and MPFR which I can probably link to if 
>> they are recent enough. 
>>
>> Flint needs to be built when the package is installed. It takes a long 
>> time to build, e.g. 40 minutes or so on Windows, maybe a third of that on 
>> Linux.
>>
>> I can't find any documentation explaining where to put the commands in a 
>> Pkg to actually git clone flint, build it, install it and set up paths for 
>> Nemo. Given the complexities of installing flint for the user, I'd like to 
>> have the Julia package manager do this automatically if at all possible. 
>> And I see it does seem to be possible. I just can't figure out how.
>>
>> Flint is here:
>>
>> https://github.com/wbhart/flint2
>>
>> Can anyone help, or point me in the right direction?
>>
>> Bill.
>>
>
>

[julia-users] help with bounds in NLopt

2014-09-10 Thread Jude
Hi,

In my model I iterate over a lot of different values and solve a 
constrained optimisation problem but for some values of my lower and upper 
bounds I get an error saying "invalid NLopt arguments". I am not sure why 
as my lower bound is < upper bound in all the iterations. I tried to 
understand this using a more simple example such as the following but even 
for this simple example if I set the bounds to (1,100) it's fine but if I 
use (2,100) I get the same error. Why is this?:

using NLopt
function simpleopt(lbA1, ubA1)

z=1

function test_max(x,z)
x[1]^2 + z 
end

count = 0 

function func(x::Vector, grad::Vector)
   global count +=1
println("f_$count($x)")
 test_max(x[1],z)
end

opt = Opt(:LN_SBPLX,1)
lower_bounds!(opt, [lbA1])
upper_bounds!(opt, [ubA1])
min_objective!(opt, func)

(minf,minx,ret)=optimize(opt,[1])

println("got $minf at $minx after $count iterations (returned $ret)")
end


Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Bill Hart
Thanks for the reply. Some follow-up questions inline below.

On Wednesday, 10 September 2014 15:57:21 UTC+2, Leah Hanson wrote:
>
> 1) You can try looking at other packages to see the structure.
>

Thanks, I see you mention Cairo below. I'll try to find that on GitHub for 
some clues.
 

>
> Code goes is `src/` 
>

 Do you mean src/ in the Julia directory, or do you mean the Nemo code 
should go in a subdirectory called /src within the git repository?

And test should be a subdirectory of src/ or a separate directory. (I guess 
I can look at an example for this.)
 

> (and you'll need a `Nemo.jl` in there that will be what Julia runs when 
> you say `using Nemo`). 
>

I do have Nemo.jl, since I read I'd need this. But it is currently empty.

The problem, leading to another question, is that Nemo currently consists 
of two large modules called Rings and Fields (Fields uses Rings, but not 
vice versa). There will be more such modules in the future.

But I can't find a way for Nemo.jl to import everything from Rings and 
Fields and then export all those symbols out to the user if they type say 
`using Nemo`. Is there a way to do this without exporting all the symbols 
again individually from the Nemo module?

Tests go in the `tests` folder; you should have a file `runtests.jl` in 
> there that runs the tests for your package (if you want Julia's 
> auto-testing stuff to work).
>

Great. I wondered how to make that work. This should be easy to add. It 
will just call the two large sets of test functions I currently have.
 

>
> A file named REQUIRE is where any dependencies on other Julia go; it is 
> also where you specify compatible versions of Julia. Every package has one 
> of these, so you can look at them for examples to see the syntax. You 
> probably want a line like `julia 0.3-` if you believe you package works for 
> 0.3 and will work for 0.4, but not in 0.2. 
>

Ok.
 

>
> Like most OSS projects: license in LICENSE.md, some documentation in 
> README.md. (*.md means a plain text Markdown file; there's flexibility on 
> plain text format/filename here; these are just what's made by default by 
> `Pkg.generate`).
>

Ok.
 

>
> This is enough for people to get your package installed via the Julia 
> package manager by running `Pkg.clone("https://github.com/wbhart/nemo";)`.
>

Yes, that is all I want for the time being.
 

>
> Since Pkg.clone will put you package in the "right" place (i.e. where all 
> your other Julia packages are installed), you'll be able to follow the 
> normal package publishing (register with METADATA) instructions.
>

Ok.
 

>
> 2) https://github.com/JuliaLang/BinDeps.jl is the package for installing 
> binary dependencies.
>
> You should also search this mailing list for past BinDeps questions, as 
> there have been a number of them. Looking at other packages that use 
> BinDeps can also be very helpful; Cairo.jl is an example, but anything that 
> wraps C libraries would probably be helpful.
>
>
Will do. That is the keyword I needed, thanks.

Bill.
 

> Best,
> Leah
>
>
>
> On Wed, Sep 10, 2014 at 8:31 AM, Bill Hart  > wrote:
>
>> Hi,
>>
>> I have been writing a new Julia package, which I have called Nemo (it's 
>> essentially a limited computer algebra system).
>>
>> I have two specific problems:
>>
>> 1) The git and GitHub repository for Nemo already exists, but I haven't 
>> created a Julia Pkg yet.
>>
>> https://github.com/wbhart/nemo
>>
>> The documentation on creating a Julia Pkg seems to assume you are going 
>> to start with the Pkg then commit code to the git repository that it 
>> creates, not create a git/github project and then add the necessary stuff 
>> to turn it into a Julia package.
>>
>> Is there documentation somewhere explaining how to do the latter? Or can 
>> someone help me with doing the latter?
>>
>> (I have a couple of small build issues to fix in order for flint to work 
>> on Windows 64 before it will work there. But I will be working on those 
>> right away. I have managed to get it to work with Julia there, just not 
>> hacked the fixes into the flint build system yet. Other than this minor 
>> thing, I am quite ready to publish Nemo as a package right away (well, 
>> apart from a horrible 3x slowdown and excessive memory usage caused by gc, 
>> but I think I've given up on solving that problem for now).)
>>
>> 2) Nemo relies on mpir (or GMP), mpfr and flint, which are large external 
>> C/assembly libraries which need to get built or be available to run Nemo. I 
>> understand Julia has its own GMP and MPFR which I can probably link to if 
>> they are recent enough. 
>>
>> Flint needs to be built when the package is installed. It takes a long 
>> time to build, e.g. 40 minutes or so on Windows, maybe a third of that on 
>> Linux.
>>
>> I can't find any documentation explaining where to put the commands in a 
>> Pkg to actually git clone flint, build it, install it and set up paths for 
>> Nemo. Given the complexities of installing flint for the us

Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Isaiah Norton
>
> Is there documentation somewhere explaining how to do the latter? Or can
> someone help me with doing the latter?


You could run `Pkg.generate("Nemo")` and then copy and commit (some of) the
resulting files in your own Nemo git tree; there aren't very many.

I can't find any documentation explaining where to put the commands in a
> Pkg to actually git clone flint, build it, install it and set up paths for
> Nemo. Given the complexities of installing flint for the user, I'd like to
> have the Julia package manager do this automatically if at all possible.
> And I see it does seem to be possible. I just can't figure out how.
>

The Pkg manager will look for a file called `MYPKG/deps/build.jl` and run
that if it exists. That's just a Julia file, so you can do whatever you
want there (shell out, etc.). One option is to use the BinDeps package
which provides primitives for interacting with various package managers and
build systems:

https://github.com/JuliaLang/BinDeps.jl

A very advanced and fully-developed usage example can be found in the Cairo
package, which has Autotools, Apt, Yum, and several other targets:

https://github.com/JuliaLang/Cairo.jl/blob/master/deps/build.jl

There are a number of other examples to draw from. Hopefully the above
links will give you a sense of where to start. I can help out on Linux and
Windows (@ihnorton on github).


On Wed, Sep 10, 2014 at 9:31 AM, Bill Hart 
wrote:

> Hi,
>
> I have been writing a new Julia package, which I have called Nemo (it's
> essentially a limited computer algebra system).
>
> I have two specific problems:
>
> 1) The git and GitHub repository for Nemo already exists, but I haven't
> created a Julia Pkg yet.
>
> https://github.com/wbhart/nemo
>
> The documentation on creating a Julia Pkg seems to assume you are going to
> start with the Pkg then commit code to the git repository that it creates,
> not create a git/github project and then add the necessary stuff to turn it
> into a Julia package.
>
> Is there documentation somewhere explaining how to do the latter? Or can
> someone help me with doing the latter?
>
> (I have a couple of small build issues to fix in order for flint to work
> on Windows 64 before it will work there. But I will be working on those
> right away. I have managed to get it to work with Julia there, just not
> hacked the fixes into the flint build system yet. Other than this minor
> thing, I am quite ready to publish Nemo as a package right away (well,
> apart from a horrible 3x slowdown and excessive memory usage caused by gc,
> but I think I've given up on solving that problem for now).)
>
> 2) Nemo relies on mpir (or GMP), mpfr and flint, which are large external
> C/assembly libraries which need to get built or be available to run Nemo. I
> understand Julia has its own GMP and MPFR which I can probably link to if
> they are recent enough.
>
> Flint needs to be built when the package is installed. It takes a long
> time to build, e.g. 40 minutes or so on Windows, maybe a third of that on
> Linux.
>
> I can't find any documentation explaining where to put the commands in a
> Pkg to actually git clone flint, build it, install it and set up paths for
> Nemo. Given the complexities of installing flint for the user, I'd like to
> have the Julia package manager do this automatically if at all possible.
> And I see it does seem to be possible. I just can't figure out how.
>
> Flint is here:
>
> https://github.com/wbhart/flint2
>
> Can anyone help, or point me in the right direction?
>
> Bill.
>


Re: [julia-users] Help needed with creating Julia package

2014-09-10 Thread Leah Hanson
1) You can try looking at other packages to see the structure.

Code goes is `src/` (and you'll need a `Nemo.jl` in there that will be what
Julia runs when you say `using Nemo`). Tests go in the `tests` folder; you
should have a file `runtests.jl` in there that runs the tests for your
package (if you want Julia's auto-testing stuff to work).

A file named REQUIRE is where any dependencies on other Julia go; it is
also where you specify compatible versions of Julia. Every package has one
of these, so you can look at them for examples to see the syntax. You
probably want a line like `julia 0.3-` if you believe you package works for
0.3 and will work for 0.4, but not in 0.2.

Like most OSS projects: license in LICENSE.md, some documentation in
README.md. (*.md means a plain text Markdown file; there's flexibility on
plain text format/filename here; these are just what's made by default by
`Pkg.generate`).

This is enough for people to get your package installed via the Julia
package manager by running `Pkg.clone("https://github.com/wbhart/nemo";)`.

Since Pkg.clone will put you package in the "right" place (i.e. where all
your other Julia packages are installed), you'll be able to follow the
normal package publishing (register with METADATA) instructions.

2) https://github.com/JuliaLang/BinDeps.jl is the package for installing
binary dependencies.

You should also search this mailing list for past BinDeps questions, as
there have been a number of them. Looking at other packages that use
BinDeps can also be very helpful; Cairo.jl is an example, but anything that
wraps C libraries would probably be helpful.

Best,
Leah



On Wed, Sep 10, 2014 at 8:31 AM, Bill Hart 
wrote:

> Hi,
>
> I have been writing a new Julia package, which I have called Nemo (it's
> essentially a limited computer algebra system).
>
> I have two specific problems:
>
> 1) The git and GitHub repository for Nemo already exists, but I haven't
> created a Julia Pkg yet.
>
> https://github.com/wbhart/nemo
>
> The documentation on creating a Julia Pkg seems to assume you are going to
> start with the Pkg then commit code to the git repository that it creates,
> not create a git/github project and then add the necessary stuff to turn it
> into a Julia package.
>
> Is there documentation somewhere explaining how to do the latter? Or can
> someone help me with doing the latter?
>
> (I have a couple of small build issues to fix in order for flint to work
> on Windows 64 before it will work there. But I will be working on those
> right away. I have managed to get it to work with Julia there, just not
> hacked the fixes into the flint build system yet. Other than this minor
> thing, I am quite ready to publish Nemo as a package right away (well,
> apart from a horrible 3x slowdown and excessive memory usage caused by gc,
> but I think I've given up on solving that problem for now).)
>
> 2) Nemo relies on mpir (or GMP), mpfr and flint, which are large external
> C/assembly libraries which need to get built or be available to run Nemo. I
> understand Julia has its own GMP and MPFR which I can probably link to if
> they are recent enough.
>
> Flint needs to be built when the package is installed. It takes a long
> time to build, e.g. 40 minutes or so on Windows, maybe a third of that on
> Linux.
>
> I can't find any documentation explaining where to put the commands in a
> Pkg to actually git clone flint, build it, install it and set up paths for
> Nemo. Given the complexities of installing flint for the user, I'd like to
> have the Julia package manager do this automatically if at all possible.
> And I see it does seem to be possible. I just can't figure out how.
>
> Flint is here:
>
> https://github.com/wbhart/flint2
>
> Can anyone help, or point me in the right direction?
>
> Bill.
>


[julia-users] Help needed with creating Julia package

2014-09-10 Thread Bill Hart
Hi,

I have been writing a new Julia package, which I have called Nemo (it's 
essentially a limited computer algebra system).

I have two specific problems:

1) The git and GitHub repository for Nemo already exists, but I haven't 
created a Julia Pkg yet.

https://github.com/wbhart/nemo

The documentation on creating a Julia Pkg seems to assume you are going to 
start with the Pkg then commit code to the git repository that it creates, 
not create a git/github project and then add the necessary stuff to turn it 
into a Julia package.

Is there documentation somewhere explaining how to do the latter? Or can 
someone help me with doing the latter?

(I have a couple of small build issues to fix in order for flint to work on 
Windows 64 before it will work there. But I will be working on those right 
away. I have managed to get it to work with Julia there, just not hacked 
the fixes into the flint build system yet. Other than this minor thing, I 
am quite ready to publish Nemo as a package right away (well, apart from a 
horrible 3x slowdown and excessive memory usage caused by gc, but I think 
I've given up on solving that problem for now).)

2) Nemo relies on mpir (or GMP), mpfr and flint, which are large external 
C/assembly libraries which need to get built or be available to run Nemo. I 
understand Julia has its own GMP and MPFR which I can probably link to if 
they are recent enough. 

Flint needs to be built when the package is installed. It takes a long time 
to build, e.g. 40 minutes or so on Windows, maybe a third of that on Linux.

I can't find any documentation explaining where to put the commands in a 
Pkg to actually git clone flint, build it, install it and set up paths for 
Nemo. Given the complexities of installing flint for the user, I'd like to 
have the Julia package manager do this automatically if at all possible. 
And I see it does seem to be possible. I just can't figure out how.

Flint is here:

https://github.com/wbhart/flint2

Can anyone help, or point me in the right direction?

Bill.


[julia-users] Re: Simple parallel for loop example

2014-09-10 Thread Lars Ruthotto
Thanks, Bradley. I really like your example and in fact I have played with 
pmap already. I think it is a great tool for getting into distributed 
computing since - as far as I know - pmap sends the different input 
variables to different workers and communicates back the result). 

In some cases shared memory access might be more feasible (such as in the 
example I posted above). Does anybody how to do that in parallel?



On Tuesday, September 9, 2014 3:42:02 PM UTC-4, Alex wrote:
>
> Bradley, 
>
> That's an awesome tutorial. Thanks for putting that together. 
>
>
> On Monday, August 18, 2014 7:32:17 AM UTC-7, Bradley Setzler wrote:
>>
>> I found that the easiest way was to use two files - one file contains the 
>> function to be run in parallel, the other file uses Require() to load the 
>> function in parallel, and pmap to call the function.
>>
>> I have a working example of the two-file approach here:
>>
>> http://juliaeconomics.com/2014/06/18/parallel-processing-in-julia-bootstrapping-the-mle/
>>
>> Best,
>> Bradley
>>
>>
>>
>>
>>
>> On Wednesday, November 6, 2013 10:08:38 PM UTC-6, Lars Ruthotto wrote:
>>>
>>> I am relatively new to Julia and doing some simple experiments. So far, 
>>> I am very impressed by it's nice and intuitive syntax and performance. Good 
>>> job!
>>>
>>> However, I have a simple question regarding parallel for loops the 
>>> manual could not answer for me. Say I am interested in parallelizing this 
>>> code
>>>
>>> a = zeros(10)
>>> for i=1:10
>>>   a[i] = i
>>> end
>>>
>>> In the manual it is said (and I verified) that 
>>>
>>> a = zeros(10)
>>> @parallel for i=1:10
>>>   a[i] = i
>>> end
>>>
>>> does not give the correct result. Unfortunately it does not say (or I 
>>> couldn't find it) how this can be done in Julia? Does anyone have an idea?
>>>
>>> Thanks!
>>> Lars
>>>
>>>

Re: [julia-users] How come &(x, y) isn't legal syntax?

2014-09-10 Thread Jeff Waller
I would add that (&)(1,2) works; I'm imagining that it changes the context 
and forces the parser to use the one legal interpretation.


Re: [julia-users] Range to Array with power functions fails

2014-09-10 Thread Földes László
Thanks.

On Friday, September 5, 2014 1:02:55 PM UTC+2, Milan Bouchet-Valat wrote:
>
>  Le vendredi 05 septembre 2014 à 03:29 -0700, Földes László a écrit : 
>
> This works fine:
>
>  julia> x = 1:5
> 1:5
>
> julia> y = [z^2 for z in x]
> 5-element Array{Any,1}:
>   1
>   4
>   9
>  16
>  25
>
>  
> and I can use similar solution with a simplified form:
>
>  julia> y = [x*2]
> 5-element Array{Int64,1}:
>   2
>   4
>   6
>   8
>  10
>
>  
> so I got brave and tried this, but it failed:
>
>  julia> x = 1:5
> 1:5
>
> julia> y = [x^2]
> ERROR: `*` has no method matching *(::UnitRange{Int64}, ::UnitRange{Int64
> })
>  in power_by_squaring at intfuncs.jl:56
>  in ^ at intfuncs.jl:86
>
>  
> or:
>
>  julia> y = [x*x]
> ERROR: `*` has no method matching *(::StepRange{Int64,Int64}, ::StepRange{
> Int64,Int64}) 
>
> Actually it's even simpler than that: 
>
> julia> x = 1:5
> 1:5
>
> julia> x*x
> ERROR: `*` has no method matching *(::UnitRange{Int64}, ::UnitRange{Int64})
>
>
> You want to use .* instead of *, and .^ instead of ^:
> julia> x .* x
> 5-element Array{Int64,1}:
>   1
>   4
>   9
>  16
>  25
>
> julia> x.^2
> 5-element Array{Int64,1}:
>   1
>   4
>   9
>  16
>  25
>
>
> Regards 
>


[julia-users] Re: About OpenCV-Julia binding

2014-09-10 Thread Boxiang Sun
Hi Jake,

Thanks for your comment!

Use the exist Python header parser could save a lot of work. I will be glad 
to accept it. If other friends believe the dependency of Python is not a 
problem, too. Then I will write the the type conversion first(Mat, etc), 
like Java binding did(../modules/java/generator).

Regards,
Sun

在 2014年9月10日星期三UTC+8上午10时29分48秒,Jake Bolewski写道:
>
> Hi Boxiang,
>
> I'm excited that you are working on this.  The one comment I would have is 
> don't rewrite the custom header parser.  It is maintained as part of the 
> official build system in OpenCV and will be maintained.  All the "official" 
> OpenCV bindings depend on it.  It is awkward to write python code to emit 
> Julia code, but I feel you will save so much time in the end and have a 
> chance of getting it into OpenCV core in the future if you reuse their 
> infrastructure. 
>
> Best,
> Jake
>
>
> On Tuesday, September 9, 2014 10:08:43 PM UTC-4, Boxiang Sun wrote:
>>
>> Hi all,
>>
>> Before the Google Summer of Code 2014, I proposed a proposal about 
>> OpenCV-Julia binding. But at last, I was accepted by another project. Now I 
>> am successfully accomplished the GSoC. With the help of Tim Holy, I am 
>> restarted the OpenCV-Julia binding. Tim just send me a link: 
>> https://github.com/JuliaLang/julia/issues/8288. And I think I need to 
>> let people know there has a project about OpenCV-Julia binding.
>>
>> During the time that I talk to Tim Holy, and my own research. I have some 
>> results, please allow me to introduce the status of the binding.
>>
>> I am wrapped some basic API manually and tested it. Try to find a correct 
>> mechanism of the binding. Now my plan is like OpenCV-Python binding did: 
>>
>> *Extract OpenCV API, like the hdr_parser.py did in OpenCV-Python binding. 
>> But rewrite the header parser with Julia(We don't want OpenCV-Julia has 
>> dependency of Python, do we?). Another reason is the output of 
>> hdr_parser.py is not perfect for Julia wrapper.
>> *Write automatic generation tool to wrap OpenCV API base on the output of 
>> header parser. Generate the wrapped API, the wrapped API could build a 
>> shared lib, just like OpenCV-Python did.
>>
>> I will continue try to wrap more API manually today. Then try to write 
>> the header parser in Julia. That is the recently plan.
>>
>> Some details, such as memory management, interactive between OpenCV-Julia 
>> binding and Image/Array, and other things, not decide yet.
>>
>> Any comments or suggestions will be highly appreciated!
>>
>> Regards,
>> Sun
>>
>

Re: [julia-users] How to read julia code?

2014-09-10 Thread Tim Holy
Gardens are indeed great for debugging.

I should have also mentioned, with the profiler you can set the delay to 
something like 10 microseconds (rather than 1 ms) and get more complete call 
chains.

I've had the same difficulty with Winston.

--Tim

On Wednesday, September 10, 2014 01:11:23 AM Andreas Lobinger wrote:
> Hello colleague,
> 
> On Wednesday, September 10, 2014 2:13:15 AM UTC+2, Tim Holy wrote:
> > A full call graph would be great. Between the profiler and code-coverage
> > (try
> > `julia -h` if you don't know about code-coverage), you can at least get
> > close.
> 
> i looked a little bit at the .cov files and this looks very well prepared.
> But still you only see which lines have been run but not in which sequence.
> 
> Actually i wrote this yesterday in some state of frustration, as i tried to
> extend a package and was lost without a good idea how to connect the pieces
> (and it seems quite common for julia programms to stay free of comments).
> 
> Then i went out into the garden for 10 minutes and had an idea.
> 
> Therefore i recommend the garden as debugging tool.
> 
> Wishing a happy day,
>   Andreas
> 
> P.S. seem my PR on Winston for the result.



Re: [julia-users] Best way to flatten an 2D array of Array{T, 2} into a single 2D array

2014-09-10 Thread Tim Holy
Your approach is fine, but maybe easier is to use ImageView's canvas grid, and 
then you can use write_to_png(cg, filename).

--Tim

On Tuesday, September 09, 2014 07:16:04 PM Yuri Vishnevsky wrote:
> Hi all,
> 
> I'm writing code to take a bunch of images and concatenate them into one
> big image (you can see the attached picture for an example of what this can
> look like).
> 
> The code I wrote to generate the above picture is fairly hideous; I arrived
> at it after trying a number of approaches that seemed more natural and then
> giving up in despair.
> 
> The code I initially wanted to write looked something like this:
> 
> 
> grid = Char[
> 'A' 'B' 'C' 'D' 'E';
> 'F' 'G' 'H' 'I' 'J';
> 'K' 'L' 'M' 'N' 'O';
> 'P' 'Q' 'R' 'S' 'T';
> 'U' 'V' 'W' 'X' 'Y';
> 'Z'  0   0   0   0 ;
> ]
> 
> arr = map(c -> c == 0 ? zeros(Ufixed8, 64, 64) : convert(Array,
> imread("$prefix/sdf/$c.png")), grid)
> imwrite(arr, "$prefix/atlas.png")
> 
> This approach fails in imwrite because the individual elements in the array
> are themselves arrays, rather than numbers. I couldn't figure out a way to
> flatten the resulting array-of-arrays into a single matrix and ended up
> writing code that preallocates a big matrix of the right output size and
> assigns to calculated subranges in a loop.
> 
> My background is in user interface design and web programming, and right
> now I'm fairly new to writing matrix-manipulation code. If there's a
> natural way to express this computation in Julia I'd love to know.
> 
> Cheers,
> Yuri



Re: [julia-users] How to read julia code?

2014-09-10 Thread Andreas Lobinger
Hello colleague,

On Wednesday, September 10, 2014 2:13:15 AM UTC+2, Tim Holy wrote:
>
> A full call graph would be great. Between the profiler and code-coverage 
> (try 
> `julia -h` if you don't know about code-coverage), you can at least get 
> close. 
>
>
i looked a little bit at the .cov files and this looks very well prepared. 
But still you only see which lines have been run but not in which sequence.

Actually i wrote this yesterday in some state of frustration, as i tried to 
extend a package and was lost without a good idea how to connect the pieces 
(and it seems quite common for julia programms to stay free of comments).

Then i went out into the garden for 10 minutes and had an idea.

Therefore i recommend the garden as debugging tool.

Wishing a happy day, 
  Andreas

P.S. seem my PR on Winston for the result.