Using Spot containers
Spot provides a set of "wrappers" that can be used to integrate external opertors with Spot utilities.
Contents
Function containers
Suppose that we have an existing function that implements a discretized Heaviside step function. This function returns a vector with the cumulative sum of the input vector (i.e., Matlab's cumsum function.) In the "adjoint" mode, our function returns the cumulative-sum vector, but in reverse order. Here is one simple way to implement such a function:
type heaviside.m
function y = heaviside(x,mode) %heaviside The discrete Heaviside transform. if mode == 1 y = cumsum(x); else y = flipud(cumsum(flipud(x))); end end
In order to make this function available as a Spot operator, we wrap it using opFunction:
n = 5; m = 5; A = opFunction(n,m,@heaviside);
Note that we provide the number of rows and columns for this particular instance, because all Spot operators must have their dimensions defined. Now A can be used like any other Spot operator. For example:
B = A(1:2:end,:); % B is a new operator with even rows of A double(B) % print the elements of B
ans = 1 0 0 0 0 1 1 1 0 0 1 1 1 1 1
Matrix containers
Spot's default behavior when multiplying operators with matrices is to apply the operator to each column of the matrix. For example, this next command scales the columns of the Heaviside operator:
C = A * diag(1:m)
C = 1 0 0 0 0 1 2 0 0 0 1 2 3 0 0 1 2 3 4 0 1 2 3 4 5
But if we instead want to form a new operator formed from the products of A and the diagonal, we first need to wrap the diagonal matrix:
C = A * opMatrix(diag(1:m))
C = Spot operator: Function(5,5) * Matrix(5,5) rows: 5 complex: no cols: 5 type: FoG
Though in this special case, we might have as well used the Spot operator opDiag instead of the more general (and in this case, cumbersome) opMatrix(diag(1:m)).
Class containers
Finally, the opClass container can be used to encapsulate objects defined by external toolboxes.