Defining classdef property validations for gpuArrays
조회 수: 3 (최근 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?
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!