MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / getStructMemberIdx

Method getStructMemberIdx

python/cudaq/kernel/ast_bridge.py:959–982  ·  view source on GitHub ↗

For the given struct type and member variable name, return the index of the variable in the struct and the specific MLIR type for the variable.

(self, memberName, structTy)

Source from the content-addressed store, hash-verified

957 return result
958
959 def getStructMemberIdx(self, memberName, structTy):
960 """For the given struct type and member variable name, return the index
961 of the variable in the struct and the specific MLIR type for the
962 variable."""
963 if cc.StructType.isinstance(structTy):
964 structName = cc.StructType.getName(structTy)
965 else:
966 structName = quake.StruqType.getName(structTy)
967 structIdx = None
968 if structName == 'tuple':
969 self.emitFatalError('`tuple` does not support attribute access')
970 if not globalRegisteredTypes.isRegisteredClass(structName):
971 self.emitFatalError(f'Dataclass is not registered: {structName})')
972
973 _, userType = globalRegisteredTypes.getClassAttributes(structName)
974 for i, (k, _) in enumerate(userType.items()):
975 if k == memberName:
976 structIdx = i
977 break
978 if structIdx == None:
979 self.emitFatalError(
980 f'Invalid struct member: {structName}.{memberName} '
981 f'(members={[k for k,_ in userType.items()]})')
982 return structIdx, mlirTypeFromPyType(userType[memberName], self.ctx)
983
984 def __copyStructAndConvertElements(self,
985 struct,

Callers 1

visit_AttributeMethod · 0.95

Calls 6

emitFatalErrorMethod · 0.95
enumerateFunction · 0.85
mlirTypeFromPyTypeFunction · 0.85
getNameMethod · 0.80
isRegisteredClassMethod · 0.80
getClassAttributesMethod · 0.80

Tested by

no test coverage detected