0

I'm trying to calculate the probability that a point (a nxn matrix) uniformly distributed in R^(n^2) exclusively has eigenvalues with negative real part, but I keep getting the following error:

Not enough input arguments.

Error in probability_n (line 4)
for i = 1:num_pts

Here is my code:

N = 10^2;
num_pts = 10^4;
n = 2;
n = n*ones(N,1,'gpuArray');

k = arrayfun(probability_n,n,num_pts);

and the function called is

function k = probability_n(n,num_pts)

    k = 0;
    for i = 1:num_pts
        R = reshape(randsphere(1,n^2,1),n,n);
        if all(real(eig(R))<0)
            k = k+1;
        end
    end

end

function P = randsphere(m,n,r)

    P = randn(m,n);
    s2 = sum(P.^2,2);
    P = P.*repmat(r*(gammainc(s2/2,n/2).^(1/n))./sqrt(s2),1,n);

end

Why is this happening? I suspect it is something very simple to do with a syntax error, since this is my first time trying to use my GPU for MATLAB. The GPU is an Nvidia GeForce GTX 580. Thanks.

0

1 Answer 1

2

In general, it's best to test things in vanilla MATLAB (without GPU or parallel processing) if you experience issues to see if the issue is specific to the GPU or parallel processing or whether it's something else. If you do that, you'll see that your code still doesn't work.

This is because you need to pass a function handle for probability_n to arrayfun, as you have it written, probability_n is implicitly called with no input arguments (you don't need the () to invoke a function). You receive the error you do when MATLAB tries to access num_pts from within probability_n and it hasn't been provided.

k = arrayfun(@probability_n, n, num_pts);

Note that passing the scalar num_pts as the third input only works when the first input to arrayfun is a gpuarray object. Otherwise, you'll want to create an anonymous function which passes num_pts to probability_n

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but now I get another error: Error using gpuArray/arrayfun \\ Use of functional workspace is not supported. For more information see Tips and Restrictions. Is this because some built-in functions used in the randsphere function is not supported for GPU usage?
Thanks, but now I get Function passed as first input argument contains unsupported or unknown function 'reshape'. I suspect it is because it is not supported in GPU-mode. I don't think num_pts being a scalar is a problem. From the doc: A = arrayfun(FUN,B,C,...) evaluates FUN using elements of arrays B, C, ... as input arguments with singleton expansion enabled. [...] The inputs B, C, ... must all have the same size or be scalar. Any scalar inputs are scalar expanded before being input to the function FUN.
@Lovsovs Yes, all functions you use within your function must be implemented for gpuarray objects since the data resides on the GPU. Also you're right about arrayfun on the GPU, this must have changed in a recent release. I have updated it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.