Page-wise matrix multiplication

I wanted to perform page-wise multiplication of two 3-D arrays:
C(:,:,i) = A(:,:,i) * B(:,:,i), \forall i.
Matlab R2020b has a built-in function “pagetimes” that performs exactly this:
C = pagetimes(A, B).
However, CVX doesn’t seem to recognize “pagetimes”. What would be the most efficient way of performing this operation?
Or do CVXPY and CVXR have better ways of doing this?
Thank you!

CVX does not support pagetimes, nor implicit expansion which was introduced in MATLAB R2016b.

I’ll assume B is an n by m by k numerically populated array, because one of A and B must be a numerical array, else CVX’s DCP rule precluding multiplication of (matrix) variables would be violated.

I don’t know that there is anything better than

variable A(m,n,k)
expression C(m,m,k)
for i=1:k
  C(:,:,i) = A(:,:,i) * B(:,:,i);

No idea on CVXPY or CVXR, I’d be surprised if they have a better way.

Thank you Mark! I tried the for loop and it was very slow. I wondered if more information about the structure of my problem would help:
I was hoping to implement something like \min_c f \bigg( \Big( \sum_{i=1}^k A_i \odot (B_i C) \Big) - D \bigg) where A_i \in \mathbb{R}^{m \times p} \ \forall i, B_i \in \mathbb{R}^{m \times n} \ \forall i, C \in \mathbb{R}^{n \times p}, D \in \mathbb{R}^{m \times p}, f is a convex function, and \odot is the element-wise (Hadamard) product.
Regarding to the scale of the problem, m \approx 10^5, n \approx 10, p \approx 100, k \approx 700.
So my optimization variable is actually a 2-D matrix that is not that large. I originally thought the most efficient way would be to concatenate A_i and B_i into 3-D arrays. But since pagetimes is not an option, I wondered if there will be more efficient implementations than brute-force for-loops.
Again, thank you very much for your help!

If you can find an efficient computation in “regular” MATLAB (i.e., numerically populated variables rather than CVX variables or expressions), and it does not use language features, such as implicit expansion or pagetimes, which are unsupported in CVX, it is also likely to be efficient in CVX.

I.e., If you have some clever vectorization in regular MATLAB, that should be good for CVX.

1 Like