-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
equistore.contiguous
operation, making all the data contiguous
#265
Comments
Could you give a bit more explanation on the function signature and in which way it is contiguous? Does it return an array |
My idea was more to apply
|
Stumbled across this issue and thought I'd share a function I already use in my code - might be helpful as a starting point for anyone that wants to take on this #goodfirstissue ! def make_contiguous_numpy(tensor: TensorMap) -> TensorMap:
"""
Takes a TensorMap of numpy backend and makes the ndarray block and
gradient values contiguous in memory.
"""
new_blocks = []
for key, block in tensor.items():
new_block = TensorBlock(
values=np.ascontiguousarray(block.values),
samples=block.samples,
components=block.components,
properties=block.properties,
)
for parameter, gradient in block.gradients():
new_gradient = TensorBlock(
values=np.ascontiguousarray(gradient.values),
samples=gradient.samples,
components=gradient.components,
properties=gradient.properties,
)
new_block.add_gradient(parameter, new_gradient)
new_blocks.append(new_block)
return TensorMap(
keys=tensor.keys,
blocks=new_blocks,
) Note: the above does not handle second derivatives (gradients of gradients). |
We should have an operation to transform all data inside equistore into contiguous arrays. This is required in particular if one wants to use
equistore.save
, which only support contiguous arrays.The text was updated successfully, but these errors were encountered: