Re: [julia-users] ControKTH

2016-06-13 Thread Linus Härenstam-Nielsen
I have to admit I did not take any licencing issues into consideration before 
uploading the code. I've deleted the repository for now but I will post 
here again if I end up re-uploading.

On Monday, June 13, 2016 at 4:34:01 PM UTC+2, Stefan Karpinski wrote:
>
> There is no LICENSE file in that directory, so using this code is legally 
> iffy. Linus says he "copied part of MatLab's algorithm", which makes 
> legality sound even more questionable. Linus, can you address the license 
> issues here and in the repository? What license was the original code 
> under? What license is this code under?
>
> On Sun, Jun 12, 2016 at 2:54 PM, Linus Härenstam-Nielsen <
> linu...@gmail.com > wrote:
>
>> Here we go: https://github.com/Linusnie/ControlBasic
>>
>> Note that at the time I used a 0.4.0 dev build so everything might not 
>> work properly. 
>>
>>
>> On Sunday, June 12, 2016 at 7:35:51 PM UTC+2, Linus Härenstam-Nielsen 
>> wrote:
>>>
>>> Hi author of (part of) ControlKTH here
>>>
>>> This was indeed a student project last summer, we based the development 
>>> on Control.jl <https://github.com/jcrist/Old-Control.jl>. We decided 
>>> not to post the code publicly under the university name since I copied part 
>>> of MatLab's algorithm for drawing root locus diagrams, but since you ask I 
>>> could post it on my private repository. 
>>>
>>> I'll write here once I've done so. 
>>>
>>> On Sunday, June 12, 2016 at 5:47:34 AM UTC+2, Christian Peel wrote:
>>>>
>>>> Here are two pertinent links
>>>> * 
>>>> https://www.kth.se/polopoly_fs/1.627826!/harenstam-nielsen_lindemann.pdf
>>>> * 
>>>> https://www.kth.se/social/files/55f124f8f276547bba8a16f9/controldoc.pdf
>>>>
>>>> I guess they refer to a student project to implement basic control 
>>>> theory concepts in Julia. Even if it is not too fancy, it would be useful 
>>>> for the author (cc'd) to post the code publicly.  
>>>>
>>>> On Sat, Jun 11, 2016 at 4:48 PM, Stefan Karpinski <ste...@karpinski.org
>>>> > wrote:
>>>>
>>>>> The top Google hit on "ControKTH" is this message thread. After that 
>>>>> the hits are all nonsense. It's also completely unclear what EL1000 is 
>>>>> supposed to be.
>>>>>
>>>>> On Sat, Jun 11, 2016 at 6:06 AM, Henri Girard <henri@gmail.com> 
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>> Does somebody knows where I can get the control toolbox ?
>>>>>>
>>>>>> EL1000 home page and download the ControlKTH.zip
>>>>>> Is there other toolbox for julia ?
>>>>>> Regards
>>>>>> Henri
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> -- 
>>>> chris...@ieee.org
>>>>
>>>
>

Re: [julia-users] ControKTH

2016-06-12 Thread Linus Härenstam-Nielsen
Here we go: https://github.com/Linusnie/ControlBasic

Note that at the time I used a 0.4.0 dev build so everything might not work 
properly. 


On Sunday, June 12, 2016 at 7:35:51 PM UTC+2, Linus Härenstam-Nielsen wrote:
>
> Hi author of (part of) ControlKTH here
>
> This was indeed a student project last summer, we based the development on 
> Control.jl <https://github.com/jcrist/Old-Control.jl>. We decided not to 
> post the code publicly under the university name since I copied part of 
> MatLab's algorithm for drawing root locus diagrams, but since you ask I 
> could post it on my private repository. 
>
> I'll write here once I've done so. 
>
> On Sunday, June 12, 2016 at 5:47:34 AM UTC+2, Christian Peel wrote:
>>
>> Here are two pertinent links
>> * 
>> https://www.kth.se/polopoly_fs/1.627826!/harenstam-nielsen_lindemann.pdf
>> * https://www.kth.se/social/files/55f124f8f276547bba8a16f9/controldoc.pdf
>>
>> I guess they refer to a student project to implement basic control theory 
>> concepts in Julia. Even if it is not too fancy, it would be useful for the 
>> author (cc'd) to post the code publicly.  
>>
>> On Sat, Jun 11, 2016 at 4:48 PM, Stefan Karpinski <ste...@karpinski.org> 
>> wrote:
>>
>>> The top Google hit on "ControKTH" is this message thread. After that the 
>>> hits are all nonsense. It's also completely unclear what EL1000 is supposed 
>>> to be.
>>>
>>> On Sat, Jun 11, 2016 at 6:06 AM, Henri Girard <henri@gmail.com> 
>>> wrote:
>>>
>>>> Hi,
>>>> Does somebody knows where I can get the control toolbox ?
>>>>
>>>> EL1000 home page and download the ControlKTH.zip
>>>> Is there other toolbox for julia ?
>>>> Regards
>>>> Henri
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>> -- 
>> chris...@ieee.org
>>
>

Re: [julia-users] ControKTH

2016-06-12 Thread Linus Härenstam-Nielsen
Hi author of (part of) ControlKTH here

This was indeed a student project last summer, we based the development on 
Control.jl . We decided not to 
post the code publicly under the university name since I copied part of 
MatLab's algorithm for drawing root locus diagrams, but since you ask I 
could post it on my private repository. 

I'll write here once I've done so. 

On Sunday, June 12, 2016 at 5:47:34 AM UTC+2, Christian Peel wrote:
>
> Here are two pertinent links
> * https://www.kth.se/polopoly_fs/1.627826!/harenstam-nielsen_lindemann.pdf
> * https://www.kth.se/social/files/55f124f8f276547bba8a16f9/controldoc.pdf
>
> I guess they refer to a student project to implement basic control theory 
> concepts in Julia. Even if it is not too fancy, it would be useful for the 
> author (cc'd) to post the code publicly.  
>
> On Sat, Jun 11, 2016 at 4:48 PM, Stefan Karpinski  > wrote:
>
>> The top Google hit on "ControKTH" is this message thread. After that the 
>> hits are all nonsense. It's also completely unclear what EL1000 is supposed 
>> to be.
>>
>> On Sat, Jun 11, 2016 at 6:06 AM, Henri Girard > > wrote:
>>
>>> Hi,
>>> Does somebody knows where I can get the control toolbox ?
>>>
>>> EL1000 home page and download the ControlKTH.zip
>>> Is there other toolbox for julia ?
>>> Regards
>>> Henri
>>>
>>>
>>>
>>>
>>
>
>
> -- 
> chris...@ieee.org 
>


[julia-users] rref in 0.4.3

2016-02-04 Thread Linus Härenstam-Nielsen
So it seems like the rref function has been taken out from Base 
(https://github.com/JuliaLang/julia/pull/9804). Is there a package floating 
around that contains the same function? I really liked having it for 
checking my work and for a quick way of find spanning vectors for kernel 
spaces etc.. 




[julia-users] Re: setindex! for matrix of vectors

2015-07-29 Thread Linus Härenstam-Nielsen
I haven't found a solution that works perfectly yet but I circumvented the 
problem by making a check for colons:

rows = inds[1] == Colon() ? (1:sys.ny) : inds[1]
cols = inds[2] == Colon() ? (1:sys.nu) : inds[2]

Not perfect since it limits you to always have to use exactly 2 incidences, 
but it works in my case. 

Maybe the handling of Array{Vector} should be looked at, seems to me that 
there are quiet a few cases where you run into problems with that datatype. 
For example, I don't think there is a built in way to transpose an 
Array{Vector, N1}.


[julia-users] setindex! for matrix of vectors

2015-07-28 Thread Linus Härenstam-Nielsen
I'm implementing a setindex! method for an object with a field of type 
Matrix{Vector{Float64}} (a matrix of vectors) and I've run into a problem 
with getting the Colon() index to work properly. It comes down to this:

julia A = Array(Vector{Int}, 1)
1-element Array{Array{Int64,1},1}:
 #undef

julia A[:] = [1,2,3]
ERROR: DimensionMismatch(tried to assign 3 elements to 1 destinations)
 in throw_setindex_mismatch at operators.jl:226

Since the element I'm trying to assign is a vector setindex! calls the 
wrong method for my purposes. What I would like is for the resulting array 
to be:

julia A
1-element Array{Array{Int64,1},1}:
 [1,2,3]

Is there a way to get around this? I would change the datatype to 
Array{Float64, 3} if I could but other functions rely on the current 
structure.


[julia-users] Tracking a type instability

2015-07-24 Thread Linus Härenstam-Nielsen
I recently poked around a bit with the @code_warntype macro in my code and 
quickly realized that a lot of my variables were assigned Any at compile 
time. I tried to find the reason for it and got down to the eig function: 

julia @code_warntype eig(rand(Float64, 5,5))
Variables:
  A::Array{Float64,2}
  args::Tuple{}

Body:
  begin $(Expr(:line, 66, symbol(linalg/eigen.jl), symbol()))
  GenSym(8) = (top(ccall))(:jl_alloc_array_1d,$(Expr(:call1, 
:(top(apply_type)), :Array, Any, 1)),$(Expr(:call1, :(top(svec)), :Any, 
:Int)),Array{Any,1},0,0,0)::Array{Any,1}
  GenSym(9) = GenSym(8)
  return __eig#179__(GenSym(9),A::Array{Float64,2})::Tuple{Any,Any}
  end::Tuple{Any,Any}


Is there a reason this returns Tuple{Any, Any} instead of Tuple{Complex128, 
Complex128} as you might expect? As far as I understand it this causes 
everything touched by the eig function to become type unstable. 


Re: [julia-users] Tracking a type instability

2015-07-24 Thread Linus Härenstam-Nielsen
Thanks for the replies. I filed the issue here 
https://github.com/JuliaLang/julia/issues/12304 (#12304)

On Friday, July 24, 2015 at 4:09:07 PM UTC+2, Stefan Karpinski wrote:

 Please do file an issue https://github.com/JuliaLang/julia/issues if 
 you haven't already.

 On Fri, Jul 24, 2015 at 5:09 AM, Mauro maur...@runbox.com javascript: 
 wrote:

  I recently poked around a bit with the @code_warntype macro in my code 
 and
  quickly realized that a lot of my variables were assigned Any at 
 compile
  time. I tried to find the reason for it and got down to the eig 
 function:
 
  julia @code_warntype eig(rand(Float64, 5,5))
  Variables:
A::Array{Float64,2}
args::Tuple{}
 
  Body:
begin $(Expr(:line, 66, symbol(linalg/eigen.jl), symbol()))
GenSym(8) = (top(ccall))(:jl_alloc_array_1d,$(Expr(:call1,
  :(top(apply_type)), :Array, Any, 1)),$(Expr(:call1, :(top(svec)), :Any,
  :Int)),Array{Any,1},0,0,0)::Array{Any,1}
GenSym(9) = GenSym(8)
return __eig#179__(GenSym(9),A::Array{Float64,2})::Tuple{Any,Any}
end::Tuple{Any,Any}
 
 
  Is there a reason this returns Tuple{Any, Any} instead of 
 Tuple{Complex128,
  Complex128} as you might expect? As far as I understand it this causes
  everything touched by the eig function to become type unstable.

 The reason is the method getindex(A::Union{Eigen,GeneralizedEigen},
 d::Symbol) near the top of base/linalg/eigen.jl which is not type
 stable.  This is then used in eig.  Have a look at it with

 @edit eig(rand(Float64, 5,5))

 I suspect this is a bug, you should file a report.  In the meantime you
 can monkey patch by adding this to your code:

 function Base.eig(A::Union{Number, AbstractMatrix}, args...; kwargs...)
 F = eigfact(A, args...; kwargs...)
 F.values, F.vectors
 end




Re: [julia-users] Passing keyword arguments through a function

2015-07-21 Thread Linus Härenstam-Nielsen
This worked! Didn't realize you could use ; when calling functions. 


On Tuesday, July 21, 2015 at 4:49:36 PM UTC+2, Stefan Karpinski wrote:

 f(floor(x); args...) should work.

 On Tue, Jul 21, 2015 at 10:14 AM, Linus Härenstam-Nielsen 
 linu...@gmail.com javascript: wrote:

 I am looking for a way to automatically pass on all keyword arguments 
 through a function. Naively I would like to be able to do something like 
 this: 

 f(x::Int; y::Int=5, z::Int=3) = x+y+z
 f(x::Float64; args...) = f(floor(x), args...)

 But that doesn't work currently (actually, it causes StackOverflowError 
 in 0.4.0). So far I've been using the following instead:

 f(x::Float64, y::Int=5, z::Int=3) = f(floor(x), y=y, z=z)

 But that gets messy very quickly if there are several keyword arguments 
 to handle. Does anyone know of a clean way to do this?





[julia-users] Passing keyword arguments through a function

2015-07-21 Thread Linus Härenstam-Nielsen
I am looking for a way to automatically pass on all keyword arguments 
through a function. Naively I would like to be able to do something like 
this: 

f(x::Int; y::Int=5, z::Int=3) = x+y+z
f(x::Float64; args...) = f(floor(x), args...)

But that doesn't work currently (actually, it causes StackOverflowError in 
0.4.0). So far I've been using the following instead:

f(x::Float64, y::Int=5, z::Int=3) = f(floor(x), y=y, z=z)

But that gets messy very quickly if there are several keyword arguments to 
handle. Does anyone know of a clean way to do this?




[julia-users] Multiple dispatch for keyword arguments

2015-06-30 Thread Linus Härenstam-Nielsen
As I understand it keyword arguments aren't affected by multiple dispatch, 
I'm guessing it is a performance decition but it means you can run into the 
following situation: 

 f(x::Int; t::Int=0) = t
 f(x::Number; t::Number=1) = t
 f(1, t=1.0)
 ERROR:TypeError:f:intypeassert, expected Int64, got Float64

That is, the first method is used even though the second would be 
appropriate if t was accounted for. Is there a standard way of dealing with 
this? I am working with a function with several keyword arguments and it 
has me stuck.


[julia-users] Supertypes in function arguments

2015-06-26 Thread Linus Härenstam-Nielsen
I ran into a problem with types today that I don't know how to interpret.

If I define a function according to 
f(x::Real) = x
it returns x as expected as long as the type of x is a subtype of Real. 
However if I define
f(x::Array{Real}) = x
it throws MethodError no matter what I pass as argument. For example when I 
try to pass it an Int array:
f([1 2 3; 3 4 5])
ERROR: MethodError: `f` has no method matching f(::Array{Int64,2})

I would expect it to work like
f{T:Real}(x::Array{T}) = x
and accept any array of reals. Am I missing something?





[julia-users] Re: Supertypes in function arguments

2015-06-26 Thread Linus Härenstam-Nielsen
Ok, that makes sense. In that case what would be the best way to write a 
funcion that accepts several Real arrays (of not necessarily the same 
type)? Currently I'm using 

function f{T1,T2,T3 : Real}(x::Array{T1}, y::Array{T2}, z::Array{T3})
 ...
end

But that gets messy very quickly if there are many arguments. 

On Friday, June 26, 2015 at 6:00:25 PM UTC+2, Tim Wheeler wrote:

 Hello Linus,

 This is based on how array types are defined. In general, Vector{subtype} 
 is not a subtype of Vector{supertype}.
 Try this:

 f{R:Real}(x::Array{R}) = x

 -Tim

 On Friday, June 26, 2015 at 8:38:12 AM UTC-7, Linus Härenstam-Nielsen 
 wrote:

 I ran into a problem with types today that I don't know how to interpret.

 If I define a function according to 
 f(x::Real) = x
 it returns x as expected as long as the type of x is a subtype of Real. 
 However if I define
 f(x::Array{Real}) = x
 it throws MethodError no matter what I pass as argument. For example when 
 I try to pass it an Int array:
 f([1 2 3; 3 4 5])
 ERROR: MethodError: `f` has no method matching f(::Array{Int64,2})

 I would expect it to work like
 f{T:Real}(x::Array{T}) = x
 and accept any array of reals. Am I missing something?





[julia-users] Re: PyPlot not working on 0.4.0

2015-06-19 Thread Linus Härenstam-Nielsen
This fixed it! Thanks 

[julia-users] PyPlot not working on 0.4.0

2015-06-18 Thread Linus Härenstam-Nielsen
I am having problems with using PyPlot in the nightly build (version 
0.4.0). Typing 'using PyPlot' followed by 'plot([sin(a) for 
a=linspace(0,2*pi)])' yields the following:

   _
   _   _ _(_)_ |  A fresh approach to technical computing
  (_) | (_) (_)|  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type help() for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-dev+5416 (2015-06-17 00:39 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 0bb31a0 (1 day old master)
|__/   |  x86_64-w64-mingw32

julia using PyPlot
Warning: New definition
call(Type{PyCall.PyDict}, Base.Associative{#K:Any, Any}) at 
C:\Users\Linus\.julia\v0.4\PyCall
rc\conversions.jl:464
is ambiguous with:
call(Type{PyCall.PyDict}, Base.Associative{Any, #V:Any}) at 
C:\Users\Linus\.julia\v0.4\PyCall
rc\conversions.jl:463.
To fix, define
call(Type{PyCall.PyDict}, Base.Associative{Any, Any})
before the new definition.
WARNING: No working GUI backend found for matplotlib.
C:\Anaconda\lib\site-packages\matplotlib\__init__.py:1318: UserWarning: 
 This call to matplotlib.u
() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
WARNING: ntuple(n::Integer,f::Function) is deprecated, use ntuple(f,n) 
instead.
 in depwarn at deprecated.jl:62
 in ntuple at deprecated.jl:49
 in convert at C:\Users\Linus\.julia\v0.4\PyCall\src\conversions.jl:222
 in py2array at C:\Users\Linus\.julia\v0.4\PyCall\src\conversions.jl:73
 in convert at C:\Users\Linus\.julia\v0.4\PyCall\src\conversions.jl:429
 in pywrap at C:\Users\Linus\.julia\v0.4\PyCall\src\PyCall.jl:305
 in pywrap at C:\Users\Linus\.julia\v0.4\PyCall\src\PyCall.jl:304
 in __init__ at C:\Users\Linus\.julia\v0.4\PyPlot\src\PyPlot.jl:149
 in include at boot.jl:254
 in include_from_node1 at loading.jl:133
 in reload_path at loading.jl:157
 in _require at loading.jl:69
 in require at loading.jl:52
while loading C:\Users\Linus\.julia\v0.4\PyPlot\src\PyPlot.jl, in 
expression starting on line 560

julia plot([sin(a) for a=linspace(0,2*pi)])
WARNING: ntuple(n::Integer,f::Function) is deprecated, use ntuple(f,n) 
instead.
 in depwarn at deprecated.jl:62
 in ntuple at deprecated.jl:49
 in convert at C:\Users\Linus\.julia\v0.4\PyCall\src\conversions.jl:222
 in convert at C:\Users\Linus\.julia\v0.4\PyCall\src\conversions.jl:846
 in jl_Function_call at C:\Users\Linus\.julia\v0.4\PyCall\src\callback.jl:36
 in pycall at C:\Users\Linus\.julia\v0.4\PyCall\src\PyCall.jl:73
 in plot at C:\Users\Linus\.julia\v0.4\PyPlot\src\PyPlot.jl:371
 in anonymous at no file
while loading no file, in expression starting on line 0
1-element Array{Any,1}:
 PyObject matplotlib.lines.Line2D object at 0x1555D080

julia plot([sin(a) for a=linspace(0,2*pi)])
1-element Array{Any,1}:
 PyObject matplotlib.lines.Line2D object at 0x1555D2B0


As you can see importing PyPlot produces several warnings, one of them is 
'WARNING: 
No working GUI backend found for matplotlib' which led me to believe there 
is a problem with loading matplotlib? I am using python 2.7.9 on windows 
8.1 with the Anaconda 2.2.0 distribution and matplotlib version 1.4.3. 

The plot function returns a PyObject properly but no plot window is opened. 
In Julia 0.3.9 everything works as you would expect with no warnings.

Any ideas?