Defining classdef property validations for gpuArrays

1 Ansicht (letzte 30 Tage)
Jacob Lynch August
Jacob Lynch August am 6 Nov. 2018
Beantwortet: Steven Lord am 6 Nov. 2018
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?

Antworten (2)

Matt J
Matt J am 6 Nov. 2018
Bearbeitet: Matt J am 6 Nov. 2018
Couldn't you just use Property Set Methods to enforce types?

Steven Lord
Steven Lord am 6 Nov. 2018
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.

Kategorien

Mehr zu GPU Computing finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by