Skip to content
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

Optimize memory usage in empirical_cross_covariance calculation #214

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

dafeda
Copy link
Collaborator

@dafeda dafeda commented Mar 7, 2024

Resolves: #213

If X is a large matrix, it might be stored as a float32 array to save memory. However, if Y is of type float64,
the resulting cross-covariance matrix will be float64, potentially doubling the memory usage even if X is float32. To prevent unnecessary memory consumption,
we cast Y to the same data type as X before computing the dot product. This ensures that the output cross-covariance matrix uses memory efficiently while retaining the precision dictated by X's data type.

If X is a large matrix, it might be stored as a float32 array to save memory.
However, if Y is of type float64,
the resulting cross-covariance matrix will be float64,
potentially doubling the memory usage even if X is float32.
To prevent unnecessary memory consumption,
we cast Y to the same data type as X before computing the dot product.
This ensures that the output cross-covariance matrix uses memory efficiently
while retaining the precision dictated by X's data type.
@dafeda dafeda requested review from tommyod and removed request for tommyod March 7, 2024 11:26
Copy link
Collaborator

@tommyod tommyod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Only comment is that you could generalize and convert to the "lowest" type: if either X or Y is float32, then convert the other. But I guess X being float32 is the realistic case.

@dafeda dafeda merged commit d19e2b3 into equinor:main Mar 7, 2024
10 checks passed
@dafeda dafeda deleted the cov-float32 branch March 7, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure empirical cross covariance contains 32-bit values if X is a 32-bit float array
2 participants