Defining classdef property validations for gpuArrays

1 次查看(过去 30 天)
Here are two scenarios I'm unsure how to handle when it comes to constructing class property validations with GPU types.
classdef NewObject
properties
Gobjs (:,1) % this is any numeric type, on or off the gpu
Types (:,1) int8 % this must be int8, on or off the gpuArray
Index (:,1) gpuArray % But enforce that uint32 is the class underlying
Grids (:,1) gpuArray % But enforce either double or single is the class underlying
end
% ... methods ...
end
What happens is that default values are instantiated but with incorrect types (e.g. usually a null gpuArray is of type double) and errors are thrown. I obviously could set default values with the correct types but then I need to manage within the functions the types, instead of letting the classdef manage the property types itself.
Is there a smarter way of letting MATLAB know the allowed types in these properties without defining a plethora of static methods to assert the conditions are met?

回答(2 个)

Matt J
Matt J 2018-11-6
编辑:Matt J 2018-11-6
Couldn't you just use Property Set Methods to enforce types?

Steven Lord
Steven Lord 2018-11-6
See the "Define Validation Functions" section on this documentation page for an example of how to create your own validator function. In this case, you'd probably want to write something like a mustHaveUnderlyingClass(a, allowedClasses) validator function that checks if the classUnderlying of the a input is a member of the allowedClasses list.

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by