Fix geometry dtype to respect config.real(np) for NumPy 2.x compatibility#2069
Fix geometry dtype to respect config.real(np) for NumPy 2.x compatibility#2069SimingShan wants to merge 1 commit intolululxvi:masterfrom
Conversation
…lity Several geometry subclasses (Rectangle, Disk, StarShaped, Triangle, Polygon, Cuboid, GeometryXTime) created NumPy arrays via np.linspace, np.full, np.zeros, np.ones without specifying dtype, defaulting to float64. This caused a dtype mismatch with the neural network (float32 by default), resulting in "mat1 and mat2 must have the same dtype, but got Double and Float" errors in PyTorch with NumPy >= 2.0. Added dtype=config.real(np) to all affected array-creation calls, consistent with the existing pattern used in geometry_1d.py, geometry_nd.py, and sampler.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Could you provide code to demonstrate the issue? |
|
See below Training model... Traceback (most recent call last): |
|
`(base) shansiming@wuzhui:~/project/deepxde$ python test_script.py Training model... /home/shansiming/.local/lib/python3.12/site-packages/torch/autograd/graph.py:768: UserWarning: Attempting to run cuBLAS, but there was no current CUDA context! Attempting to set the primary context... (Triggered internally at ../aten/src/ATen/cuda/CublasHandlePool.cpp:135.) Best model at step 100: 'train' took 0.478478 s Training completed successfully` |
|
After the fix Training model... /home/shansiming/.local/lib/python3.12/site-packages/torch/autograd/graph.py:768: UserWarning: Attempting to run cuBLAS, but there was no current CUDA context! Attempting to set the primary context... (Triggered internally at ../aten/src/ATen/cuda/CublasHandlePool.cpp:135.) Best model at step 100: 'train' took 0.473906 s Training completed successfully` |
|
Pay attention to the numpy version @echen5503 |
|
Logs are convincing. As a final check, can you provide the test script itself? |
|
Looks like some files like geometry/pointcloud.py aren't using correct dtype either, maybe good to fix that too |
Several geometry subclasses (Rectangle, Disk, StarShaped, Triangle, Polygon, Cuboid, GeometryXTime) created NumPy arrays via np.linspace, np.full, np.zeros, np.ones without specifying dtype, defaulting to float64. This caused a dtype mismatch with the neural network (float32 by default), resulting in "mat1 and mat2 must have the same dtype, but got Double and Float" errors in PyTorch with NumPy >= 2.0.
Added dtype=config.real(np) to all affected array-creation calls, consistent with the existing pattern used in geometry_1d.py, geometry_nd.py, and sampler.py.