mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
563 stars 40 forks source link

upsample align_corners #215

Closed ziyi-zhang closed 6 months ago

ziyi-zhang commented 7 months ago

Add the optional flag align_corners to upsample. This is in line with PyTorch upsample.

To upsample the following 2D texture (bi-linear interp) to be 5x5

[[1 2]
 [3 4]]

With align_corners = False (default), the result is

[[1.        1.1000001 1.5       1.9000001 2.0000002]
 [1.2       1.3000001 1.7       2.1       2.2000003]
 [2.        2.1000001 2.5       2.9       3.       ]
 [2.8000002 2.9       3.3       3.6999998 3.8000002]
 [3.        3.1000004 3.5       3.9       3.9999998]]

With align_corners = True, the result is

[[1.   1.25 1.5  1.75 2.  ]
 [1.5  1.75 2.   2.25 2.5 ]
 [2.   2.25 2.5  2.75 3.  ]
 [2.5  2.75 3.   3.25 3.5 ]
 [3.   3.25 3.5  3.75 4.  ]]