[REQ] Storing a sparse matrix in a warp struct
Description
I'm trying to create a warp struct that holds a sparse matrix:
@wp.struct
class NeohookeanElasticMaterial:
sparse_hessian: wps.bsr_matrix_t(dtype=wp.types.matrix(shape=(9,9), dtype=wp.float32))
Context
Setting the sparse matrix shape during construction as follows;
neohookean_struct = NeohookeanElasticMaterial()
neohookean_struct.sparse_hessian = wps.bsr_zeros(
N, N, block_type=wp.types.matrix(shape=(9, 9), dtype=wp.float32), device=device)
And finally setting its values within the hessian function as:
wps.bsr_set_diag(neohookean_struct.sparse_hessian,hessian_blocks)
I get an error saying:
AttributeError: 'StructInstance' object has no attribute 'copy_nnz_async'
@gdaviet added a fix for this in 87e843b544f715116c275681c1c39457f483e95c
Previously creating a struct instance with the call operator would inherit the attributes from the Python base class, but this was not the case for instances crated as nested attributes of a parent struct. This fixes this discrepancy, and in particular allows the use of wp.sparse.BsrMatrix helper properties on nested attributes.
Please give it a try by building Warp from source or installing a nightly build. It will be included in Warp 1.8.0.