cuquantum.cutensornet.contraction_optimizer_info_get_attribute_dtype

cuquantum.cutensornet.contraction_optimizer_info_get_attribute_dtype(int attr)[source]

Get the Python data type of the corresponding optimizer info attribute.

Parameters

attr (ContractionOptimizerInfoAttribute) – The attribute to query.

Returns

The data type of the queried attribute. The returned dtype is always a valid NumPy dtype object.

Note

This API has no C counterpart and is a convenient helper for allocating memory for contraction_optimizer_info_get_attribute() and contraction_optimizer_info_set_attribute().

Note

Unlike other enum values, for ContractionOptimizerInfoAttribute.PATH the following usage pattern is expected:

val = ContractionOptimizerInfoAttribute.PATH
dtype = contraction_optimizer_info_get_attribute_dtype(val)

# for setting a path
path = np.asarray([(1, 3), (1, 2), (0, 1)], dtype=np.int32)
# ... or for getting a path; note that num_contractions is the number of
# input tensors minus one
path = np.empty(2*num_contractions, dtype=np.int32)

path_obj = np.zeros((1,), dtype=dtype)
path_obj["num_contractions"] = path.size // 2
path_obj["data"] = path.ctypes.data

# for setting a path
contraction_optimizer_info_set_attribute(
    handle, info, val, path_obj.ctypes.data, path_obj.dtype.itemsize)

# for getting a path
contraction_optimizer_info_get_attribute(
    handle, info, val, path_obj.ctypes.data, path_obj.dtype.itemsize)
# now path is filled
print(path)