数据类型#
每个集合必须有一个单一的数据类型,由 .dtype
属性指示。
定义的数据类型有:
布尔值
UINT8
UINT16
UINT32
UINT64
INT8
INT16
INT32
INT64
FP32 (float32)
FP64 (float64)
FC32 (复数 float32) (Windows 不支持)
FC64 (complex float64) (不支持在Windows上)
graphblas.dtypes
命名空间包含这些数据类型的对象。
每个定义的类型都有一个字符串表示(通过.name
访问),
一个对应的numpy dtype(通过.np_type
访问),以及一个对应的
numba dtype(通过.numba_type
访问)。
在API调用中需要数据类型时,可以使用字符串或numpy或numba dtype来代替实际的数据类型对象。此外,Python内置的bool
、int
和float
也可以使用。int
表示INT64,float
表示FP64。
用户定义类型#
python-graphblas 支持用户定义的类型。
首先创建一个自定义的numpy数据类型。然后在graphblas.dtypes
命名空间中注册它。
NP_Point = np.dtype([("x", np.int64), ("y", np.int64)], align=True)
Point = gb.dtypes.register_new("Point", NP_Point)
# Create a 10-element sparse vector holding Points
v = gb.Vector(Point, size=10)