YALMIP and the "times" function

25 views
Skip to first unread message

Sumeet Singh

unread,
Jun 12, 2018, 6:45:23 PM6/12/18
to YALMIP
I apologize if this question has already been addressed. 

I have a ndsdpvar object X, e.g., X = sdpvar(2,2,3), and a vector sdpvar object, e.g., y = sdpvar(3,1). 

I wish to compute a product Z of size (2,2,3) such that Z(:,:,i) = X(:,:,i) * y(i), i = 1,2,3. 

If X and y were Matlab arrays, I can achieve this quickly using: X .* reshape(y, 1,1,3). 

However, this throws an error in Yalmip since Yalmip converts the X object into a 12 x1 sdpvar object. Any simple suggestions for adressing this? Ideally, using vectorization. 

Note: the actual dimensions I am working with are on the order of 10x10x2000 (hence the requirement for fast code).

Thanks!

Johan Löfberg

unread,
Jun 13, 2018, 2:45:53 AM6/13/18
to YALMIP
This singleton expansion which they added in the latest release (or maybe 2017 or something) is something I am still on the fence about. I feel it is a recipe for hidden diimension errors in the code, so I do not support it (yet...)

You will have to repmat your way to it, such as

reshape(X(:).*kron(y,ones(4,1)),2,2,3)


Sumeet Singh

unread,
Jun 13, 2018, 3:08:08 AM6/13/18
to YALMIP
Ah! Thought so. That is the currently implemented method. Curiously, a for loop ended up being faster.

Johan Löfberg

unread,
Jun 13, 2018, 3:15:20 AM6/13/18
to YALMIP
scalar * matrix when both are decision variables is highly optimized I guess

Sumeet Singh

unread,
Jun 13, 2018, 3:18:48 AM6/13/18
to YALMIP
Actually, I flag one of them as a parameter in the "optimizer" call so everything remains convex. My guess is that the sum(setup overhead time each iteration) > single (painful) setup + optimizer. 

Johan Löfberg

unread,
Jun 13, 2018, 3:38:47 AM6/13/18
to YALMIP
That doesn't make any difference. They are both symbolic variables when the problem is created, hence massive symbolic overhead
Reply all
Reply to author
Forward
0 new messages