필터 지우기
필터 지우기

Defining classdef property validations for gpuArrays

조회 수: 1 (최근 30일)
Jacob Lynch August
Jacob Lynch August 2018년 11월 6일
답변: Steven Lord 2018년 11월 6일
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