# 通过quant自定义数据类型

https://yuanming.taichi.graphics/publication/2021-quantaichi/quantaichi.pdf

@YuPeng 谢谢，老师。 请问下，使用default_fp=ti.f64之后，是不是就没法再用Quant了？

``````# ti.init(arch=ti.cpu, cpu_max_num_threads=1, default_fp=ti.f64)  # Try to run on GPU

ti.init(arch=ti.cuda, default_fp=ti.f64)  # Try to run on GPU
# ti.init(arch=ti.cuda, default_fp=ti.f64,random_seed=int(time.time()))
# random_seed=int(time.time())3
# summ = ti.field(dtype=float, shape=())  # grid forces
# summ[None] = 1000000000
# fixed17 = ti.quant.fixed(frac=17, range=3.14)
f19 = ti.types.quantized_types.quant.float(exp=6, frac=13, signed=True)

summ = ti.field(dtype=float, shape=())  # grid forces
summ1 = ti.field(dtype=float, shape=())  # grid forces

@ti.kernel
def func():
for indx in range(10000000):
summ[None] += 0.000001
summ[None] -= 1000000000

@ti.kernel
def func1():
c = 0.0
for indx in range(1000000):
summ1[None] += 0.000001
summ1[None] -= 1000000000
#
# test()
# # print('非精确解（双精度）：', summ[None])
# print('精确解GPU：', summ1[None])
for i in range(10):
summ[None] = 1000000000.0
func()
print('数值解1(优化)：', summ[None])

summ1[None] = 1000000000.0
func1()
print('数值解2(非优化)：', summ1[None])
``````