Defining classdef property validations for gpuArrays

3 visualizaciones (últimos 30 días)
Jacob Lynch August
Jacob Lynch August el 6 de Nov. de 2018
Respondida: Steven Lord el 6 de Nov. de 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?

Respuestas (2)

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

Steven Lord
Steven Lord el 6 de Nov. de 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.

Categorías

Más información sobre Properties en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by