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

2014-09-09 Thread 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] Best way to flatten an 2D array of Array{T, 2} into a single 2D array

2014-09-09 Thread Yuri Vishnevsky
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




[julia-users] About OpenCV-Julia binding

2014-09-09 Thread Boxiang Sun
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] println a IOStream

2014-09-09 Thread Jake Bolewski
print takes an IO parameter so

julia> println(STDERR, "test")
test

julia> io = IOBuffer()
IOBuffer(data=Uint8[...], readable=true, writable=true, seekable=true, 
append=false, size=0, maxsize=Inf, ptr=1, mark=-1)

julia> print(io, "test")

julia> bytestring(io)
"test"

works.

On Tuesday, September 9, 2014 7:14:50 PM UTC-4, Patrick O'Leary wrote:
>
> On Tuesday, September 9, 2014 6:03:14 PM UTC-5, muraveill wrote:
>>
>> Thanks! I missed this one.
>> But it adds no newline, which is not the greatest for debugging (outside 
>> of the REPL). "showln" ?
>>
>
> Consider using the @show macro:
>
> @show f
>
> `@show` is also useful for displaying expressions:
>
> @show foo = bar + baz
>
> Patrick
>


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

2014-09-09 Thread Tim Holy
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.

Obviously the debugger, when that lands, will be the nicest tool of all.

--Tim

On Tuesday, September 09, 2014 09:16:05 AM Andreas Lobinger wrote:
> Hello colleagues,
> 
> the obvious answer to the literal question is: Open the file and use your
> favorite method of text-to-mind-transfer.
> 
> However, the question goes deeper: Are there tools available that help me
> (or anyone) understanding a given program structure?
> 
> More than once now, i thought: Well, extending that package should be easy,
> but later it was medium sized complicated, as the program structure was
> somehow hidden inside a type hierarchy. And just a call graph would have
> been nice.
> 
> In other environments i'd use a debugger (and some breakpoints) or some
> tools for tracing. Or the find function in the text editor.
> In Julia programs due to multiple dispatch the function name tells me only
> half of the story which part of the source to read, i need the type of the
> argument also.
> 
> I played around with the Profiler, but as it is sampling, not all the
> called code is showing up.
> 
> Do i miss something obvious for tooling?
> 
> Wishing a happy day,
>Andreas



[julia-users] Discrete sine transform

2014-09-09 Thread Diego Tapias
Can please anyone help me with the use of the method FFTW.r2r?, I need to
do a discrete sine transform over the elements of an array. Particularly I
need the transform RODFT00 (option of the method). I read what the manual
says but it is a little bit confused for me.


Thanks in advance.


Re: [julia-users] println a IOStream

2014-09-09 Thread Patrick O'Leary
On Tuesday, September 9, 2014 6:03:14 PM UTC-5, muraveill wrote:
>
> Thanks! I missed this one.
> But it adds no newline, which is not the greatest for debugging (outside 
> of the REPL). "showln" ?
>

Consider using the @show macro:

@show f

`@show` is also useful for displaying expressions:

@show foo = bar + baz

Patrick


Re: [julia-users] println a IOStream

2014-09-09 Thread muraveill
Thanks! I missed this one.
But it adds no newline, which is not the greatest for debugging (outside of 
the REPL). "showln" ?


Re: [julia-users] How to append two arrays?

2014-09-09 Thread Diego Tapias
yay! That's what I wanted.
Thank you guys

2014-09-09 17:33 GMT-05:00 Keno Fischer :

> If I understand correctly, you want hcat:
>
> julia> hcat(v,w)
> 3x2 Array{Float64,2}:
>  1.0  2.0
>  2.0  4.0
>  3.0  6.0
>
> The general version of that is `cat`.
>
> On Tue, Sep 9, 2014 at 6:31 PM, Diego Tapias 
> wrote:
> > Thanks for answering!, but what if I want to form a matrix of dimension 2
> > and not an array of dimension 1.
> >
> > 2014-09-09 17:27 GMT-05:00 Stefan Karpinski :
> >
> >> append!(v,w) – it modifies and returns v.
> >>
> >>
> >> On Wed, Sep 10, 2014 at 12:25 AM, Diego Tapias 
> >> wrote:
> >>>
> >>> Consider the arrays given by
> >>>
> >>> v = [1.,2.,3.]
> >>>
> >>> w = [2.,4.,6.]
> >>>
> >>> As you know both are arrays of dimension 1. I want to form the matrix
> >>> with its columns given by v and w. How can I do that (I tried with
> “cat” but
> >>> it didn’t worh)? How can it be generalized for n arrrays.
> >>>
> >>> Thanks in advance
> >>
> >>
> >
>


Re: [julia-users] println a IOStream

2014-09-09 Thread John Myles White
You want show, not print.

 -- John

On Sep 9, 2014, at 3:32 PM, muraveill  wrote:

> This is really confusing. In the REPL one can evaluate a stream to get useful 
> info on what the object is:
> 
> julia> f
> IOStream()
> 
> But in a script, just "f" would not work, so for debugging I try to print it 
> to stdout:
> 
> julia> print(f)
> [empty]
> 
> julia> println(f)
> ERROR: attempt to write to a read-only IOStream
>  in write at iostream.jl:208
>  in println at string.jl:5
> 
> julia> print(repr(f))
> IOStream()
> 
> I thought that "write" was the method to write to a file. 
> Why is there this strange re-use of "println"? I suggest a "writeln" if it is 
> just to append a newline to a file.
> Why does "print" not use the representation of the object? 
> Am I supposed to use "repr" every time, or am I just debugging the wrong way?



Re: [julia-users] How to append two arrays?

2014-09-09 Thread Keno Fischer
If I understand correctly, you want hcat:

julia> hcat(v,w)
3x2 Array{Float64,2}:
 1.0  2.0
 2.0  4.0
 3.0  6.0

The general version of that is `cat`.

On Tue, Sep 9, 2014 at 6:31 PM, Diego Tapias  wrote:
> Thanks for answering!, but what if I want to form a matrix of dimension 2
> and not an array of dimension 1.
>
> 2014-09-09 17:27 GMT-05:00 Stefan Karpinski :
>
>> append!(v,w) – it modifies and returns v.
>>
>>
>> On Wed, Sep 10, 2014 at 12:25 AM, Diego Tapias 
>> wrote:
>>>
>>> Consider the arrays given by
>>>
>>> v = [1.,2.,3.]
>>>
>>> w = [2.,4.,6.]
>>>
>>> As you know both are arrays of dimension 1. I want to form the matrix
>>> with its columns given by v and w. How can I do that (I tried with “cat” but
>>> it didn’t worh)? How can it be generalized for n arrrays.
>>>
>>> Thanks in advance
>>
>>
>


Re: [julia-users] How to append two arrays?

2014-09-09 Thread John Myles White
Try vcat/hcat.

 -- John

On Sep 9, 2014, at 3:31 PM, Diego Tapias  wrote:

> Thanks for answering!, but what if I want to form a matrix of dimension 2 and 
> not an array of dimension 1.
> 
> 2014-09-09 17:27 GMT-05:00 Stefan Karpinski :
> append!(v,w) – it modifies and returns v.
> 
> 
> On Wed, Sep 10, 2014 at 12:25 AM, Diego Tapias  wrote:
> Consider the arrays given by
> 
> v = [1.,2.,3.]
> 
> w = [2.,4.,6.]
> 
> As you know both are arrays of dimension 1. I want to form the matrix with 
> its columns given by v and w. How can I do that (I tried with “cat” but it 
> didn’t worh)? How can it be generalized for n arrrays.
> 
> Thanks in advance
> 
> ​
> 
> 



[julia-users] println a IOStream

2014-09-09 Thread muraveill
This is really confusing. In the REPL one can evaluate a stream to get 
useful info on what the object is:

julia> f
IOStream()

But in a script, just "f" would not work, so for debugging I try to print 
it to stdout:

julia> print(f)
[empty]

julia> println(f)
ERROR: attempt to write to a read-only IOStream
 in write at iostream.jl:208
 in println at string.jl:5

julia> print(repr(f))
IOStream()

I thought that "write" was the method to write to a file. 
Why is there this strange re-use of "println"? I suggest a "writeln" if it 
is just to append a newline to a file.
Why does "print" not use the representation of the object? 
Am I supposed to use "repr" every time, or am I just debugging the wrong 
way?


Re: [julia-users] How to append two arrays?

2014-09-09 Thread Diego Tapias
Thanks for answering!, but what if I want to form a matrix of dimension 2
and not an array of dimension 1.

2014-09-09 17:27 GMT-05:00 Stefan Karpinski :

> append!(v,w) – it modifies and returns v.
>
>
> On Wed, Sep 10, 2014 at 12:25 AM, Diego Tapias 
> wrote:
>
>> Consider the arrays given by
>>
>> v = [1.,2.,3.]
>>
>> w = [2.,4.,6.]
>>
>> As you know both are arrays of dimension 1. I want to form the matrix
>> with its columns given by v and w. How can I do that (I tried with “cat”
>> but it didn’t worh)? How can it be generalized for n arrrays.
>>
>> Thanks in advance
>> ​
>>
>
>


Re: [julia-users] How to append two arrays?

2014-09-09 Thread Stefan Karpinski
append!(v,w) – it modifies and returns v.


On Wed, Sep 10, 2014 at 12:25 AM, Diego Tapias 
wrote:

> Consider the arrays given by
>
> v = [1.,2.,3.]
>
> w = [2.,4.,6.]
>
> As you know both are arrays of dimension 1. I want to form the matrix with
> its columns given by v and w. How can I do that (I tried with “cat” but it
> didn’t worh)? How can it be generalized for n arrrays.
>
> Thanks in advance
> ​
>


[julia-users] How to append two arrays?

2014-09-09 Thread Diego Tapias
Consider the arrays given by

v = [1.,2.,3.]

w = [2.,4.,6.]

As you know both are arrays of dimension 1. I want to form the matrix with
its columns given by v and w. How can I do that (I tried with “cat” but it
didn’t worh)? How can it be generalized for n arrrays.

Thanks in advance
​


Re: [julia-users] best practices for unescaping Julia specific escape sequences (ie: "\$")

2014-09-09 Thread fur514
Figured it out
On Sep 7, 2014 7:19 AM, "YB Israel"  wrote:

> My scenario, I have a file that I read, manipulate the strings and write
> back. It's not JSON, just some html tag stuff, where I'm replacing a few
> strings and then rewriting the file.
>
> If in the process I encounter a string e.g., "${abcd}", how can I avoid
>  finding "\${abcd}" when rewriting the file?
>
> On Wednesday, May 22, 2013 11:19:34 PM UTC+3, Westley Hennigh wrote:
>>
>> Ya, should be fine in this case. Parsing proper JSON seems to work fine
>> and it even errors properly on the malformed strings with "\$".
>>
>> In this case all that needs to happen is we replace the call to
>> `print_quoted` (a trivial function) with a json-aware version that handles
>> any oddities... and so far the only thing that's come up is "\$".
>>
>> On Wednesday, May 22, 2013 1:04:18 PM UTC-7, Stefan Karpinski wrote:
>>>
>>> Starting from the versions in Base it probably shouldn't be too awful. I
>>> might take a look.
>>>
>>>
>>> On Wed, May 22, 2013 at 3:59 PM, Westley Hennigh 
>>> wrote:
>>>
 Ok, thanks.

 I guess I'll work on that then.


 On Wednesday, May 22, 2013 12:47:30 PM UTC-7, Stefan Karpinski wrote:

> Using Julia's escaping and unescaping for JSON is a bit of a dirty
> hack that mostly happens to work but isn't really right – as you're
> discovering here. Since Julia strings and JSON strings aren't the same, it
> probably makes the most sense to write escape and unescape routines
> specifically for JSON rather than abusing the ones in Base. These 
> functions
> shouldn't go in Base since they're JSON-specific. Even though other
> languages like C and Java will have fairly similar escaping routines, 
> these
> rules are never quite identical, so I think we just handle interop with
> various systems on a case-by-case basis. Fortunately, everybody seems to
> understand JSON these days.
>
> On Wed, May 22, 2013 at 1:22 PM, Westley Hennigh  > wrote:
>
>> JSON.jl uses `print_quoted` to escape strings used to build json
>> objects. This is great, but doesn't handle julia strings like "bla bla
>> \$expensive-bla". "\$" is not valid json.
>>
>> I don't think it makes sense to change `print_quoted` (to remove the
>> "\"). From the perspective of most julia code that would be the opposite 
>> of
>> printing quoted.
>>
>> I also don't think this is a JSON.jl specific issue, I suspect that
>> the same problem will come up anywhere people send julia strings to other
>> languages.
>>
>> So maybe there needs to be a new method in Base? Or is there a
>> solution to this problem that I've overlooked?
>>
>
>
>>>


Re: [julia-users] Re: Two issues with Juno, the Julia plugin for LightTable

2014-09-09 Thread Mike Innes
Unfortunately there's no auto-updating yet. You can check for updates to
the plugin in LT's plugin manager, but they generally coincide with updates
to the Jewel package in Julia, so the best thing is to Pkg.update() every
so often and watch out for changes there.

On 8 September 2014 13:11, Erlend Magnus Viggen 
wrote:

> Hi Mike,
>
> That sounds good! Will the Juno plugin be auto-updated when there is a new
> version available? Until then, I'll happily continue using Juno/LightTable
> as an enhanced editor and run and post-process my simulations in the REPL.
>
>
> On Monday, September 8, 2014 5:04:31 PM UTC+2, Mike Innes wrote:
>>
>> Hey Erlend,
>>
>> Thanks a lot for the detailed report. Honestly, PyPlot and terminal
>> integration aren't things I've tested much recently, so there's a good
>> chance I broke them at some point (sorry about that). Although the PyPlot
>> error is weird because it looks like an internal problem.
>>
>> On the plus side, some of my recent work will enable much nicer
>> integration with PyPlot, so this should behave much more nicely very soon.
>> (Provided I can get PyPlot running on my laptop, that is)
>>
>> I have a couple 
>> of issues  to
>> track these.
>>
>> – Mike
>>
>> On Sunday, 7 September 2014 10:15:08 UTC-4, Erlend Magnus Viggen wrote:
>>>
>>> Hi,
>>>
>>> I've been trying out the Juno plugin after finding out that Julia Studio
>>> unfortunately doesn't work well for me at the moment. Juno seems really
>>> nice, and I'd highly recommend checking it out. However, I have some issues
>>> with plotting and the REPL.
>>>
>>> First, the plotting. Gadfly seems to work well with Juno, but I'd rather
>>> be using PyPlot to be honest. Unfortunately PyPlot doesn't work for me in
>>> Juno. I've made a minimal working example that works fine in the regular
>>> Julia REPL:
>>>
>>> using PyPlot
>>> plot([0 1]', [0 1]')
>>>
>>> Now, the first line executes nicely in Juno, but the second one results
>>> in an exception,
>>>
>>> *PyError (PyObject_Call) RuntimeError('Julia exception:
 UndefVarError(:htmlimage)',) File
 "/Users/username/anaconda3/lib/python3/site-packages/matplotlib/pyplot.py",
 line 3094, in plot draw_if_interactive()*
 in pyerr_check at exception.jl:58
 in pycall at PyCall.jl:85
 in plot at PyPlot.jl:314

>>>
>>> Second, I've tried to connect Juno with the Julia REPL in the Terminal,
>>> as described here
>>> ,
>>> in order to have an interactive console in addition to Juno. But when I do,
>>> it dumps out errors on my Julia command line,
>>>
>>> WARNING: Can't handle command julia.set-default-client

>>>
>>>
 WARNING: LightTable.jl: global_client not defined
  in anonymous at /Users/*username*/.julia/v0.3/
 Jewel/src/LightTable/misc.jl:11
  in handle_cmd at /Users/*username*/.julia/v0.3/Jewel/src/LightTable/
 LightTable.jl:65
  in server at /Users/*username*/.julia/v0.3/Jewel/src/LightTable/
 LightTable.jl:22
  in server at /Users/*username*/.julia/v0.3/Jewel/src/Jewel.jl:16
  in anonymous at task.jl:340

>>>
>>> At this point, I can still run execute Julia commands in Juno and on the
>>> Terminal REPL, but the latter kind of warning pops up regularly.
>>>
>>> Any tips on any of these issues? My setup is:
>>>
>>>- Mac OS X 10.9.4
>>>- Julia 0.3.0, with the latest version of all packages as given by
>>>Pkg.update()
>>>- LightTable 0.6.7 with Juno/Julia plugin version 0.8.0
>>>- Anaconda Python 3.4 distribution with Python 3.4.1 and Matplotlib
>>>1.4.0
>>>
>>>


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

2014-09-09 Thread Alex
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
>>
>>

[julia-users] Re: For Loop over set of vector names

2014-09-09 Thread Alex
Thanks for the tips! As an academic trying to move lots of code over from 
other languages my lack of knowledge in coding fundamentals is being 
exposed a bit.

Alex

On Sunday, September 7, 2014 3:03:01 PM UTC-7, Alex wrote:
>
> Hi Everyone, 
>
> I've been having some trouble using a for loop to perform tasks over 
> similarly named vectors. This simple example below illustrates my problem 
> pretty well. I would like to create two 5x5 arrays of zeros, but with 
> dynamic names. In this case x_foo and x_bar would be the names. When I run 
> this code, it clearly is looping over the string set, but it is not 
> actually creating the array. I have had similar problem trying to call 
> arrays into functions dynamically based on their names. Clearly I am just 
> incorrectly referencing i, but I cannot figure it where the error is. I am 
> trying to port a complicated version of this code from Stata, where this is 
> quite easy to do by referencing i in your code as `i'. Sorry for such a 
> novice question, but this has been driving me nuts all day!
>
> Thanks in advance!
>
> Alex
>
> n=5
> for i in ["foo","bar"]
> x_$i=zeros(n,n)
> println("x_$i")
> end
> x_bar
>


[julia-users] Re: Passing an expression to a macro

2014-09-09 Thread cormullion
Thanks to you both, I now see where I went wrong - I'm going to back up and 
try again in a lower gear... :)


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

2014-09-09 Thread Mauro
> In other environments i'd use a debugger (and some breakpoints) or some 
> tools for tracing. Or the find function in the text editor. 
> In Julia programs due to multiple dispatch the function name tells me only 
> half of the story which part of the source to read, i need the type of the 
> argument also.

You probably know this already... For this you could insert a 
   @which fn(arg1, arg2)
into the code.  Also @show can help with debugging.


Re: [julia-users] Does Julia have something similar to Python's documentation string?

2014-09-09 Thread Ross Boylan
How would documentation handle type information for the arguments to a
method?  There are 3 possible sources: the comments, the text of the
function arguments (e.g. someArg::FooType), and the compiler.

The ::FooType notation will not always be present.  The comments could
just be wrong.  So it seems there's an argument for getting this info
from the compiler, which is perhaps an argument in favor of the
"comments as AST metadata" approach.

Also, even if the argument is declared ::FooType it may be that only
some subtypes are permitted because of the way the argument is used in
the body of the function.

For various purposes one might be interested in abstract types,
concrete types, or both.

An even messier question is which concrete types could actually be
used, or are actually used in a particular run.

Ross Boylan


Re: [julia-users] Passing an expression to a macro

2014-09-09 Thread Leah Hanson
So, currently, your @my macro is evaluating the arguments in the macro
context (vs. returning them to be evaluated in the calling context.

~~~
julia> macro my2(exp)
 quote
 for i in $exp.args
 println("the arg is ", i)
 end
  end
   end

julia> @my2 e
the arg is  # none, line 2:
the arg is a = 2
the arg is  # line 3:
the arg is b = 3
~~~

Note that I'm returning a quote block from the macro, and passing in `e`,
not `:e` when I call it. Your macro is only working at it is because the
macro context and the calling context are the same (in the REPL).

Have you seen the macroexpand function? It's often very useful when
debugging macros.

~~~
julia> macroexpand(quote @my2 e end)
quote  # none, line 1:
begin  # none, line 3:
for #168#i = e.args # line 4:
println("the arg is ",#168#i)
end
end
end

julia> macroexpand(quote @my :e end)
the arg is begin  # none, line 2:
a = 2 # line 3:
b = 3
end
quote  # none, line 1:
nothing
end
~~~

-- Leah


On Tue, Sep 9, 2014 at 11:42 AM,  wrote:

> Just puzzling over this simple problem I'm having while learning about
> macros. Here's an expression:
>
> julia> e = quote
>a = 2
>b  = 3
>end
>
> quote  # none, line 2:
> a = 2 # line 3:
> b = 3
> end
>
>
> If I go through this simply, I'll get a crack at each element of the args
> array:
>
>
>
> julia> for i in e.args
>println("the arg is ", i)
>end
>
>
>
> the arg is  # none, line 2:
> the arg is a = 2
> the arg is  # line 3:
> the arg is b = 3
>
>
> If I try to write a macro:
>
>
> julia> macro my(exp)
>   for i in exp.args
>   println("the arg is ", eval(i))
>   end
>   end
>
> and call it like this:
>
>
> julia> @my :e
> the arg is begin  # none, line 2:
> a = 2 # line 3:
> b = 3
> end
>
>
> it does all the elements at once.
>
> It's probably a simple thing, but I could do with a hint!
>
> cheers
>
>


Re: [julia-users] Passing an expression to a macro

2014-09-09 Thread Jacob Quinn
The key here is that you want your macro to return an expression, not
necessarily do the computation itself. So instead of

macro my(exp)
for i in exp.args
println("the arg is ", eval(i))
end
end

You want something like:

macro my(exp)
quote
for i in $(exp.args)
println("the arg is ", i)
end

end
end

Which gives you:

In  [21]: @my quote
   a = 2
   b  = 3
end
the arg is begin  # In[21], line 2:
a = 2 # line 3:
b = 3
end

​

On Tue, Sep 9, 2014 at 12:42 PM,  wrote:

> Just puzzling over this simple problem I'm having while learning about
> macros. Here's an expression:
>
> julia> e = quote
>a = 2
>b  = 3
>end
>
> quote  # none, line 2:
> a = 2 # line 3:
> b = 3
> end
>
>
> If I go through this simply, I'll get a crack at each element of the args
> array:
>
>
>
> julia> for i in e.args
>println("the arg is ", i)
>end
>
>
>
> the arg is  # none, line 2:
> the arg is a = 2
> the arg is  # line 3:
> the arg is b = 3
>
>
> If I try to write a macro:
>
>
> julia> macro my(exp)
>   for i in exp.args
>   println("the arg is ", eval(i))
>   end
>   end
>
> and call it like this:
>
>
> julia> @my :e
> the arg is begin  # none, line 2:
> a = 2 # line 3:
> b = 3
> end
>
>
> it does all the elements at once.
>
> It's probably a simple thing, but I could do with a hint!
>
> cheers
>
>


[julia-users] Passing an expression to a macro

2014-09-09 Thread cormullion
Just puzzling over this simple problem I'm having while learning about 
macros. Here's an expression:

julia> e = quote
   a = 2
   b  = 3
   end

quote  # none, line 2:
a = 2 # line 3:
b = 3
end


If I go through this simply, I'll get a crack at each element of the args 
array: 

 

julia> for i in e.args
   println("the arg is ", i)
   end

 

the arg is  # none, line 2:
the arg is a = 2
the arg is  # line 3:
the arg is b = 3


If I try to write a macro:
 

julia> macro my(exp)
  for i in exp.args
  println("the arg is ", eval(i))
  end
  end

and call it like this:
 

julia> @my :e
the arg is begin  # none, line 2:
a = 2 # line 3:
b = 3
end


it does all the elements at once.

It's probably a simple thing, but I could do with a hint!

cheers



[julia-users] How to read julia code?

2014-09-09 Thread Andreas Lobinger
Hello colleagues,

the obvious answer to the literal question is: Open the file and use your 
favorite method of text-to-mind-transfer.

However, the question goes deeper: Are there tools available that help me 
(or anyone) understanding a given program structure?

More than once now, i thought: Well, extending that package should be easy, 
but later it was medium sized complicated, as the program structure was 
somehow hidden inside a type hierarchy. And just a call graph would have 
been nice.

In other environments i'd use a debugger (and some breakpoints) or some 
tools for tracing. Or the find function in the text editor. 
In Julia programs due to multiple dispatch the function name tells me only 
half of the story which part of the source to read, i need the type of the 
argument also.

I played around with the Profiler, but as it is sampling, not all the 
called code is showing up. 

Do i miss something obvious for tooling?

Wishing a happy day,
   Andreas


Re: [julia-users] Very Stupid Question

2014-09-09 Thread Duncan Parker
Many thanks!

On Tuesday, September 9, 2014 11:27:15 AM UTC-4, Isaiah wrote:
>
> You will probably want to start by looking at:
>
> - the embedding section of the manual
> - the pyjulia repository
>
> And see also: JavaCall package, for going the other direction.
>  On Sep 9, 2014 10:58 AM, "Duncan Parker"  > wrote:
>
>> Hello all,
>>
>> I'm a novice programmer (about a year in) curious to integrate Julia into 
>> a new Java application.  The Java shell is designed to be both a GUI for 
>> charting various types commodity prices and executing code (i.e. Julia -- 
>> currently JavaScript) for algorithmic trading.  
>>
>> Now, the stupid part:
>> Is there some sort of compiler necessary for Julia to be interpreted by 
>> the Java application?
>>
>> Thanks in advance for your patience with my ignorance.  I appear to be 
>> missing something very basic.
>>
>> Cheers,
>> Duncan
>>
>>

[julia-users] Re: Type returned by div

2014-09-09 Thread Leonardo Taccari
Fair enough.

Il giorno martedì 9 settembre 2014 17:43:59 UTC+2, Steven G. Johnson ha 
scritto:
>
>
>
> On Tuesday, September 9, 2014 10:47:02 AM UTC-4, Leonardo Taccari wrote:
>>
>> Why does div() with non-Int arguments return a non-Int? 
>> E.g., div(27,2.3) returns a Float64. I would expect it to be an Int, 
>> while it seems I have to manually convert the result to Int.
>>
>
> A floating-point value is necessary to capture the possible range of 
> results.  e.g. what would you want div(27e82, 2.3) to return? 
>


Re: [julia-users] intermediate results with reduce / FoldList

2014-09-09 Thread John Drummond
That's very helpful. Thank you both.
 I'd only got to
a route with map and a closure  
for plus
let y = 0;map(x->(g() = y += x; g()),1:10);end


Thanks,
John.

On Tuesday, September 9, 2014 4:47:30 PM UTC+1, Shashi Gowda wrote:
>
> or rather,
>
> julia> cumfoldl(f, x0, itr) = foldl((a, b) -> push!(a, f(a[end], b)), 
> [x0], itr)
> julia> cumfoldl(*, "0", map(string, 1:10))
> 11-element Array{ASCIIString,1}:
>  "0"   
>  "01"  
>  "012" 
>  "0123"
>  "01234"   
>  "012345"  
>  "0123456" 
>  "01234567"
>  "012345678"   
>  "0123456789"  
>  "012345678910"
>
>
> On Tue, Sep 9, 2014 at 9:15 PM, Shashi Gowda  > wrote:
>
>> In this particular case, cumsum does exactly this,
>>
>> julia> cumsum([1:10])
>> 10-element Array{Int64,1}:
>>   1
>>   3
>>   6
>>  10
>>  15
>>  21
>>  28
>>  36
>>  45
>>  55
>>
>> I guess that would be idiomatic Julia ;)
>>
>> An equivalent foldl would be
>> foldl((a, b) -> push!(a, a[end]+b), Int[1], [2:10])
>> 10-element Array{Int64,1}:
>>   1
>>   3
>>   6
>>  10
>>  15
>>  21
>>  28
>>  36
>>  45
>>  55
>>
>> A generic cumfoldl would be
>>
>> julia> cumfoldl(f, x0, itr) = foldl((a, b) -> push!(a, f(a[end], b)), 
>> [itr[1]], itr[2:end])
>> cumfoldl (generic function with 1 method)
>>
>> julia> cumfoldl(*, 0, map(string, 1:10))
>> 10-element Array{ASCIIString,1}:
>>  "1"  
>>  "12" 
>>  "123"
>>  "1234"   
>>  "12345"  
>>  "123456" 
>>  "1234567"
>>  "12345678"   
>>  "123456789"  
>>  "12345678910"
>>
>>
>> I often find it useful to remind myself that foldl(push!, eltype(list)[], 
>> list) constructs the same list and take it from there.
>>
>
>

Re: [julia-users] intermediate results with reduce / FoldList

2014-09-09 Thread Shashi Gowda
or rather,

julia> cumfoldl(f, x0, itr) = foldl((a, b) -> push!(a, f(a[end], b)), [x0],
itr)
julia> cumfoldl(*, "0", map(string, 1:10))
11-element Array{ASCIIString,1}:
 "0"
 "01"
 "012"
 "0123"
 "01234"
 "012345"
 "0123456"
 "01234567"
 "012345678"
 "0123456789"
 "012345678910"


On Tue, Sep 9, 2014 at 9:15 PM, Shashi Gowda 
wrote:

> In this particular case, cumsum does exactly this,
>
> julia> cumsum([1:10])
> 10-element Array{Int64,1}:
>   1
>   3
>   6
>  10
>  15
>  21
>  28
>  36
>  45
>  55
>
> I guess that would be idiomatic Julia ;)
>
> An equivalent foldl would be
> foldl((a, b) -> push!(a, a[end]+b), Int[1], [2:10])
> 10-element Array{Int64,1}:
>   1
>   3
>   6
>  10
>  15
>  21
>  28
>  36
>  45
>  55
>
> A generic cumfoldl would be
>
> julia> cumfoldl(f, x0, itr) = foldl((a, b) -> push!(a, f(a[end], b)),
> [itr[1]], itr[2:end])
> cumfoldl (generic function with 1 method)
>
> julia> cumfoldl(*, 0, map(string, 1:10))
> 10-element Array{ASCIIString,1}:
>  "1"
>  "12"
>  "123"
>  "1234"
>  "12345"
>  "123456"
>  "1234567"
>  "12345678"
>  "123456789"
>  "12345678910"
>
>
> I often find it useful to remind myself that foldl(push!, eltype(list)[],
> list) constructs the same list and take it from there.
>


Re: [julia-users] intermediate results with reduce / FoldList

2014-09-09 Thread Shashi Gowda
In this particular case, cumsum does exactly this,

julia> cumsum([1:10])
10-element Array{Int64,1}:
  1
  3
  6
 10
 15
 21
 28
 36
 45
 55

I guess that would be idiomatic Julia ;)

An equivalent foldl would be
foldl((a, b) -> push!(a, a[end]+b), Int[1], [2:10])
10-element Array{Int64,1}:
  1
  3
  6
 10
 15
 21
 28
 36
 45
 55

A generic cumfoldl would be

julia> cumfoldl(f, x0, itr) = foldl((a, b) -> push!(a, f(a[end], b)),
[itr[1]], itr[2:end])
cumfoldl (generic function with 1 method)

julia> cumfoldl(*, 0, map(string, 1:10))
10-element Array{ASCIIString,1}:
 "1"
 "12"
 "123"
 "1234"
 "12345"
 "123456"
 "1234567"
 "12345678"
 "123456789"
 "12345678910"


I often find it useful to remind myself that foldl(push!, eltype(list)[],
list) constructs the same list and take it from there.


[julia-users] Re: Type returned by div

2014-09-09 Thread Steven G. Johnson


On Tuesday, September 9, 2014 10:47:02 AM UTC-4, Leonardo Taccari wrote:
>
> Why does div() with non-Int arguments return a non-Int? 
> E.g., div(27,2.3) returns a Float64. I would expect it to be an Int, while 
> it seems I have to manually convert the result to Int.
>

A floating-point value is necessary to capture the possible range of 
results.  e.g. what would you want div(27e82, 2.3) to return? 


Re: [julia-users] Very Stupid Question

2014-09-09 Thread Isaiah Norton
You will probably want to start by looking at:

- the embedding section of the manual
- the pyjulia repository

And see also: JavaCall package, for going the other direction.
 On Sep 9, 2014 10:58 AM, "Duncan Parker"  wrote:

> Hello all,
>
> I'm a novice programmer (about a year in) curious to integrate Julia into
> a new Java application.  The Java shell is designed to be both a GUI for
> charting various types commodity prices and executing code (i.e. Julia --
> currently JavaScript) for algorithmic trading.
>
> Now, the stupid part:
> Is there some sort of compiler necessary for Julia to be interpreted by
> the Java application?
>
> Thanks in advance for your patience with my ignorance.  I appear to be
> missing something very basic.
>
> Cheers,
> Duncan
>
>


Re: [julia-users] How do you change the default location for package installation in Windows?

2014-09-09 Thread Freddy Svensson
Hi, can you show exactly how to change prepare-julia-env.bat to have 
JULIA_PKGDIR and other ENV variables preset when Julia loads, adding an 
empty line and then set JULIA_PKGDIR=C:\julia_pkg does not work for me.

Thanks, FS



On Friday, 8 November 2013 00:00:28 UTC+1, Dave Ramsey wrote:
>
> Hi,  thanks for the reply.   That appeared to work.   For others that will 
> read this post you need to modify the file prepare-julia-env.bat and add 
> the line (for example)
> set JULIA_PKGDIR=c:\users\xxx\juliapackages
>
> or something similar.  Out of the box Julia v0.2 rc2 was creating the 
> .julia folder on one of my network drives  H:\.julia and there were some 
> permission problems associated with package installation.   Setting the 
> package directory to a local drive solved the problem.   Why Julia was 
> going to a network drive in the first place a mystery.   As my previous 
> post mentioned the v0.2prerelease version did not do this.  
>
> Thanks again for your help
> cheers
> Dave
>
>
> On Thursday, November 7, 2013 6:33:23 PM UTC+11, Elliot Saba wrote:
>>
>> Hello there!  You can set the JULIA_PKGDIR environment variable to a 
>> different directory, and that will change where the packages are stored. 
>>  (It will not create a .julia directory inside of whatever JULIA_PKGDIR 
>> points to, so for instance you set JULIA_PKGDIR equal to 
>> "C:\Users\MyUsername\JuliaPackages" and it would store the packages 
>> directory inside that folder).
>>
>> Could you post the error that it is encountering?  Permissions likely 
>> should not be an issue on your local disk, as we take pains to choose 
>> default locations you should have write access to.
>> -E
>>
>>
>> On Wed, Nov 6, 2013 at 4:20 PM, Dave Ramsey  wrote:
>>
>>> Hi,  Newbie question here.   I am using Julia v0.2-rc2 on a 32 bit 
>>> Windows 7 machine.   I wish to change the default location of my installed 
>>> packages (i.e. the location of my .julia folder).  There doesn't appear to 
>>> be anything relevant in the package documentation or the list that I can 
>>> find?   Since upgrading from 0.2prerelease I can no longer install packages 
>>> and was wondering if the new default package location is the cause (I'm 
>>> behind a work network).   
>>>
>>> thanks for you help
>>> Dave
>>>
>>>
>>>
>>>
>>

Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Ján Dolinský

Hello Andreas,

Thanks for the tip. I'll check it out. Thumbs up for the 0.4!

Jan

On 09.09.2014 17:04, Andreas Noack wrote:
If you need the speed now you can try one of the package ArrayViews or 
ArrayViewsAPL. It is something similar to the functionality in these 
packages that we are trying to include in base.


Med venlig hilsen

Andreas Noack

2014-09-09 9:38 GMT-04:00 Ján Dolinský >:


OK, so basically there is nothing wrong with the syntax
X[:,1001:end] ?
|
d =sumabs2(X[:,1001:end],1);
|
||and I should just wait until v0.4 is available (perhaps
available soon in Julia Nightlies PPA).

I did the benchmark with the floating point power function based
on Simon's comment. Here are my results (after couple of
repetitive iterations):
|
@time X.^2;
elapsed time: 0.511988142 seconds (392000256 bytes allocated,
2.52% gc time)
@time X.^2.0;
elapsed time: 0.411791612 seconds (392000256 bytes allocated,
3.12% gc time)
|

Thanks,
Jan Dolinsky

On 09.09.2014 14:06, Andreas Noack wrote:

The problem is that right now X[:,1001,end] makes a copy of the
array. However,  in 0.4 this will instead be a view of the
original matrix and therefore the computing time should be almost
the same.

It might also be worth repeating Simon's comment that the
floating point power function has special handling of 2. The
result is that

julia> @time A.^2;
elapsed time: 1.402791357 seconds (20256 bytes allocated,
5.90% gc time)

julia> @time A.^2.0;
elapsed time: 0.554241105 seconds (20256 bytes allocated,
15.04% gc time)

I tend to agree with Simon that special casing of integer 2 would
be reasonable.

Med venlig hilsen

Andreas Noack

2014-09-09  4:24 GMT-04:00 Ján Dolinský
mailto:jan.dolin...@2bridgz.com>>:

Hello guys,

Thanks a lot for the lengthy discussions. It helped me a lot
to get a feeling on what is Julia like. I did some more
performance comparisons as suggested by first two posts
(thanks a lot for the tips). In the mean time I upgraded to v0.3.
|
X =rand(7000,7000);
@timed =sum(X.^2,1);
elapsed time:0.573125833seconds (392056672bytes
allocated,2.25%gc time)
@timed =sum(X.*X,1);
elapsed time:0.178715901seconds (392057080bytes
allocated,14.06%gc time)
@timed =sumabs2(X,1);
elapsed time:0.067431808seconds (56496bytes allocated)
|

In Octave then
|
X =rand(7000);
tic;d =sum(X.^2);toc;
Elapsedtime is0.167578seconds.
|

So the ultimate solution is the sumabs2 function which is a
blast. I am comming from Matlab/Octave and I would expect
X.^2 to be fast "out of the box" but nevertheless if I can
get an excellent performance by learning some new paradigms I
will go for it.

The above tests lead me to another question. I often need to
calculate the "self" dot product over a portion of a matrix, e.g.
|
@timed =sumabs2(X[:,1001:end],1);
elapsed time:0.17566seconds (336048688bytes
allocated,7.01%gc time)
|

Apparently this is not a way to do it in Julia because
working on a smaller matrix of 7000x6000 gives more than
double computing time and furthermore it seems to allocate
unnecessary memory.

Best Regards,
Jan



Dňa pondelok, 8. septembra 2014 10:36:02 UTC+2 Ján Dolinský
napísal(-a):

Hello,

I am a new Julia user. I am trying to write a function
for computing "self" dot product of all columns in a
matrix, i.e. calculating a square of each element of a
matrix and computing a column-wise sum. I am interested
in a proper way of doing it because I often need to
process large matrices.

I first put a focus on calculating the squares. For
testing purposes I use a matrix of random floats of size
7000x7000. All timings here are deducted after several
repetitive runs.

I used to do it in Octave (v3.8.1) a follows:
|
tic;X =rand(7000);toc;
Elapsedtime is0.579093seconds.
tic;XX =X.^2;toc;
Elapsedtime is0.114737seconds.
|


I tried to to the same in Julia (v0.2.1):
|
@timeX =rand(7000,7000);
elapsed time:0.114418731seconds (392000128bytes allocated)
@timeXX =X.^2;
elapsed time:0.369641268seconds (392000224bytes allocated)
|

I was surprised to see that Julia is about 3 times slower
when calculating a square than my original routine in
Octave. I then read "Performance tips" and fo

Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Andreas Noack
If you need the speed now you can try one of the package ArrayViews or
ArrayViewsAPL. It is something similar to the functionality in these
packages that we are trying to include in base.

Med venlig hilsen

Andreas Noack

2014-09-09 9:38 GMT-04:00 Ján Dolinský :

>  OK, so basically there is nothing wrong with the syntax X[:,1001:end] ?
>
>  d = sumabs2(X[:,1001:end], 1);
>  and I should just wait until v0.4 is available (perhaps available soon
> in Julia Nightlies PPA).
>
> I did the benchmark with the floating point power function based on
> Simon's comment. Here are my results (after couple of repetitive
> iterations):
>  @time X.^2;
> elapsed time: 0.511988142 seconds (392000256 bytes allocated, 2.52% gc
> time)
> @time X.^2.0;
> elapsed time: 0.411791612 seconds (392000256 bytes allocated, 3.12% gc
> time)
>
> Thanks,
> Jan Dolinsky
>
>  On 09.09.2014 14:06, Andreas Noack wrote:
>
> The problem is that right now X[:,1001,end] makes a copy of the array.
> However,  in 0.4 this will instead be a view of the original matrix and
> therefore the computing time should be almost the same.
>
>  It might also be worth repeating Simon's comment that the floating point
> power function has special handling of 2. The result is that
>
> julia> @time A.^2;
> elapsed time: 1.402791357 seconds (20256 bytes allocated, 5.90% gc
> time)
>
> julia> @time A.^2.0;
> elapsed time: 0.554241105 seconds (20256 bytes allocated, 15.04% gc
> time)
>
>  I tend to agree with Simon that special casing of integer 2 would be
> reasonable.
>
>  Med venlig hilsen
>
> Andreas Noack
>
> 2014-09-09 4:24 GMT-04:00 Ján Dolinský :
>
>> Hello guys,
>>
>> Thanks a lot for the lengthy discussions. It helped me a lot to get a
>> feeling on what is Julia like. I did some more performance comparisons as
>> suggested by first two posts (thanks a lot for the tips). In the mean time
>> I upgraded to v0.3.
>>  X = rand(7000,7000);
>> @time d = sum(X.^2, 1);
>> elapsed time: 0.573125833 seconds (392056672 bytes allocated, 2.25% gc
>> time)
>> @time d = sum(X.*X, 1);
>> elapsed time: 0.178715901 seconds (392057080 bytes allocated, 14.06% gc
>> time)
>> @time d = sumabs2(X, 1);
>> elapsed time: 0.067431808 seconds (56496 bytes allocated)
>>
>> In Octave then
>>  X = rand(7000);
>> tic; d = sum(X.^2); toc;
>> Elapsed time is 0.167578 seconds.
>>
>> So the ultimate solution is the sumabs2 function which is a blast. I am
>> comming from Matlab/Octave and I would expect X.^2 to be fast "out of the
>> box" but nevertheless if I can get an excellent performance by learning
>> some new paradigms I will go for it.
>>
>> The above tests lead me to another question. I often need to calculate
>> the "self" dot product over a portion of a matrix, e.g.
>>  @time d = sumabs2(X[:,1001:end], 1);
>> elapsed time: 0.17566 seconds (336048688 bytes allocated, 7.01% gc
>> time)
>>
>> Apparently this is not a way to do it in Julia because working on a
>> smaller matrix of 7000x6000 gives more than double computing time and
>> furthermore it seems to allocate unnecessary memory.
>>
>> Best Regards,
>> Jan
>>
>>
>>
>> Dňa pondelok, 8. septembra 2014 10:36:02 UTC+2 Ján Dolinský napísal(-a):
>>
>>> Hello,
>>>
>>> I am a new Julia user. I am trying to write a function for computing
>>> "self" dot product of all columns in a matrix, i.e. calculating a square of
>>> each element of a matrix and computing a column-wise sum. I am interested
>>> in a proper way of doing it because I often need to process large matrices.
>>>
>>> I first put a focus on calculating the squares. For testing purposes I
>>> use a matrix of random floats of size 7000x7000. All timings here are
>>> deducted after several repetitive runs.
>>>
>>> I used to do it in Octave (v3.8.1) a follows:
>>>  tic; X = rand(7000); toc;
>>> Elapsed time is 0.579093 seconds.
>>> tic; XX = X.^2; toc;
>>> Elapsed time is 0.114737 seconds.
>>>
>>>
>>> I tried to to the same in Julia (v0.2.1):
>>>  @time X = rand(7000,7000);
>>> elapsed time: 0.114418731 seconds (392000128 bytes allocated)
>>> @time XX = X.^2;
>>> elapsed time: 0.369641268 seconds (392000224 bytes allocated)
>>>
>>> I was surprised to see that Julia is about 3 times slower when
>>> calculating a square than my original routine in Octave. I then read
>>> "Performance tips" and found out that one should use * instead of of
>>> raising to small integer powers, for example x*x*x instead of x^3. I
>>> therefore tested the following.
>>>  @time XX = X.*X;
>>> elapsed time: 0.146059577 seconds (392000968 bytes allocated)
>>>
>>> This approach indeed resulted in a lot shorter computing time. It is
>>> still however a little slower than my code in Octave. Can someone advise on
>>> any performance tips ?
>>>
>>> I then finally do a sum over all columns of XX to get the "self" dot
>>> product but first I'd like to fix the squaring part.
>>>
>>> Thanks a lot.
>>> Best Regards,
>>> Jan
>>>
>>> p.s. In Julia manual I found a while ago an example of using @vectorize

Re: [julia-users] intermediate results with reduce / FoldList

2014-09-09 Thread John Myles White
I don't believe this exists, but it should be easy to write by combining ideas 
from Julia's cumsum and foldl. You'd end up with cumfoldl and cumfoldr.

 -- John

On Sep 9, 2014, at 7:29 AM, John Drummond  wrote:

> What's the idiomatic way of writing Mathematica's Foldlist in Julia?
> i.e. a fold that gives the intermediate results?
> 
> e.g. in Mathematica
> Fold[Plus, 1, Rest[Range[10]]] 
> gives
> 55
> and 
> FoldList[Plus, 1, Rest[Range[10]]]
> gives
> {1, 3, 6, 10, 15, 21, 28, 36, 45, 55}
> 
> 
> in Julia
>  foldl(+,1,2:10)
> gives
> 55
> 
> what's the idiomatic way of giving the intermediate results in an array?
> Thanks
> 
> kind Regards, John.
> 
> 
> 
> 



[julia-users] Very Stupid Question

2014-09-09 Thread Duncan Parker
Hello all,

I'm a novice programmer (about a year in) curious to integrate Julia into a 
new Java application.  The Java shell is designed to be both a GUI for 
charting various types commodity prices and executing code (i.e. Julia -- 
currently JavaScript) for algorithmic trading.  

Now, the stupid part:
Is there some sort of compiler necessary for Julia to be interpreted by the 
Java application?

Thanks in advance for your patience with my ignorance.  I appear to be 
missing something very basic.

Cheers,
Duncan



Re: [julia-users] Interact + PyPlot: only update when releasing slider

2014-09-09 Thread Steven G. Johnson


On Monday, September 8, 2014 11:15:05 AM UTC-4, Andrei Berceanu wrote:
>
> Another option would be to use drop-down boxes with selectable values or 
> custom text boxes instead of sliders, at least as a temporary fix. Anyone 
> knows how I can do that?
>

Just wrap dropdown(...) around the range to get a dropdown menu instead of 
a slider:

@manipulate for n in dropdown(1:5)
...
end

By the way, iirc, IPython does have the update-on-release mechanism 
> implemented in their interactive widget functionality.
>>
>>
We are using the same JavaScript widgets as IPython.  Maybe you just need 
to set some option when the widget is created?
 


[julia-users] Type returned by div

2014-09-09 Thread Leonardo Taccari
Hello,
sorry if this was asked before, I'm a beginner here.

Why does div() with non-Int arguments return a non-Int? 
E.g., div(27,2.3) returns a Float64. I would expect it to be an Int, while 
it seems I have to manually convert the result to Int.


[julia-users] intermediate results with reduce / FoldList

2014-09-09 Thread John Drummond
What's the idiomatic way of writing Mathematica's Foldlist in Julia?
i.e. a fold that gives the intermediate results?

e.g. in Mathematica
Fold[Plus, 1, Rest[Range[10]]] 
gives
55
and 
FoldList[Plus, 1, Rest[Range[10]]]
gives
{1, 3, 6, 10, 15, 21, 28, 36, 45, 55}


in Julia
 foldl(+,1,2:10)
gives
55

what's the idiomatic way of giving the intermediate results in an array?
Thanks

kind Regards, John.






Re: [julia-users] Embed julia in C/C++

2014-09-09 Thread Einar Otnes
Isaiah,
Thank you so much for this. This  really help and hopefully I can move on
making some progress...

Einar


On Tue, Sep 9, 2014 at 4:06 PM, Isaiah Norton 
wrote:

> julia> cval(x) = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},), x)
> cval (generic function with 1 method)
>
> julia> cval("using DSP")
> Ptr{Void} @0x034bc280
>
> julia> cval("DSP.hanning")
> Ptr{Void} @0x306408a0
>
> julia> hanning = unsafe_pointer_to_objref(ptr)
> hanning (generic function with 1 method)
>
> On Tue, Sep 9, 2014 at 9:47 AM, Einar Otnes  wrote:
>
>> It seems that your suggestion using ccall from within julia to play
>> around with the c-api provides some info. Running your ccall command on a
>> couple of "External Packages", i.e. DSP and HDF5  returns the Null pointer.
>>
>> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"DSP.Pkg.hanning")
>> Ptr{Void} @0x
>>
>>
>> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.sin")
>> Ptr{Void} @0x02a431f0
>>
>> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.cos")
>> Ptr{Void} @0x032acfa0
>>
>> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"HDF5.Pkg.h5open")
>> Ptr{Void} @0x
>>
>>
>> So, it seems we are not able to get hold of the external packages from
>> within C. Any ideas?
>>
>> Best,
>>
>> Einar
>>
>>
>> On Fri, Sep 5, 2014 at 5:46 PM, Jake Bolewski 
>> wrote:
>>
>>> It's jl_eval_string located in jl_api.c in src.
>>>
>>> so you would do
>>> jl_value_t * func2 = jl_eval_string("DSP.hanning")
>>>
>>> The best way to play around with Julia's c-api is within julia itself.
>>> julia> pkg_ptr = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},),
>>> "Base.Pkg.clone")
>>> Ptr{Void} @0x7fd11c1754a0
>>>
>>> julia> unsafe_pointer_to_objref(ans)
>>> clone (generic function with 2 methods)
>>>
>>> julia> typeof(ans)
>>> Function
>>>
>>> That way you can prototype what you want much more easily.
>>>
>>> On Friday, September 5, 2014 9:32:43 AM UTC-4, Einar Otnes wrote:

 Thank you for your help on this. It seems that the 'jl_eval_global_var'
 function is local as I got the error "undefined reference to
 `jl_eval_global_var'" when linking. I replaced
 your suggestion with:

 jl_module_t* jl_dsp_module = (jl_module_t*)
 jl_get_binding(jl_main_module, jl_symbol("DSP"));
 jl_function_t* func2 = jl_get_function(jl_dsp_module,"hanning");

 This compiles OK, but I get a "segfault  (core dumped)" when running
 the line with 'jl_get_function' .

 Any ideas or thoughts?

 Thanks,

 Einar








 On Fri, Sep 5, 2014 at 11:15 AM, Ivar Nesje  wrote:

> I would guess that something like
>
> module = jl_eval_global_var
> 
> (jl_main_module, jl_sym
> 
> ("MyModule"))
>
> would work, but I don't have the required testing setup to see if it
> actually works. (Where is my C REPL?) The embedding API has not gotten 
> much
> attention (yet), so it is mostly documented in source, and it is likely
> that there will be some adjustments.
>
>
> On Friday, September 5, 2014 10:09:03 AM UTC+2, Einar Otnes wrote:
>>
>> Sorry, I'm a bit slow. How do I look up a binding for a specific
>> module? In other words, how would I explicitly get to call the "fftfreq"
>> function in the "DSP" module from C/C++?
>>
>> Is this this documented anywhere in Julia docs?
>>
>> Thanks,
>> Einar
>>
>>
>>
>> On Wednesday, September 3, 2014 3:10:59 PM UTC+2, Isaiah wrote:
>>>
>>> If you have defined a module already (by eval'ing julia code?) then
>>> you can look up the binding and cast that to a jl_module_t.
>>> On Sep 3, 2014 8:14 AM, "Einar Otnes"  wrote:
>>>
 Dear experts,

 I've looking at the documentation " Embedding Julia" (
 http://julia.readthedocs.org/en/latest/manual/embedding/) to
 figure out how I can call my own julia functions from within C, and I'm
 struggling to figure out how I should define the jl_module_t that
 corresponds the module I've defined. The examples show that there is an
 instance of jl_module_t,  "jl_base_module",  that you need to provide 
 to be
 able to call a function defined in the base module. How do I define a
 corresponding jl_module_t type for the modules that are defined 
 outside of
 standard julia, e.g. for the external packages or the modules I have
 created myself?

 Thanks for your help.

 Best regards,

 Einar Otnes



>>
>


Re: [julia-users] Embed julia in C/C++

2014-09-09 Thread Isaiah Norton
julia> cval(x) = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},), x)
cval (generic function with 1 method)

julia> cval("using DSP")
Ptr{Void} @0x034bc280

julia> cval("DSP.hanning")
Ptr{Void} @0x306408a0

julia> hanning = unsafe_pointer_to_objref(ptr)
hanning (generic function with 1 method)

On Tue, Sep 9, 2014 at 9:47 AM, Einar Otnes  wrote:

> It seems that your suggestion using ccall from within julia to play around
> with the c-api provides some info. Running your ccall command on a couple
> of "External Packages", i.e. DSP and HDF5  returns the Null pointer.
>
> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"DSP.Pkg.hanning")
> Ptr{Void} @0x
>
>
> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.sin")
> Ptr{Void} @0x02a431f0
>
> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.cos")
> Ptr{Void} @0x032acfa0
>
> pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"HDF5.Pkg.h5open")
> Ptr{Void} @0x
>
>
> So, it seems we are not able to get hold of the external packages from
> within C. Any ideas?
>
> Best,
>
> Einar
>
>
> On Fri, Sep 5, 2014 at 5:46 PM, Jake Bolewski 
> wrote:
>
>> It's jl_eval_string located in jl_api.c in src.
>>
>> so you would do
>> jl_value_t * func2 = jl_eval_string("DSP.hanning")
>>
>> The best way to play around with Julia's c-api is within julia itself.
>> julia> pkg_ptr = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},),
>> "Base.Pkg.clone")
>> Ptr{Void} @0x7fd11c1754a0
>>
>> julia> unsafe_pointer_to_objref(ans)
>> clone (generic function with 2 methods)
>>
>> julia> typeof(ans)
>> Function
>>
>> That way you can prototype what you want much more easily.
>>
>> On Friday, September 5, 2014 9:32:43 AM UTC-4, Einar Otnes wrote:
>>>
>>> Thank you for your help on this. It seems that the 'jl_eval_global_var'
>>> function is local as I got the error "undefined reference to
>>> `jl_eval_global_var'" when linking. I replaced
>>> your suggestion with:
>>>
>>> jl_module_t* jl_dsp_module = (jl_module_t*)
>>> jl_get_binding(jl_main_module, jl_symbol("DSP"));
>>> jl_function_t* func2 = jl_get_function(jl_dsp_module,"hanning");
>>>
>>> This compiles OK, but I get a "segfault  (core dumped)" when running the
>>> line with 'jl_get_function' .
>>>
>>> Any ideas or thoughts?
>>>
>>> Thanks,
>>>
>>> Einar
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Fri, Sep 5, 2014 at 11:15 AM, Ivar Nesje  wrote:
>>>
 I would guess that something like

 module = jl_eval_global_var
 
 (jl_main_module, jl_sym
 
 ("MyModule"))

 would work, but I don't have the required testing setup to see if it
 actually works. (Where is my C REPL?) The embedding API has not gotten much
 attention (yet), so it is mostly documented in source, and it is likely
 that there will be some adjustments.


 On Friday, September 5, 2014 10:09:03 AM UTC+2, Einar Otnes wrote:
>
> Sorry, I'm a bit slow. How do I look up a binding for a specific
> module? In other words, how would I explicitly get to call the "fftfreq"
> function in the "DSP" module from C/C++?
>
> Is this this documented anywhere in Julia docs?
>
> Thanks,
> Einar
>
>
>
> On Wednesday, September 3, 2014 3:10:59 PM UTC+2, Isaiah wrote:
>>
>> If you have defined a module already (by eval'ing julia code?) then
>> you can look up the binding and cast that to a jl_module_t.
>> On Sep 3, 2014 8:14 AM, "Einar Otnes"  wrote:
>>
>>> Dear experts,
>>>
>>> I've looking at the documentation " Embedding Julia" (
>>> http://julia.readthedocs.org/en/latest/manual/embedding/) to figure
>>> out how I can call my own julia functions from within C, and I'm 
>>> struggling
>>> to figure out how I should define the jl_module_t that corresponds the
>>> module I've defined. The examples show that there is an instance of
>>> jl_module_t,  "jl_base_module",  that you need to provide to be able to
>>> call a function defined in the base module. How do I define a 
>>> corresponding
>>> jl_module_t type for the modules that are defined outside of standard
>>> julia, e.g. for the external packages or the modules I have created 
>>> myself?
>>>
>>> Thanks for your help.
>>>
>>> Best regards,
>>>
>>> Einar Otnes
>>>
>>>
>>>
>


Re: [julia-users] Embed julia in C/C++

2014-09-09 Thread Einar Otnes
It seems that your suggestion using ccall from within julia to play around
with the c-api provides some info. Running your ccall command on a couple
of "External Packages", i.e. DSP and HDF5  returns the Null pointer.

pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"DSP.Pkg.hanning")
Ptr{Void} @0x


pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.sin")
Ptr{Void} @0x02a431f0

pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"Base.Pkg.cos")
Ptr{Void} @0x032acfa0

pkg_ptr = ccall(:jl_eval_string,Ptr{Void},(Ptr{Cchar},),"HDF5.Pkg.h5open")
Ptr{Void} @0x


So, it seems we are not able to get hold of the external packages from
within C. Any ideas?

Best,

Einar


On Fri, Sep 5, 2014 at 5:46 PM, Jake Bolewski 
wrote:

> It's jl_eval_string located in jl_api.c in src.
>
> so you would do
> jl_value_t * func2 = jl_eval_string("DSP.hanning")
>
> The best way to play around with Julia's c-api is within julia itself.
> julia> pkg_ptr = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},),
> "Base.Pkg.clone")
> Ptr{Void} @0x7fd11c1754a0
>
> julia> unsafe_pointer_to_objref(ans)
> clone (generic function with 2 methods)
>
> julia> typeof(ans)
> Function
>
> That way you can prototype what you want much more easily.
>
> On Friday, September 5, 2014 9:32:43 AM UTC-4, Einar Otnes wrote:
>>
>> Thank you for your help on this. It seems that the 'jl_eval_global_var'
>> function is local as I got the error "undefined reference to
>> `jl_eval_global_var'" when linking. I replaced
>> your suggestion with:
>>
>> jl_module_t* jl_dsp_module = (jl_module_t*)
>> jl_get_binding(jl_main_module, jl_symbol("DSP"));
>> jl_function_t* func2 = jl_get_function(jl_dsp_module,"hanning");
>>
>> This compiles OK, but I get a "segfault  (core dumped)" when running the
>> line with 'jl_get_function' .
>>
>> Any ideas or thoughts?
>>
>> Thanks,
>>
>> Einar
>>
>>
>>
>>
>>
>>
>>
>>
>> On Fri, Sep 5, 2014 at 11:15 AM, Ivar Nesje  wrote:
>>
>>> I would guess that something like
>>>
>>> module = jl_eval_global_var
>>> 
>>> (jl_main_module, jl_sym
>>> 
>>> ("MyModule"))
>>>
>>> would work, but I don't have the required testing setup to see if it
>>> actually works. (Where is my C REPL?) The embedding API has not gotten much
>>> attention (yet), so it is mostly documented in source, and it is likely
>>> that there will be some adjustments.
>>>
>>>
>>> On Friday, September 5, 2014 10:09:03 AM UTC+2, Einar Otnes wrote:

 Sorry, I'm a bit slow. How do I look up a binding for a specific
 module? In other words, how would I explicitly get to call the "fftfreq"
 function in the "DSP" module from C/C++?

 Is this this documented anywhere in Julia docs?

 Thanks,
 Einar



 On Wednesday, September 3, 2014 3:10:59 PM UTC+2, Isaiah wrote:
>
> If you have defined a module already (by eval'ing julia code?) then
> you can look up the binding and cast that to a jl_module_t.
> On Sep 3, 2014 8:14 AM, "Einar Otnes"  wrote:
>
>> Dear experts,
>>
>> I've looking at the documentation " Embedding Julia" (
>> http://julia.readthedocs.org/en/latest/manual/embedding/) to figure
>> out how I can call my own julia functions from within C, and I'm 
>> struggling
>> to figure out how I should define the jl_module_t that corresponds the
>> module I've defined. The examples show that there is an instance of
>> jl_module_t,  "jl_base_module",  that you need to provide to be able to
>> call a function defined in the base module. How do I define a 
>> corresponding
>> jl_module_t type for the modules that are defined outside of standard
>> julia, e.g. for the external packages or the modules I have created 
>> myself?
>>
>> Thanks for your help.
>>
>> Best regards,
>>
>> Einar Otnes
>>
>>
>>


Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Ján Dolinský

OK, so basically there is nothing wrong with the syntax X[:,1001:end] ?
|
d =sumabs2(X[:,1001:end],1);
|
||and I should just wait until v0.4 is available (perhaps available soon 
in Julia Nightlies PPA).


I did the benchmark with the floating point power function based on 
Simon's comment. Here are my results (after couple of repetitive 
iterations):

|
@time X.^2;
elapsed time: 0.511988142 seconds (392000256 bytes allocated, 2.52% gc time)
@time X.^2.0;
elapsed time: 0.411791612 seconds (392000256 bytes allocated, 3.12% gc time)
|

Thanks,
Jan Dolinsky

On 09.09.2014 14:06, Andreas Noack wrote:
The problem is that right now X[:,1001,end] makes a copy of the array. 
However,  in 0.4 this will instead be a view of the original matrix 
and therefore the computing time should be almost the same.


It might also be worth repeating Simon's comment that the floating 
point power function has special handling of 2. The result is that


julia> @time A.^2;
elapsed time: 1.402791357 seconds (20256 bytes allocated, 5.90% gc 
time)


julia> @time A.^2.0;
elapsed time: 0.554241105 seconds (20256 bytes allocated, 15.04% 
gc time)


I tend to agree with Simon that special casing of integer 2 would be 
reasonable.


Med venlig hilsen

Andreas Noack

2014-09-09 4:24 GMT-04:00 Ján Dolinský >:


Hello guys,

Thanks a lot for the lengthy discussions. It helped me a lot to
get a feeling on what is Julia like. I did some more performance
comparisons as suggested by first two posts (thanks a lot for the
tips). In the mean time I upgraded to v0.3.
|
X =rand(7000,7000);
@timed =sum(X.^2,1);
elapsed time:0.573125833seconds (392056672bytes allocated,2.25%gc
time)
@timed =sum(X.*X,1);
elapsed time:0.178715901seconds (392057080bytes allocated,14.06%gc
time)
@timed =sumabs2(X,1);
elapsed time:0.067431808seconds (56496bytes allocated)
|

In Octave then
|
X =rand(7000);
tic;d =sum(X.^2);toc;
Elapsedtime is0.167578seconds.
|

So the ultimate solution is the sumabs2 function which is a blast.
I am comming from Matlab/Octave and I would expect X.^2 to be fast
"out of the box" but nevertheless if I can get an excellent
performance by learning some new paradigms I will go for it.

The above tests lead me to another question. I often need to
calculate the "self" dot product over a portion of a matrix, e.g.
|
@timed =sumabs2(X[:,1001:end],1);
elapsed time:0.17566seconds (336048688bytes allocated,7.01%gc
time)
|

Apparently this is not a way to do it in Julia because working on
a smaller matrix of 7000x6000 gives more than double computing
time and furthermore it seems to allocate unnecessary memory.

Best Regards,
Jan



Dňa pondelok, 8. septembra 2014 10:36:02 UTC+2 Ján Dolinský
napísal(-a):

Hello,

I am a new Julia user. I am trying to write a function for
computing "self" dot product of all columns in a matrix, i.e.
calculating a square of each element of a matrix and computing
a column-wise sum. I am interested in a proper way of doing it
because I often need to process large matrices.

I first put a focus on calculating the squares. For testing
purposes I use a matrix of random floats of size 7000x7000.
All timings here are deducted after several repetitive runs.

I used to do it in Octave (v3.8.1) a follows:
|
tic;X =rand(7000);toc;
Elapsedtime is0.579093seconds.
tic;XX =X.^2;toc;
Elapsedtime is0.114737seconds.
|


I tried to to the same in Julia (v0.2.1):
|
@timeX =rand(7000,7000);
elapsed time:0.114418731seconds (392000128bytes allocated)
@timeXX =X.^2;
elapsed time:0.369641268seconds (392000224bytes allocated)
|

I was surprised to see that Julia is about 3 times slower when
calculating a square than my original routine in Octave. I
then read "Performance tips" and found out that one should use
* instead of of raising to small integer powers, for example
x*x*x instead of x^3. I therefore tested the following.
|
@timeXX =X.*X;
elapsed time:0.146059577seconds (392000968bytes allocated)
|

This approach indeed resulted in a lot shorter computing time.
It is still however a little slower than my code in Octave.
Can someone advise on any performance tips ?

I then finally do a sum over all columns of XX to get the
"self" dot product but first I'd like to fix the squaring part.

Thanks a lot.
Best Regards,
Jan

p.s. In Julia manual I found a while ago an example of using
@vectorize macro with a squaring function but can not find it
any more. Perhaps the name of macro was different ...






Re: [julia-users] Embed julia in C/C++

2014-09-09 Thread Einar Otnes
I have now tried to go back to the basic example in the documentation by
calling a single valued function sigmoid from module NumericFuns using
jl_eval_string with no success. The code snippet below calling
"Base.sqrt(2.0)" works as anticipated, but the snippet calling
"NumericFuns.sigmoid(0.0)" ends up in a seg fault...

jl_value_t *ret = (jl_value_t*)(jl_eval_string("Base.sqrt(2.0)"));

 if (jl_is_float64(ret)) {
   double ret_unboxed = jl_unbox_float64(ret);
   printf("sqrt(2.0) in C: %e \n", ret_unboxed);
 }


// Call sigmoid from NumericFuns module

jl_value_t* sig =  (jl_value_t*)
(jl_eval_string("NumericFuns.sigmoid(0.0)"));


if(jl_is_float64(sig)){
  double unsig = jl_unbox_float64(sig);
}


Any suggesions?

Thanks,
Einar



On Fri, Sep 5, 2014 at 7:23 PM, Tobias Knopp 
wrote:

> Yes, Jakes suggestion looks good. When I wrote the embedding doku I also
> played around with several internal functions and it turned out that
> jl_eval_string is very versatile and can be used in various circumstances.
>
> Einar: Would be great if you could test it and improve the embedding
> documentation (on the github page) with an example how to get arbitrary
> module pointer.
>
> Thanks
>
> Tobi
>
> Am Freitag, 5. September 2014 17:46:33 UTC+2 schrieb Jake Bolewski:
>
>> It's jl_eval_string located in jl_api.c in src.
>>
>> so you would do
>> jl_value_t * func2 = jl_eval_string("DSP.hanning")
>>
>> The best way to play around with Julia's c-api is within julia itself.
>> julia> pkg_ptr = ccall(:jl_eval_string, Ptr{Void}, (Ptr{Cchar},),
>> "Base.Pkg.clone")
>> Ptr{Void} @0x7fd11c1754a0
>>
>> julia> unsafe_pointer_to_objref(ans)
>> clone (generic function with 2 methods)
>>
>> julia> typeof(ans)
>> Function
>>
>> That way you can prototype what you want much more easily.
>>
>> On Friday, September 5, 2014 9:32:43 AM UTC-4, Einar Otnes wrote:
>>>
>>> Thank you for your help on this. It seems that the 'jl_eval_global_var'
>>> function is local as I got the error "undefined reference to
>>> `jl_eval_global_var'" when linking. I replaced
>>> your suggestion with:
>>>
>>> jl_module_t* jl_dsp_module = (jl_module_t*)
>>> jl_get_binding(jl_main_module, jl_symbol("DSP"));
>>> jl_function_t* func2 = jl_get_function(jl_dsp_module,"hanning");
>>>
>>> This compiles OK, but I get a "segfault  (core dumped)" when running the
>>> line with 'jl_get_function' .
>>>
>>> Any ideas or thoughts?
>>>
>>> Thanks,
>>>
>>> Einar
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Fri, Sep 5, 2014 at 11:15 AM, Ivar Nesje  wrote:
>>>
 I would guess that something like

 module = jl_eval_global_var
 
 (jl_main_module, jl_sym
 
 ("MyModule"))

 would work, but I don't have the required testing setup to see if it
 actually works. (Where is my C REPL?) The embedding API has not gotten much
 attention (yet), so it is mostly documented in source, and it is likely
 that there will be some adjustments.


 On Friday, September 5, 2014 10:09:03 AM UTC+2, Einar Otnes wrote:
>
> Sorry, I'm a bit slow. How do I look up a binding for a specific
> module? In other words, how would I explicitly get to call the "fftfreq"
> function in the "DSP" module from C/C++?
>
> Is this this documented anywhere in Julia docs?
>
> Thanks,
> Einar
>
>
>
> On Wednesday, September 3, 2014 3:10:59 PM UTC+2, Isaiah wrote:
>>
>> If you have defined a module already (by eval'ing julia code?) then
>> you can look up the binding and cast that to a jl_module_t.
>> On Sep 3, 2014 8:14 AM, "Einar Otnes"  wrote:
>>
>>> Dear experts,
>>>
>>> I've looking at the documentation " Embedding Julia" (
>>> http://julia.readthedocs.org/en/latest/manual/embedding/) to figure
>>> out how I can call my own julia functions from within C, and I'm 
>>> struggling
>>> to figure out how I should define the jl_module_t that corresponds the
>>> module I've defined. The examples show that there is an instance of
>>> jl_module_t,  "jl_base_module",  that you need to provide to be able to
>>> call a function defined in the base module. How do I define a 
>>> corresponding
>>> jl_module_t type for the modules that are defined outside of standard
>>> julia, e.g. for the external packages or the modules I have created 
>>> myself?
>>>
>>> Thanks for your help.
>>>
>>> Best regards,
>>>
>>> Einar Otnes
>>>
>>>
>>>


Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Patrick O'Leary
On Tuesday, September 9, 2014 8:02:44 AM UTC-5, Tim Holy wrote:
>
> In Matlab, until quite recently X.^2 was slower than X.*X. It was that way 
> for 
> something like 25 years before they fixed it. 
>

And a couple more years before it was fixed in Coder. And an expensive, 
very branchy set of guards was generated to wrap every invocation of pow(). 
We once had to change a whole bunch of these to X.*X to get a simulation 
down to realtime... 

Patrick


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

2014-09-09 Thread Patrick O'Leary
On Tuesday, September 9, 2014 2:02:03 AM UTC-5, gentlebeldin wrote:
>
> Not true, & is an undocumented singular case (regrettably). - is a unary 
> operator, too, but nonetheless, -(1,5) gives -4, as it well should.
>

Did you look at the link Jake posted? The `-` operator is not in the class 
`syntactic_unary_operator`, but listed in `unary_ops`, which by implication 
doesn't have the special handling:

https://github.com/jakebolewski/JuliaParser.jl/blob/aa466d7a84dee73db9cec66dbe631c1e534ebcc0/src/lexer.jl#L89

The problem is that `&`, `$`, and `::` are not just operators, but syntax 
(for instance, `&` in `ccall()`, and `$` in expression interpolation), so 
they require special parser handling, and this can conflict with the normal 
rules for parsing unary operators.


Re: [julia-users] Calling julia functions from Python

2014-09-09 Thread Isaiah Norton
It would be great if you can edit the readme and add some examples and
other information you find, and submit as a pull request. The pyjulia
package has not been used by many people so far, so any chance
contributions will help.
On Sep 9, 2014 8:25 AM, "Uwe Fechner"  wrote:

> Ok, by reading the source code of pyjulia I found the answer myself:
>
> j.call is for calling julia functions only, not for getting results back.
>
> If you need the result, use j.eval:
>
> In [6]: j.eval("2+2")
> Out[6]: 4
>
> I think the main problem is, that pyjulia has no documentation yet.
> I might open a pyjulia issue for this.
>
> Regards:
>
> Uwe
>
>
> On Tuesday, September 9, 2014 2:18:49 PM UTC+2, Uwe Fechner wrote:
>>
>> Ok, no exeption any more if I use j.call instead of j.run.
>>
>> But the result is wrong:
>>
>> import julia
>> j=julia.Julia()
>> In [3]: j.call("2+2")
>> Out[3]: 49655584
>>
>> Any idea?
>>
>> Uwe
>>
>>
>> On Tuesday, September 9, 2014 1:49:55 PM UTC+2, Isaiah wrote:
>>>
>>> I think you need `julia.call` instead of `julia.run`.
>>>
>>> On Tue, Sep 9, 2014 at 7:16 AM, Uwe Fechner 
>>> wrote:
>>>
 Hello,

 I have a function, that is running much faster in Julia then in Python.

 Now I want to call it from my (large) Python program.

 I tried to do this, using pyjulia from
 https://github.com/JuliaLang/pyjulia .

 I am using Ubuntu 12.04, 64 bits and Julia 0.3 and tried to install
 pyjulia in the following way:

 cd ~
 mkdir 00Software
 cd 00Software
 git clone https://github.com/JuliaLang/pyjulia.git
 cd pyjulia
 sudo python setup.py install

 Then I started ipython and tried the following code:

 import julia
 j=julia.Julia()
 j.run("2+2")

 I get the following error message:

 In [3]: j.run("2+2")
 
 ---
 RuntimeError  Traceback (most recent call
 last)
  in ()
 > 1 j.run("2+2")

 RuntimeError: Julia exception: MethodError(run,("2+2",))

 In [4]:

 Any idea what is going wrong?

 Best regards:

 Uwe Fechner

>>>
>>>


Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Tim Holy
Is it really better to introduce VML as a temporary hack than it is to fix 
LLVM, even if the latter takes a little longer?

In Matlab, until quite recently X.^2 was slower than X.*X. It was that way for 
something like 25 years before they fixed it.

--Tim

On Monday, September 08, 2014 10:50:53 PM Jeff Waller wrote:
> I feel that x^2 must among the things that are convenient and fast; it's
> one of those language elements that people simply depend on.  If it's
> inconvenient, then people are going to experience that over and over.  If
> it's not fast enough people are going experience slowness over and over.
> 
> Like Simon says it's already a thing
> .  Maybe use of something
> like VML is an option or necessary, or maybe extending inference.jl or
> maybe even it eventually might not be necessary
> .
> 
> Julia is a fundamental improvement, but give Matlab and Octave their due,
> that syntax is great.  When I say essentially C, to me it means
> 
> Option A use built in infix:
> 
> X.^y
> 
> versus Option B go write a function
> 
> pow(x,y)
>for i = 1 ...
>   for j = 
>...
>etc
> 
> Option A is just too good, it has to be supported.
> 
> What to do?  Is this a fundamental flaw?  No I don't think so.  Is this a
> one time only thing?  It feels like no, this is one of many things that
> will occasionally occur.  Is it possible to make this a hassle?  Like I
> think Tony is saying, can/should there be a "branch of immediate
> optimizations?"  Stuff that would eventually be done in a better way but
> needs to be completed now.  It's a branch so things can be collected and
> retracted more coherently.



Re: [julia-users] Re: ANN: revamped Images based on Color, FixedPointNumbers

2014-09-09 Thread Stefan Karpinski
Yes, but now I'm wrestling with Tk. Should have gotten this working way
earlier.


On Tue, Sep 9, 2014 at 2:39 PM, Tim Holy  wrote:

> Is it fixed now?
> --Tim
>
> On Tuesday, September 09, 2014 02:18:34 PM Stefan Karpinski wrote:
> > Ah, I was getting the same thing in the REPL, but that was because of
> > TerminalExtensions, which uses the same display API, which seems to be
> > broken.
> >
> > On Tue, Sep 9, 2014 at 2:11 PM, Tim Holy  wrote:
> > > Missing method problem; I'm afraid that in these early days, there are
> > > simply
> > > going to be some of these, because this is a huge expansion of the type
> > > hierarchy and I'm sure I didn't catch everything that everyone will
> try.
> > > (I
> > > rarely use IJulia in part because I have a weird display bug that
> seems to
> > > affect only me---individual pixels are displayed as tiles with spaces
> > > between
> > > them---and I haven't yet succeeded in tracking it down.)
> > >
> > > Should be fixed if you do Pkg.update(). I can't promise that whatever
> > > larger-
> > > scale thing you were trying will work, however, unless you give me a
> more
> > > complete example.
> > >
> > > Best,
> > > --Tim
> > >
> > > On Tuesday, September 09, 2014 12:27:35 PM Stefan Karpinski wrote:
> > > > I'm seeing this error:
> > > >
> > > > `mapinfo` has no method matching
> > >
> > > mapinfo(::Type{RGB{UfixedBase{Uint8,8}}},
> > >
> > > >
> ::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
> > > >
> > > >  in base64 at base64.jl:125
> > > >  in display_dict at
> > > >  /Users/stefan/.julia/IJulia/src/execute_request.jl:34
> > > >
> > > > What versions of things are required to make this work? I wonder it
> this
> > >
> > > is
> > >
> > > > something obviously wrong. My system info:
> > > >
> > > > Julia Version 0.3.1-pre+48
> > > > Commit 8c1b105 (2014-09-08 12:46 UTC)
> > > >
> > > > Platform Info:
> > > >   System: Darwin (x86_64-apple-darwin13.3.0)
> > > >   CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
> > > >   WORD_SIZE: 64
> > > >   BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY
> Sandybridge)
> > > >   LAPACK: libopenblas
> > > >   LIBM: libopenlibm
> > > >   LLVM: libLLVM-3.3
> > > >
> > > > 30 required packages:
> > > >  - ASCIIPlots0.0.2
> > > >  - DataArrays0.2.0
> > > >  - DataFrames0.5.7
> > > >  - DataStructures0.3.2
> > > >  - Debug 0.0.4
> > > >  - Distributions 0.5.4
> > > >  - Example   0.3.3+ master
> > > >  - Gadfly0.3.7
> > > >  - Gaston0.0.0  master
> > > >  - IJulia0.1.15
> > > >  - Images0.4.2
> > > >  - ImmutableArrays   0.0.6
> > > >  - Iterators 0.1.6
> > > >  - JSON  0.3.7
> > > >  - Morsel0.0.4
> > > >  - NLopt 0.1.3  master
> > > >  - ODBC  0.3.8+ master
> > > >  - PyCall0.4.8
> > > >  - PyPlot1.3.3
> > > >  - RDatasets 0.1.1
> > > >  - RNGTest   0.0.1+ 421b289d
> > > >  - SIUnits   0.0.2
> > > >  - SortingAlgorithms 0.0.1
> > > >  - SpecialMatrices   0.1.3
> > > >  - Stats 0.1.0
> > > >  - TerminalExtensions0.0.2
> > > >  - TestImages0.0.5
> > > >  - TimeSeries0.4.5
> > > >  - Winston   0.11.4
> > > >  - ZMQ   0.1.13
> > > >
> > > > 38 additional packages:
> > > >  - ArrayViews0.4.6
> > > >  - BinDeps   0.3.5
> > > >  - Cairo 0.2.17
> > > >  - Cartesian 0.3.0
> > > >  - Codecs0.1.2
> > > >  - Color 0.3.7
> > > >  - Compose   0.3.7
> > > >  - Contour   0.0.4
> > > >  - Dates 0.3.1
> > > >  - Datetime  0.1.7
> > > >  - Distances 0.1.1
> > > >  - FixedPointNumbers 0.0.4
> > > >  - GZip  0.2.13
> > > >  - GnuTLS0.0.1
> > > >  - Hexagons  0.0.2
> > > >  - Homebrew  0.1.10
> > > >  - HttpCommon0.0.6
> > > >  - HttpParser0.0.9
> > > >  - HttpServer0.0.8
> > > >  - IniFile   0.2.3
> > > >  - KernelDensity 0.0.2
> > > >  - LibTrading0.0.1  master (dirty)
> > > >  - Loess 0.0.3
> > > >  - MathProgBase  0.3.0
> > > >  - Meddle0.0.5
> > > 

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

2014-09-09 Thread Randy Zwitch
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

Re: [julia-users] Re: ANN: revamped Images based on Color, FixedPointNumbers

2014-09-09 Thread Tim Holy
Is it fixed now?
--Tim

On Tuesday, September 09, 2014 02:18:34 PM Stefan Karpinski wrote:
> Ah, I was getting the same thing in the REPL, but that was because of
> TerminalExtensions, which uses the same display API, which seems to be
> broken.
> 
> On Tue, Sep 9, 2014 at 2:11 PM, Tim Holy  wrote:
> > Missing method problem; I'm afraid that in these early days, there are
> > simply
> > going to be some of these, because this is a huge expansion of the type
> > hierarchy and I'm sure I didn't catch everything that everyone will try.
> > (I
> > rarely use IJulia in part because I have a weird display bug that seems to
> > affect only me---individual pixels are displayed as tiles with spaces
> > between
> > them---and I haven't yet succeeded in tracking it down.)
> > 
> > Should be fixed if you do Pkg.update(). I can't promise that whatever
> > larger-
> > scale thing you were trying will work, however, unless you give me a more
> > complete example.
> > 
> > Best,
> > --Tim
> > 
> > On Tuesday, September 09, 2014 12:27:35 PM Stefan Karpinski wrote:
> > > I'm seeing this error:
> > > 
> > > `mapinfo` has no method matching
> > 
> > mapinfo(::Type{RGB{UfixedBase{Uint8,8}}},
> > 
> > > ::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
> > >  
> > >  in base64 at base64.jl:125
> > >  in display_dict at
> > >  /Users/stefan/.julia/IJulia/src/execute_request.jl:34
> > > 
> > > What versions of things are required to make this work? I wonder it this
> > 
> > is
> > 
> > > something obviously wrong. My system info:
> > > 
> > > Julia Version 0.3.1-pre+48
> > > Commit 8c1b105 (2014-09-08 12:46 UTC)
> > > 
> > > Platform Info:
> > >   System: Darwin (x86_64-apple-darwin13.3.0)
> > >   CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
> > >   WORD_SIZE: 64
> > >   BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
> > >   LAPACK: libopenblas
> > >   LIBM: libopenlibm
> > >   LLVM: libLLVM-3.3
> > > 
> > > 30 required packages:
> > >  - ASCIIPlots0.0.2
> > >  - DataArrays0.2.0
> > >  - DataFrames0.5.7
> > >  - DataStructures0.3.2
> > >  - Debug 0.0.4
> > >  - Distributions 0.5.4
> > >  - Example   0.3.3+ master
> > >  - Gadfly0.3.7
> > >  - Gaston0.0.0  master
> > >  - IJulia0.1.15
> > >  - Images0.4.2
> > >  - ImmutableArrays   0.0.6
> > >  - Iterators 0.1.6
> > >  - JSON  0.3.7
> > >  - Morsel0.0.4
> > >  - NLopt 0.1.3  master
> > >  - ODBC  0.3.8+ master
> > >  - PyCall0.4.8
> > >  - PyPlot1.3.3
> > >  - RDatasets 0.1.1
> > >  - RNGTest   0.0.1+ 421b289d
> > >  - SIUnits   0.0.2
> > >  - SortingAlgorithms 0.0.1
> > >  - SpecialMatrices   0.1.3
> > >  - Stats 0.1.0
> > >  - TerminalExtensions0.0.2
> > >  - TestImages0.0.5
> > >  - TimeSeries0.4.5
> > >  - Winston   0.11.4
> > >  - ZMQ   0.1.13
> > > 
> > > 38 additional packages:
> > >  - ArrayViews0.4.6
> > >  - BinDeps   0.3.5
> > >  - Cairo 0.2.17
> > >  - Cartesian 0.3.0
> > >  - Codecs0.1.2
> > >  - Color 0.3.7
> > >  - Compose   0.3.7
> > >  - Contour   0.0.4
> > >  - Dates 0.3.1
> > >  - Datetime  0.1.7
> > >  - Distances 0.1.1
> > >  - FixedPointNumbers 0.0.4
> > >  - GZip  0.2.13
> > >  - GnuTLS0.0.1
> > >  - Hexagons  0.0.2
> > >  - Homebrew  0.1.10
> > >  - HttpCommon0.0.6
> > >  - HttpParser0.0.9
> > >  - HttpServer0.0.8
> > >  - IniFile   0.2.3
> > >  - KernelDensity 0.0.2
> > >  - LibTrading0.0.1  master (dirty)
> > >  - Loess 0.0.3
> > >  - MathProgBase  0.3.0
> > >  - Meddle0.0.5
> > >  - NAG   0.0.0- master
> > >  (unregistered)
> > >  - Nettle0.1.5
> > >  - PDMats0.2.4
> > >  - REPLCompletions   0.0.3
> > >  - Reexport  0.0.1
> > >  - SHA   0.0.3
> > >  - Sparklines0.1.0  

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

2014-09-09 Thread Jacob Quinn
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 functions with your own functions with an 
 alternative signature, and then convert from ASCIIString to Ptr{Uint8}. 
 Note that you probably will need to do it anyways to wrap the return 
 types, 
 since you probably do not want to work with pointers from Julia :)

 In that specific example,

Re: [julia-users] Calling julia functions from Python

2014-09-09 Thread Uwe Fechner
Ok, by reading the source code of pyjulia I found the answer myself:

j.call is for calling julia functions only, not for getting results back.

If you need the result, use j.eval:

In [6]: j.eval("2+2")
Out[6]: 4

I think the main problem is, that pyjulia has no documentation yet. 
I might open a pyjulia issue for this.

Regards:

Uwe


On Tuesday, September 9, 2014 2:18:49 PM UTC+2, Uwe Fechner wrote:
>
> Ok, no exeption any more if I use j.call instead of j.run.
>
> But the result is wrong:
>
> import julia
> j=julia.Julia()
> In [3]: j.call("2+2")
> Out[3]: 49655584
>
> Any idea?
>
> Uwe
>
>
> On Tuesday, September 9, 2014 1:49:55 PM UTC+2, Isaiah wrote:
>>
>> I think you need `julia.call` instead of `julia.run`.
>>
>> On Tue, Sep 9, 2014 at 7:16 AM, Uwe Fechner  wrote:
>>
>>> Hello,
>>>
>>> I have a function, that is running much faster in Julia then in Python.
>>>
>>> Now I want to call it from my (large) Python program.
>>>
>>> I tried to do this, using pyjulia from 
>>> https://github.com/JuliaLang/pyjulia .
>>>
>>> I am using Ubuntu 12.04, 64 bits and Julia 0.3 and tried to install 
>>> pyjulia in the following way:
>>>
>>> cd ~
>>> mkdir 00Software
>>> cd 00Software
>>> git clone https://github.com/JuliaLang/pyjulia.git
>>> cd pyjulia
>>> sudo python setup.py install
>>>
>>> Then I started ipython and tried the following code:
>>>
>>> import julia
>>> j=julia.Julia()
>>> j.run("2+2")
>>>
>>> I get the following error message:
>>>
>>> In [3]: j.run("2+2")
>>>
>>> ---
>>> RuntimeError  Traceback (most recent call 
>>> last)
>>>  in ()
>>> > 1 j.run("2+2")
>>>
>>> RuntimeError: Julia exception: MethodError(run,("2+2",))
>>>
>>> In [4]: 
>>>
>>> Any idea what is going wrong?
>>>
>>> Best regards:
>>>
>>> Uwe Fechner
>>>
>>
>>

Re: [julia-users] Re: ANN: revamped Images based on Color, FixedPointNumbers

2014-09-09 Thread Stefan Karpinski
Ah, I was getting the same thing in the REPL, but that was because of
TerminalExtensions, which uses the same display API, which seems to be
broken.


On Tue, Sep 9, 2014 at 2:11 PM, Tim Holy  wrote:

> Missing method problem; I'm afraid that in these early days, there are
> simply
> going to be some of these, because this is a huge expansion of the type
> hierarchy and I'm sure I didn't catch everything that everyone will try. (I
> rarely use IJulia in part because I have a weird display bug that seems to
> affect only me---individual pixels are displayed as tiles with spaces
> between
> them---and I haven't yet succeeded in tracking it down.)
>
> Should be fixed if you do Pkg.update(). I can't promise that whatever
> larger-
> scale thing you were trying will work, however, unless you give me a more
> complete example.
>
> Best,
> --Tim
>
> On Tuesday, September 09, 2014 12:27:35 PM Stefan Karpinski wrote:
> > I'm seeing this error:
> >
> > `mapinfo` has no method matching
> mapinfo(::Type{RGB{UfixedBase{Uint8,8}}},
> >
> > ::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
> >
> >  in base64 at base64.jl:125
> >  in display_dict at /Users/stefan/.julia/IJulia/src/execute_request.jl:34
> >
> > What versions of things are required to make this work? I wonder it this
> is
> > something obviously wrong. My system info:
> >
> > Julia Version 0.3.1-pre+48
> > Commit 8c1b105 (2014-09-08 12:46 UTC)
> > Platform Info:
> >   System: Darwin (x86_64-apple-darwin13.3.0)
> >   CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
> >   WORD_SIZE: 64
> >   BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
> >   LAPACK: libopenblas
> >   LIBM: libopenlibm
> >   LLVM: libLLVM-3.3
> >
> > 30 required packages:
> >  - ASCIIPlots0.0.2
> >  - DataArrays0.2.0
> >  - DataFrames0.5.7
> >  - DataStructures0.3.2
> >  - Debug 0.0.4
> >  - Distributions 0.5.4
> >  - Example   0.3.3+ master
> >  - Gadfly0.3.7
> >  - Gaston0.0.0  master
> >  - IJulia0.1.15
> >  - Images0.4.2
> >  - ImmutableArrays   0.0.6
> >  - Iterators 0.1.6
> >  - JSON  0.3.7
> >  - Morsel0.0.4
> >  - NLopt 0.1.3  master
> >  - ODBC  0.3.8+ master
> >  - PyCall0.4.8
> >  - PyPlot1.3.3
> >  - RDatasets 0.1.1
> >  - RNGTest   0.0.1+ 421b289d
> >  - SIUnits   0.0.2
> >  - SortingAlgorithms 0.0.1
> >  - SpecialMatrices   0.1.3
> >  - Stats 0.1.0
> >  - TerminalExtensions0.0.2
> >  - TestImages0.0.5
> >  - TimeSeries0.4.5
> >  - Winston   0.11.4
> >  - ZMQ   0.1.13
> > 38 additional packages:
> >  - ArrayViews0.4.6
> >  - BinDeps   0.3.5
> >  - Cairo 0.2.17
> >  - Cartesian 0.3.0
> >  - Codecs0.1.2
> >  - Color 0.3.7
> >  - Compose   0.3.7
> >  - Contour   0.0.4
> >  - Dates 0.3.1
> >  - Datetime  0.1.7
> >  - Distances 0.1.1
> >  - FixedPointNumbers 0.0.4
> >  - GZip  0.2.13
> >  - GnuTLS0.0.1
> >  - Hexagons  0.0.2
> >  - Homebrew  0.1.10
> >  - HttpCommon0.0.6
> >  - HttpParser0.0.9
> >  - HttpServer0.0.8
> >  - IniFile   0.2.3
> >  - KernelDensity 0.0.2
> >  - LibTrading0.0.1  master (dirty)
> >  - Loess 0.0.3
> >  - MathProgBase  0.3.0
> >  - Meddle0.0.5
> >  - NAG   0.0.0- master (unregistered)
> >  - Nettle0.1.5
> >  - PDMats0.2.4
> >  - REPLCompletions   0.0.3
> >  - Reexport  0.0.1
> >  - SHA   0.0.3
> >  - Sparklines0.1.0  master
> >  - StatsBase 0.6.4
> >  - TexExtensions 0.0.1
> >  - Tk0.2.13
> >  - URIParser 0.0.2
> >  - ZipFile   0.2.2
> >  - Zlib  0.1.7
> >
> > On Sat, Sep 6, 2014 at 6:47 AM, Tim Holy  wrote:
> > > On Friday, September 05, 2014 03:37

Re: [julia-users] Calling julia functions from Python

2014-09-09 Thread Uwe Fechner
Ok, no exeption any more if I use j.call instead of j.run.

But the result is wrong:

import julia
j=julia.Julia()
In [3]: j.call("2+2")
Out[3]: 49655584

Any idea?

Uwe


On Tuesday, September 9, 2014 1:49:55 PM UTC+2, Isaiah wrote:
>
> I think you need `julia.call` instead of `julia.run`.
>
> On Tue, Sep 9, 2014 at 7:16 AM, Uwe Fechner  > wrote:
>
>> Hello,
>>
>> I have a function, that is running much faster in Julia then in Python.
>>
>> Now I want to call it from my (large) Python program.
>>
>> I tried to do this, using pyjulia from 
>> https://github.com/JuliaLang/pyjulia .
>>
>> I am using Ubuntu 12.04, 64 bits and Julia 0.3 and tried to install 
>> pyjulia in the following way:
>>
>> cd ~
>> mkdir 00Software
>> cd 00Software
>> git clone https://github.com/JuliaLang/pyjulia.git
>> cd pyjulia
>> sudo python setup.py install
>>
>> Then I started ipython and tried the following code:
>>
>> import julia
>> j=julia.Julia()
>> j.run("2+2")
>>
>> I get the following error message:
>>
>> In [3]: j.run("2+2")
>>
>> ---
>> RuntimeError  Traceback (most recent call 
>> last)
>>  in ()
>> > 1 j.run("2+2")
>>
>> RuntimeError: Julia exception: MethodError(run,("2+2",))
>>
>> In [4]: 
>>
>> Any idea what is going wrong?
>>
>> Best regards:
>>
>> Uwe Fechner
>>
>
>

Re: [julia-users] Re: ANN: revamped Images based on Color, FixedPointNumbers

2014-09-09 Thread Tim Holy
Missing method problem; I'm afraid that in these early days, there are simply 
going to be some of these, because this is a huge expansion of the type 
hierarchy and I'm sure I didn't catch everything that everyone will try. (I 
rarely use IJulia in part because I have a weird display bug that seems to 
affect only me---individual pixels are displayed as tiles with spaces between 
them---and I haven't yet succeeded in tracking it down.)

Should be fixed if you do Pkg.update(). I can't promise that whatever larger-
scale thing you were trying will work, however, unless you give me a more 
complete example.

Best,
--Tim

On Tuesday, September 09, 2014 12:27:35 PM Stefan Karpinski wrote:
> I'm seeing this error:
> 
> `mapinfo` has no method matching mapinfo(::Type{RGB{UfixedBase{Uint8,8}}},
> 
> ::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
> 
>  in base64 at base64.jl:125
>  in display_dict at /Users/stefan/.julia/IJulia/src/execute_request.jl:34
> 
> What versions of things are required to make this work? I wonder it this is
> something obviously wrong. My system info:
> 
> Julia Version 0.3.1-pre+48
> Commit 8c1b105 (2014-09-08 12:46 UTC)
> Platform Info:
>   System: Darwin (x86_64-apple-darwin13.3.0)
>   CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
>   WORD_SIZE: 64
>   BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
>   LAPACK: libopenblas
>   LIBM: libopenlibm
>   LLVM: libLLVM-3.3
> 
> 30 required packages:
>  - ASCIIPlots0.0.2
>  - DataArrays0.2.0
>  - DataFrames0.5.7
>  - DataStructures0.3.2
>  - Debug 0.0.4
>  - Distributions 0.5.4
>  - Example   0.3.3+ master
>  - Gadfly0.3.7
>  - Gaston0.0.0  master
>  - IJulia0.1.15
>  - Images0.4.2
>  - ImmutableArrays   0.0.6
>  - Iterators 0.1.6
>  - JSON  0.3.7
>  - Morsel0.0.4
>  - NLopt 0.1.3  master
>  - ODBC  0.3.8+ master
>  - PyCall0.4.8
>  - PyPlot1.3.3
>  - RDatasets 0.1.1
>  - RNGTest   0.0.1+ 421b289d
>  - SIUnits   0.0.2
>  - SortingAlgorithms 0.0.1
>  - SpecialMatrices   0.1.3
>  - Stats 0.1.0
>  - TerminalExtensions0.0.2
>  - TestImages0.0.5
>  - TimeSeries0.4.5
>  - Winston   0.11.4
>  - ZMQ   0.1.13
> 38 additional packages:
>  - ArrayViews0.4.6
>  - BinDeps   0.3.5
>  - Cairo 0.2.17
>  - Cartesian 0.3.0
>  - Codecs0.1.2
>  - Color 0.3.7
>  - Compose   0.3.7
>  - Contour   0.0.4
>  - Dates 0.3.1
>  - Datetime  0.1.7
>  - Distances 0.1.1
>  - FixedPointNumbers 0.0.4
>  - GZip  0.2.13
>  - GnuTLS0.0.1
>  - Hexagons  0.0.2
>  - Homebrew  0.1.10
>  - HttpCommon0.0.6
>  - HttpParser0.0.9
>  - HttpServer0.0.8
>  - IniFile   0.2.3
>  - KernelDensity 0.0.2
>  - LibTrading0.0.1  master (dirty)
>  - Loess 0.0.3
>  - MathProgBase  0.3.0
>  - Meddle0.0.5
>  - NAG   0.0.0- master (unregistered)
>  - Nettle0.1.5
>  - PDMats0.2.4
>  - REPLCompletions   0.0.3
>  - Reexport  0.0.1
>  - SHA   0.0.3
>  - Sparklines0.1.0  master
>  - StatsBase 0.6.4
>  - TexExtensions 0.0.1
>  - Tk0.2.13
>  - URIParser 0.0.2
>  - ZipFile   0.2.2
>  - Zlib  0.1.7
> 
> On Sat, Sep 6, 2014 at 6:47 AM, Tim Holy  wrote:
> > On Friday, September 05, 2014 03:37:10 PM Job van der Zwan wrote:
> > > This sounds like Julia magic that will greatly simplify a *lot* of code.
> > 
> > I'm hopeful of that too, and I think there's already some preliminary
> > evidence
> > for that within Images itself. Hopefully more will come as people start to
> > use
> > it.
> > 
> > One thing I should clarify is that, while Images has long striven for a
> > separation between _meaning_ and _r

Re: [julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Andreas Noack
The problem is that right now X[:,1001,end] makes a copy of the array.
However,  in 0.4 this will instead be a view of the original matrix and
therefore the computing time should be almost the same.

It might also be worth repeating Simon's comment that the floating point
power function has special handling of 2. The result is that

julia> @time A.^2;
elapsed time: 1.402791357 seconds (20256 bytes allocated, 5.90% gc time)

julia> @time A.^2.0;
elapsed time: 0.554241105 seconds (20256 bytes allocated, 15.04% gc
time)

I tend to agree with Simon that special casing of integer 2 would be
reasonable.

Med venlig hilsen

Andreas Noack

2014-09-09 4:24 GMT-04:00 Ján Dolinský :

> Hello guys,
>
> Thanks a lot for the lengthy discussions. It helped me a lot to get a
> feeling on what is Julia like. I did some more performance comparisons as
> suggested by first two posts (thanks a lot for the tips). In the mean time
> I upgraded to v0.3.
> X = rand(7000,7000);
> @time d = sum(X.^2, 1);
> elapsed time: 0.573125833 seconds (392056672 bytes allocated, 2.25% gc
> time)
> @time d = sum(X.*X, 1);
> elapsed time: 0.178715901 seconds (392057080 bytes allocated, 14.06% gc
> time)
> @time d = sumabs2(X, 1);
> elapsed time: 0.067431808 seconds (56496 bytes allocated)
>
> In Octave then
> X = rand(7000);
> tic; d = sum(X.^2); toc;
> Elapsed time is 0.167578 seconds.
>
> So the ultimate solution is the sumabs2 function which is a blast. I am
> comming from Matlab/Octave and I would expect X.^2 to be fast "out of the
> box" but nevertheless if I can get an excellent performance by learning
> some new paradigms I will go for it.
>
> The above tests lead me to another question. I often need to calculate the
> "self" dot product over a portion of a matrix, e.g.
> @time d = sumabs2(X[:,1001:end], 1);
> elapsed time: 0.17566 seconds (336048688 bytes allocated, 7.01% gc
> time)
>
> Apparently this is not a way to do it in Julia because working on a
> smaller matrix of 7000x6000 gives more than double computing time and
> furthermore it seems to allocate unnecessary memory.
>
> Best Regards,
> Jan
>
>
>
> Dňa pondelok, 8. septembra 2014 10:36:02 UTC+2 Ján Dolinský napísal(-a):
>
>> Hello,
>>
>> I am a new Julia user. I am trying to write a function for computing
>> "self" dot product of all columns in a matrix, i.e. calculating a square of
>> each element of a matrix and computing a column-wise sum. I am interested
>> in a proper way of doing it because I often need to process large matrices.
>>
>> I first put a focus on calculating the squares. For testing purposes I
>> use a matrix of random floats of size 7000x7000. All timings here are
>> deducted after several repetitive runs.
>>
>> I used to do it in Octave (v3.8.1) a follows:
>> tic; X = rand(7000); toc;
>> Elapsed time is 0.579093 seconds.
>> tic; XX = X.^2; toc;
>> Elapsed time is 0.114737 seconds.
>>
>>
>> I tried to to the same in Julia (v0.2.1):
>> @time X = rand(7000,7000);
>> elapsed time: 0.114418731 seconds (392000128 bytes allocated)
>> @time XX = X.^2;
>> elapsed time: 0.369641268 seconds (392000224 bytes allocated)
>>
>> I was surprised to see that Julia is about 3 times slower when
>> calculating a square than my original routine in Octave. I then read
>> "Performance tips" and found out that one should use * instead of of
>> raising to small integer powers, for example x*x*x instead of x^3. I
>> therefore tested the following.
>> @time XX = X.*X;
>> elapsed time: 0.146059577 seconds (392000968 bytes allocated)
>>
>> This approach indeed resulted in a lot shorter computing time. It is
>> still however a little slower than my code in Octave. Can someone advise on
>> any performance tips ?
>>
>> I then finally do a sum over all columns of XX to get the "self" dot
>> product but first I'd like to fix the squaring part.
>>
>> Thanks a lot.
>> Best Regards,
>> Jan
>>
>> p.s. In Julia manual I found a while ago an example of using @vectorize
>> macro with a squaring function but can not find it any more. Perhaps the
>> name of macro was different ...
>>
>>
>


Re: [julia-users] Calling julia functions from Python

2014-09-09 Thread Isaiah Norton
I think you need `julia.call` instead of `julia.run`.

On Tue, Sep 9, 2014 at 7:16 AM, Uwe Fechner 
wrote:

> Hello,
>
> I have a function, that is running much faster in Julia then in Python.
>
> Now I want to call it from my (large) Python program.
>
> I tried to do this, using pyjulia from
> https://github.com/JuliaLang/pyjulia .
>
> I am using Ubuntu 12.04, 64 bits and Julia 0.3 and tried to install
> pyjulia in the following way:
>
> cd ~
> mkdir 00Software
> cd 00Software
> git clone https://github.com/JuliaLang/pyjulia.git
> cd pyjulia
> sudo python setup.py install
>
> Then I started ipython and tried the following code:
>
> import julia
> j=julia.Julia()
> j.run("2+2")
>
> I get the following error message:
>
> In [3]: j.run("2+2")
> ---
> RuntimeError  Traceback (most recent call last)
>  in ()
> > 1 j.run("2+2")
>
> RuntimeError: Julia exception: MethodError(run,("2+2",))
>
> In [4]:
>
> Any idea what is going wrong?
>
> Best regards:
>
> Uwe Fechner
>


[julia-users] Calling julia functions from Python

2014-09-09 Thread Uwe Fechner
Hello,

I have a function, that is running much faster in Julia then in Python.

Now I want to call it from my (large) Python program.

I tried to do this, using pyjulia from 
https://github.com/JuliaLang/pyjulia .

I am using Ubuntu 12.04, 64 bits and Julia 0.3 and tried to install pyjulia 
in the following way:

cd ~
mkdir 00Software
cd 00Software
git clone https://github.com/JuliaLang/pyjulia.git
cd pyjulia
sudo python setup.py install

Then I started ipython and tried the following code:

import julia
j=julia.Julia()
j.run("2+2")

I get the following error message:

In [3]: j.run("2+2")
---
RuntimeError  Traceback (most recent call last)
 in ()
> 1 j.run("2+2")

RuntimeError: Julia exception: MethodError(run,("2+2",))

In [4]: 

Any idea what is going wrong?

Best regards:

Uwe Fechner


Re: [julia-users] Does Julia have something similar to Python's documentation string?

2014-09-09 Thread Magnus Lie Hetland
I have some level of eye-bleed from this and several other suggestions, 
too. The look of comments is part of the language design, and they are 
(IMO) unobtrusive yet visually indistinct -- and (for the single-line ones, 
at least) highly unsurprising and conventional. All of which I think is 
good. I'd *very much* prefer a solution that simply used the last comment 
before a method as the documentation for it, and having the convention of 
using Markdown in them, as Stefan argues.

There's talk about using Julia instead of some other language for more 
complex comment stuff. I guess that depend on what you want to use them for 
(or if you really want general metadata, rather than documentation). For 
marking up documentation text, I think a markup language is a good choice. 
For documentation comments, I think comments are a good choice ;-)

However, if one wants more programmability, would it be possible to treat 
comments as a special form of string literals in themselves (like 
docstrings), using the existing syntax? I'm assuming they'd just be 
eliminated from the compiled code, but would be available in the AST. Then 
one could use the existing Julia syntax for substituting values into the 
documentation, like:

# This is a comment. 1 + 2 = $(1 + 2)

I'm not sure I'd have any use for the extra programmability, and it doesn't 
mean that the comment/string could end up as anything other than a string. 
(There are, I guess, lots of suggestions for handling the latter issue 
already.)

But, yeah, I wholeheartedly agree with Stefan in that we "don't need 
flexible documentation – we need one simple documentation system that 
works."


Re: [julia-users] Re: ANN: revamped Images based on Color, FixedPointNumbers

2014-09-09 Thread Stefan Karpinski
I'm seeing this error:

`mapinfo` has no method matching mapinfo(::Type{RGB{UfixedBase{Uint8,8}}},
::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
 in base64 at base64.jl:125
 in display_dict at /Users/stefan/.julia/IJulia/src/execute_request.jl:34

What versions of things are required to make this work? I wonder it this is
something obviously wrong. My system info:

Julia Version 0.3.1-pre+48
Commit 8c1b105 (2014-09-08 12:46 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.3.0)
  CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

30 required packages:
 - ASCIIPlots0.0.2
 - DataArrays0.2.0
 - DataFrames0.5.7
 - DataStructures0.3.2
 - Debug 0.0.4
 - Distributions 0.5.4
 - Example   0.3.3+ master
 - Gadfly0.3.7
 - Gaston0.0.0  master
 - IJulia0.1.15
 - Images0.4.2
 - ImmutableArrays   0.0.6
 - Iterators 0.1.6
 - JSON  0.3.7
 - Morsel0.0.4
 - NLopt 0.1.3  master
 - ODBC  0.3.8+ master
 - PyCall0.4.8
 - PyPlot1.3.3
 - RDatasets 0.1.1
 - RNGTest   0.0.1+ 421b289d
 - SIUnits   0.0.2
 - SortingAlgorithms 0.0.1
 - SpecialMatrices   0.1.3
 - Stats 0.1.0
 - TerminalExtensions0.0.2
 - TestImages0.0.5
 - TimeSeries0.4.5
 - Winston   0.11.4
 - ZMQ   0.1.13
38 additional packages:
 - ArrayViews0.4.6
 - BinDeps   0.3.5
 - Cairo 0.2.17
 - Cartesian 0.3.0
 - Codecs0.1.2
 - Color 0.3.7
 - Compose   0.3.7
 - Contour   0.0.4
 - Dates 0.3.1
 - Datetime  0.1.7
 - Distances 0.1.1
 - FixedPointNumbers 0.0.4
 - GZip  0.2.13
 - GnuTLS0.0.1
 - Hexagons  0.0.2
 - Homebrew  0.1.10
 - HttpCommon0.0.6
 - HttpParser0.0.9
 - HttpServer0.0.8
 - IniFile   0.2.3
 - KernelDensity 0.0.2
 - LibTrading0.0.1  master (dirty)
 - Loess 0.0.3
 - MathProgBase  0.3.0
 - Meddle0.0.5
 - NAG   0.0.0- master (unregistered)
 - Nettle0.1.5
 - PDMats0.2.4
 - REPLCompletions   0.0.3
 - Reexport  0.0.1
 - SHA   0.0.3
 - Sparklines0.1.0  master
 - StatsBase 0.6.4
 - TexExtensions 0.0.1
 - Tk0.2.13
 - URIParser 0.0.2
 - ZipFile   0.2.2
 - Zlib  0.1.7


On Sat, Sep 6, 2014 at 6:47 AM, Tim Holy  wrote:

> On Friday, September 05, 2014 03:37:10 PM Job van der Zwan wrote:
> > This sounds like Julia magic that will greatly simplify a *lot* of code.
>
> I'm hopeful of that too, and I think there's already some preliminary
> evidence
> for that within Images itself. Hopefully more will come as people start to
> use
> it.
>
> One thing I should clarify is that, while Images has long striven for a
> separation between _meaning_ and _representation_, pretty much from
> inception
> I frankly struggled with how to achieve that goal for intensity. The key
> insight---that what we needed was a new number type---was a suggestion of
> Stefan Karpinski's
> (https://github.com/JuliaLang/Color.jl/issues/42#issuecomment-50103642).
> So
> while you won't see his fingerprints on the code, I suspect his elegant
> idea
> will have far-reaching impact.
>
> Best,
> --Tim
>
>


Re: [julia-users] Re: #JuliaLang anime character design spec.

2014-09-09 Thread Takeshi Kimura
Hi Karpinski-san:

I decided NOT to use elements of Julia logo for this character (only use 
color of three dots).
So, I have two questions for ask you:

Q1. I'd like to give you (=Karipinski-san) the right of "commercial-use" of 
this character.
   So anyone who wants to use this character in commercial-use must 
receive the grant from you (=Karpinski-san).

   The question is, "Could you receive the right of commercial-use of 
this character from me?"

Q2. If anyone who wants to use this character in non-commercial use,
   you(=anyone) use this character under the Creative Commons license 
of followings:


* Attribution-NonCommercial-ShareAlike  CC BY-NC-SA*

* http://creativecommons.org/licenses/by-nc-sa/4.0/ 
*

 The question is, "Can I settle to this CC BY-NC-SA license to 
non-commercial use of this character?"

So, this character will be under the dual-license.

Non-commercial use:
* You (=anyone) can use this character under the CC BY-NC-SA.*
Commercial use:
* You (=anyone) need to receive the grant from Karpinski-san.*

(The commercial-use contains use the character in Book's cover page or as 
figures of the Books.)

The character name is "Julia-tan" ("tan" is "san" like name postfix uses in 
Japanese).

Are these OK, Karpinski-san?

* Takeshi KIMURA*

 






2014年9月8日月曜日 5時28分27秒 UTC+9 Stefan Karpinski:
>
> You just have to ask for permission – technically the copyright is mine 
> since I made the logo. Using elements of it for something like this may 
> well be fair use, but if you ask, I'm likely to say yes as long as it's for 
> non-commercial use.
>
> On Sep 7, 2014, at 5:27 PM, Takeshi Kimura  > wrote:
>
> I misunderstand that Julia Logo and three dots logo graphic can be used 
> under the MIT core team's grant.
> So anime character is NOT derivative work of Julia logos.
>
> I think new Julia anime character is independent from Julia Logo, and 
> their license is:
>
> (quote from CC pages (license under the 
> http://creativecommons.org/licenses/by/4.0/)):
>
>
> *Attribution-NonCommercial-ShareAlike CC BY-NC-SA*
>
> This license lets others remix, tweak, and build upon your work 
> non-commercially,
>
> as long as they credit you and license their new creations under the 
> identical terms.
>
>
> may be the best choose for this character.
>
> The design specification deadline is September 10th in JST(+9:00).
>
>
>  Takeshi KIMURA
>
> 2014年9月3日水曜日 1時08分40秒 UTC+9 Takeshi Kimura:
>>
>> Hi there,
>>
>> I decided to establish #JuliaLang anime character project in Japan.
>> Now we are welcome your comments in this thread about this character 
>> spec. (costume, etc.) if you are interested in this project.
>> The design specification deadline is September 10th in JST(+9:00).
>>
>> For more details, see:
>>
>> http://mechawooser.blogspot.jp/2014/09/julialang-anime-character-project.html
>>
>> We realize that this character may be contain #JuliaLang logo or 
>> #JuliaLang 3-circle icons, and in this case,
>> our anime character may be satisfy CC's derivative work of #JuliaLang 
>> logo.
>>
>> I have two questions for julia-user:
>>
>> Q1. What type of costume or appearance do you prefer for this character? 
>> Is this better for holding Logo in her arms?
>>
>> Q2. Which type of CC License is suitable for this character itself?
>>
>> Comments are welcome!
>>
>> Best Regards,
>>
>>  Takeshi KIMURA
>>
>>
>>

Re: [julia-users] Interact + PyPlot: only update when releasing slider

2014-09-09 Thread Shashi Gowda
using Reactive, Interact
using PyPlot

f = figure();

α=slider(1:0.1:3)
β=slider(1:0.1:3)
γ=slider(1:0.1:3)
replot = button("Replot") # Commit your changes
map(display, [α, β, γ, replot]) # optional

coeffs = sampleon(replot, lift(tuple, α, β, γ))

@manipulate for x = coeffs; withfig(f) do
plot(fun(x...))
end
end

Sorry, in my rush to reply, I left behind some typos and bad thinking.
Tried this, it works.

On Tue, Sep 9, 2014 at 2:28 PM, Andrei Berceanu 
wrote:

> Thank you both for the suggestions! I am currently trying the "Replot"
> button approach, but ran into some errors, as follows:
>
> using Reactive, Interact
> using PyPlot
>
> fun(α, β, γ) = cos(α + sin(β+γ)) #example function
>
> f = figure();
>
> α=slider(1:0.1:3)
> β=slider(1:0.1:3)
> γ=slider(1:0.1:3)
> replot = button("Replot") # Commit your changes
> map(display, α, β, γ, replot) # optional
> -->  `start` has no method matching start(::Slider{Float64})
>
> sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
> -->  redo not defined
>
> withfig(f)
> @lift plot(apply(fun, sampled_coeffs))
> --> `withfig` has no method matching withfig(::Figure)
>
>
> On Monday, September 8, 2014 6:10:59 PM UTC+2, Shashi Gowda wrote:
>>
>> John's suggestion is also a good way to do this. You can sample the
>> signals at a specific interval instead of on button clicks:
>>
>> # At 2 fps, with repeats dropped.
>> sampled_coeffs = droprepeats(sampleon(fps(2), lift(tuple, α, β, γ)))
>>
>> On Mon, Sep 8, 2014 at 9:36 PM, Shashi Gowda  wrote:
>>
>>> Unfortunately, the @manipulate macro can only rerun the expression at
>>> every update of any of its input.
>>>
>>> What you need here is Reactive
>>> 's
>>> `sampleon` function:
>>>
>>> using Reactive, Interact
>>> f = figure();
>>>
>>> α=slider(1:0.1:3)
>>> β=slider(1:0.1:3)
>>> γ=slider(1:0.1:3)
>>> replot = button("Replot") # Commit your changes
>>> map(display, α, β, γ, replot) # optional
>>>
>>> sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
>>>
>>> withfig(f)
>>>
>>> @lift plot(apply(fun, sampled_coeffs))
>>>
>>> IPython doesn't do update on release, Interact, in fact, uses the same
>>> widgets. What it does do is have at most 4 updates at any given time in the
>>> processing pipeline (any more updates replace the last update in the queue).
>>>
>>> On Mon, Sep 8, 2014 at 8:45 PM, Andrei Berceanu 
>>> wrote:
>>>
 Another option would be to use drop-down boxes with selectable values
 or custom text boxes instead of sliders, at least as a temporary fix.
 Anyone knows how I can do that?
 By the way, iirc, IPython does have the update-on-release mechanism
 implemented in their interactive widget functionality.

 On Monday, September 8, 2014 4:10:05 PM UTC+2, John Myles White wrote:
>
> I suspect the only way to do this is to change Interact so that it
> exposes a minimum time threshold before it registers a state change.
>
>  — John
>
> On Sep 8, 2014, at 4:16 AM, Andrei Berceanu 
> wrote:
>
> > I have some code along the lines of
> >
> > f = figure()
> > @manipulate for α=1:0.1:3, β=1:0.1:3, γ=1:0.1:3; withfig(f) do
> > y = fun(α,β,γ)
> > PyPlot.plot(x, y)
> > end
> > end
> >
> > where fun is a *very slow* function to evaluate. Is there any way to
> tell @manipulate to update the resulting plot only after I release the
> sliders? Otherwise what I get is, I release them to the desised values and
> then have to wait ages for all the intermediate plots to be drawn.
> >
> > Tnx!
>
>
>>>
>>


Re: [julia-users] Interact + PyPlot: only update when releasing slider

2014-09-09 Thread Andrei Berceanu
Thank you both for the suggestions! I am currently trying the "Replot" 
button approach, but ran into some errors, as follows:

using Reactive, Interact
using PyPlot

fun(α, β, γ) = cos(α + sin(β+γ)) #example function

f = figure();

α=slider(1:0.1:3)
β=slider(1:0.1:3)
γ=slider(1:0.1:3)
replot = button("Replot") # Commit your changes
map(display, α, β, γ, replot) # optional
-->  `start` has no method matching start(::Slider{Float64})

sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
-->  redo not defined

withfig(f)
@lift plot(apply(fun, sampled_coeffs))
--> `withfig` has no method matching withfig(::Figure)


On Monday, September 8, 2014 6:10:59 PM UTC+2, Shashi Gowda wrote:
>
> John's suggestion is also a good way to do this. You can sample the 
> signals at a specific interval instead of on button clicks:
>
> # At 2 fps, with repeats dropped.
> sampled_coeffs = droprepeats(sampleon(fps(2), lift(tuple, α, β, γ)))
>
> On Mon, Sep 8, 2014 at 9:36 PM, Shashi Gowda  > wrote:
>
>> Unfortunately, the @manipulate macro can only rerun the expression at 
>> every update of any of its input.
>>
>> What you need here is Reactive 
>> 's 
>> `sampleon` function:
>>
>> using Reactive, Interact
>> f = figure();
>>
>> α=slider(1:0.1:3)
>> β=slider(1:0.1:3)
>> γ=slider(1:0.1:3)
>> replot = button("Replot") # Commit your changes
>> map(display, α, β, γ, replot) # optional
>>
>> sampled_coeffs = sampleon(redo, lift(tuple, α, β, γ))
>>
>> withfig(f)
>>
>> @lift plot(apply(fun, sampled_coeffs))
>>
>> IPython doesn't do update on release, Interact, in fact, uses the same 
>> widgets. What it does do is have at most 4 updates at any given time in the 
>> processing pipeline (any more updates replace the last update in the queue).
>>
>> On Mon, Sep 8, 2014 at 8:45 PM, Andrei Berceanu > > wrote:
>>
>>> Another option would be to use drop-down boxes with selectable values or 
>>> custom text boxes instead of sliders, at least as a temporary fix. Anyone 
>>> knows how I can do that?
>>> By the way, iirc, IPython does have the update-on-release mechanism 
>>> implemented in their interactive widget functionality.
>>>
>>> On Monday, September 8, 2014 4:10:05 PM UTC+2, John Myles White wrote:

 I suspect the only way to do this is to change Interact so that it 
 exposes a minimum time threshold before it registers a state change. 

  — John 

 On Sep 8, 2014, at 4:16 AM, Andrei Berceanu  
 wrote: 

 > I have some code along the lines of 
 > 
 > f = figure() 
 > @manipulate for α=1:0.1:3, β=1:0.1:3, γ=1:0.1:3; withfig(f) do 
 > y = fun(α,β,γ) 
 > PyPlot.plot(x, y) 
 > end 
 > end 
 > 
 > where fun is a *very slow* function to evaluate. Is there any way to 
 tell @manipulate to update the resulting plot only after I release the 
 sliders? Otherwise what I get is, I release them to the desised values and 
 then have to wait ages for all the intermediate plots to be drawn. 
 > 
 > Tnx! 


>>
>

[julia-users] Re: multi-panel interactive figure with PyPlot

2014-09-09 Thread Andrei Berceanu
I just submitted https://github.com/stevengj/PyPlot.jl/issues/84.

//A

On Monday, September 8, 2014 1:31:21 PM UTC+2, Andrei Berceanu wrote:
>
> I'm trying to create a two-panel interactive figure using Interact.jl and 
> PyPlot.jl. Based on the example notebooks from Interact.jl, I came up with 
> the following:
>
> using Reactive, Interact
> using PyPlot
>
> x = linspace(0,2π,1000);
> f, axes = plt.subplots(1,2, figsize=(4, 4))
> @manipulate for α=1:0.1:3, β=1:0.1:3, γ=1:0.1:3; withfig(f) do
> y = cos(α*x + sin(β*x + γ))
> axes[1][:plot](x, y)
> axes[2][:plot](x, 1/y)
> end
> end
>
> which gives me:
>
> PyError (PyObject_Call) 
> ValueError('Axes instance argument was not found in a figure.',)
>
> Anyone knows how to fix this? Tnx!
>
>
>
>

[julia-users] Re: "self" dot product of all columns in a matrix: Julia vs. Octave

2014-09-09 Thread Ján Dolinský
Hello guys,

Thanks a lot for the lengthy discussions. It helped me a lot to get a 
feeling on what is Julia like. I did some more performance comparisons as 
suggested by first two posts (thanks a lot for the tips). In the mean time 
I upgraded to v0.3.
X = rand(7000,7000);
@time d = sum(X.^2, 1);
elapsed time: 0.573125833 seconds (392056672 bytes allocated, 2.25% gc time)
@time d = sum(X.*X, 1);
elapsed time: 0.178715901 seconds (392057080 bytes allocated, 14.06% gc time
)
@time d = sumabs2(X, 1);
elapsed time: 0.067431808 seconds (56496 bytes allocated)

In Octave then
X = rand(7000);
tic; d = sum(X.^2); toc;
Elapsed time is 0.167578 seconds.

So the ultimate solution is the sumabs2 function which is a blast. I am 
comming from Matlab/Octave and I would expect X.^2 to be fast "out of the 
box" but nevertheless if I can get an excellent performance by learning 
some new paradigms I will go for it.

The above tests lead me to another question. I often need to calculate the 
"self" dot product over a portion of a matrix, e.g.
@time d = sumabs2(X[:,1001:end], 1);
elapsed time: 0.17566 seconds (336048688 bytes allocated, 7.01% gc time)

Apparently this is not a way to do it in Julia because working on a smaller 
matrix of 7000x6000 gives more than double computing time and furthermore 
it seems to allocate unnecessary memory.

Best Regards,
Jan



Dňa pondelok, 8. septembra 2014 10:36:02 UTC+2 Ján Dolinský napísal(-a):
>
> Hello,
>
> I am a new Julia user. I am trying to write a function for computing 
> "self" dot product of all columns in a matrix, i.e. calculating a square of 
> each element of a matrix and computing a column-wise sum. I am interested 
> in a proper way of doing it because I often need to process large matrices.
>
> I first put a focus on calculating the squares. For testing purposes I use 
> a matrix of random floats of size 7000x7000. All timings here are deducted 
> after several repetitive runs.
>
> I used to do it in Octave (v3.8.1) a follows:
> tic; X = rand(7000); toc;
> Elapsed time is 0.579093 seconds.
> tic; XX = X.^2; toc;
> Elapsed time is 0.114737 seconds.
>
>
> I tried to to the same in Julia (v0.2.1):
> @time X = rand(7000,7000);
> elapsed time: 0.114418731 seconds (392000128 bytes allocated)
> @time XX = X.^2;
> elapsed time: 0.369641268 seconds (392000224 bytes allocated)
>
> I was surprised to see that Julia is about 3 times slower when calculating 
> a square than my original routine in Octave. I then read "Performance tips" 
> and found out that one should use * instead of of raising to small integer 
> powers, for example x*x*x instead of x^3. I therefore tested the 
> following.
> @time XX = X.*X;
> elapsed time: 0.146059577 seconds (392000968 bytes allocated)
>
> This approach indeed resulted in a lot shorter computing time. It is still 
> however a little slower than my code in Octave. Can someone advise on any 
> performance tips ?
>
> I then finally do a sum over all columns of XX to get the "self" dot 
> product but first I'd like to fix the squaring part.
>
> Thanks a lot. 
> Best Regards,
> Jan 
>
> p.s. In Julia manual I found a while ago an example of using @vectorize 
> macro with a squaring function but can not find it any more. Perhaps the 
> name of macro was different ... 
>   
>


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

2014-09-09 Thread gentlebeldin
Not true, & is an undocumented singular case (regrettably). - is a unary 
operator, too, but nonetheless, -(1,5) gives -4, as it well should.

Am Dienstag, 9. September 2014 00:41:01 UTC+2 schrieb Jake Bolewski:
>
> Anyt unary operator defined as a `syntatic_unary_operator` 
> https://github.com/jakebolewski/JuliaParser.jl/blob/master/src/lexer.jl#L103 
> is special cased by the parser and works similarly. 
>
> On Monday, September 8, 2014 4:31:48 PM UTC-4, Stefan Karpinski wrote:
>>
>> I believe it is because of the use of & in ccall as a pseudo-operator to 
>> pass the address of a scalar. Jeff will have to confirm or deny this though.
>>
>>
>> On Mon, Sep 8, 2014 at 10:25 PM, Dan Luu  wrote:
>>
>>> julia> 1 | 2
>>> 3
>>> julia> 1 & 2
>>> 0
>>> julia> 1 + 2
>>> 3
>>> julia> 1 $ 2
>>> 3
>>> julia> |(1, 2)
>>> 3
>>> julia> &(1, 2)
>>> ERROR: unsupported or misplaced expression &
>>> julia> +(1, 2)
>>> 3
>>> julia> $(1, 2)
>>> ERROR: unsupported or misplaced expression $
>>>
>>> Is & used in some way julia that makes &(1, 2) potentially ambiguous?
>>>
>>> Apologies if this is in the archives; I couldn't figure how to
>>> effectively search for '&' or 'and'.
>>>
>>>
>>> Dan
>>>
>>
>>