nanovdb/python: fix writeGrids dropping all but the last grid#2198
Open
swahtz wants to merge 1 commit intoAcademySoftwareFoundation:masterfrom
Open
nanovdb/python: fix writeGrids dropping all but the last grid#2198swahtz wants to merge 1 commit intoAcademySoftwareFoundation:masterfrom
swahtz wants to merge 1 commit intoAcademySoftwareFoundation:masterfrom
Conversation
The Python binding for nanovdb.io.writeGrids iterated the handle list and called io::writeGrid(fileName, ...) per element. That file-level overload opens the path with std::ios::trunc, so every iteration wiped the previously written grid and the resulting .nvdb only ever contained the last handle in the list (same story for deviceWriteGrids on the CUDA side). Mirror io::writeGrids(fileName, handles, codec, verbose) from nanovdb/io/IO.h directly in the wrapper: open the output stream once with trunc, then call the ostream overload of writeGrid for each handle cast from the nb::list. We can't simply forward to io::writeGrids because GridHandle<BufferT> is move-only (see GridHandle.h) and the nb::list holds references we must not invalidate. Tests (nanovdb/python/test/TestNanoVDB.py): - TestGridHandleExchange.test_list_to_vector now reads the written file back via readGridMetaData and readGrids and asserts the full handle count is preserved. - Added TestDeviceReadWriteGrids.test_device_write_grids_multi as a CUDA-guarded regression for deviceWriteGrids with multiple handles. Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Python binding for
nanovdb.io.writeGridsiterated the handle list and calledio::writeGrid(fileName, ...)per element. That file-level overload opens the path withstd::ios::trunc, so every iteration wiped the previously written grid and the resulting .nvdb only ever contained the last handle in the list (same story for deviceWriteGrids on the CUDA side).Mirror
io::writeGrids(fileName, handles, codec, verbose)from nanovdb/io/IO.h directly in the wrapper: open the output stream once with trunc, then call the ostream overload of writeGrid for each handle cast from the nb::list. We can't simply forward toio::writeGridsbecauseGridHandle<BufferT>is move-only and the nb::list holds references we must not invalidate.Tests (nanovdb/python/test/TestNanoVDB.py):