Hi, I have a class which has many arrays and a nested functions.
The goal is I want to make all the arrays as gpuarray and use arrayfun, to be run in GPU, thus I'd like to have them well vectorised. Any thought? Thanks
%%the class
classdef egclass < handle properties cond = [1 1 1 0 0]; x = [10 20 30 40 50]; y = [0 0 0 0 0]; out= [0 0 0 0 0]; end end%%the function
function doOperation(eg) [nR,nC] = size(eg.cond); %%need to be vectorised!!!
for i = 1:nC if eg.cond(i) == 0 doTimes(eg,i); end if eg.cond(i) == 1 doAdd(eg,i); end end endfunction doTimes(eg,i) eg.out(i) = eg.x(i) * eg.y(i);endfunction doAdd(eg,i) eg.out(i) = eg.x(i) + eg.y(i);end%%debug.m
clear all; clc;eg = egclass;doOperation(eg);
Best Answer