output type is not currently implemented

42 views
Skip to first unread message

V

unread,
Jun 4, 2014, 12:39:29 PM6/4/14
to yal...@googlegroups.com
Hi,

Any reason why constraint/sdpvar output type is not currently implemented? Would be useful in shorthand like

n = 10 ;
x = sdpvar(n,1);
y = arrayfun(@(i) 2*x ,1:n) ;
F = arrayfun(@(i) 2*x >= 0 ,1:n) ;

Of course the actual expressions would be ones which cannot be vectorised easily or expressed with matlab's element-wise operators.

Cheers,
Vladimir

Johan Löfberg

unread,
Jun 4, 2014, 1:20:25 PM6/4/14
to yal...@googlegroups.com
Well, I guess The Mathworks haven't found built-in support for YALMIP necessary :-)

The only solution to this would be that I overloaded the arrayfun. Looks like a complex operator with many options to support, so not that likely. Can you show a typical minimal realistic case you would like to see supported?

V

unread,
Jun 4, 2014, 1:55:50 PM6/4/14
to yal...@googlegroups.com
I have a function which returns a set of constraints. I call this function many times with different parameters in a while loop. That gives me the overall constraint set which I pass to solvesdp.

It's just nicer to sometimes write arrayfun instead of while loop. Actually this seems to work like I want

n = 5 ;
x = sdpvar(n,1);

y = arrayfun(@(i) x(i),1:n,'UniformOutput',false) ;
y=[y{:}]

F = arrayfun(@(i) x(i) >= 0,1:n,'UniformOutput',false) 
F=[F{:}]


In fact just playing around a bit

% the usual way
s = 4000 ; % some large number
tic ;
F1 = []
for i=1:s
    F1 = [F1; x >= 0] ;
end
toc

% new way
tic
F2 = arrayfun(@(i) x >= 0,1:s,'UniformOutput',false) ;
F2=[F2{:}];
toc

It seems the second one is a lot faster. I guess because it doesn't have to copy every time?

Vladimir



Johan Löfberg

unread,
Jun 4, 2014, 2:00:21 PM6/4/14
to yal...@googlegroups.com
So the conclusion is that it works already?

Yes, the second version is faster since it only calls the concatenation method for the constraint class once, while the other once does it 4000 times with increasingly larger first argument

V

unread,
Jun 4, 2014, 2:26:34 PM6/4/14
to yal...@googlegroups.com
It seems so. I only just found out you can do [y{:}]. The constraint concatenation was my main bottleneck. Perhaps it is a faster way to "preallocate" constraints, since you can't do it directly, e.g.

tic
s = 4000 ;
F3 = cell(s,1);
for i=1:s
   F3{i} = [x >= 0] ;
end
F3=[F3{:}];
toc


Vladimir

Reply all
Reply to author
Forward
0 new messages