-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Atharva Arya
committed
Dec 25, 2024
1 parent
836fe69
commit 1a7dbc0
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
tardis/transport/montecarlo/estimators/j_blue_estimator.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
from numba import float64 | ||
from numba.experimental import jitclass | ||
|
||
def initialize_j_blue_estimator(tau_sobolev_shape): | ||
|
||
j_blue_estimator = np.zeros(tau_sobolev_shape) | ||
return JBlueEstimator(j_blue_estimator) | ||
|
||
@jitclass([ | ||
("j_blue_estimator", float64[:, :]), | ||
]) | ||
class JBlueEstimator: | ||
def __init__(self, j_blue_estimator): | ||
self.j_blue_estimator = j_blue_estimator | ||
|
||
def increment(self, other): | ||
|
||
self.j_blue_estimator += other.j_blue_estimator | ||
|
||
if __name__ == "__main__": | ||
# Create a small example with 3x3 shape | ||
test_estimator = initialize_j_blue_estimator((3, 3)) | ||
print("Initial j_blue_estimator:") | ||
print(test_estimator.j_blue_estimator) | ||
|
||
# Create another estimator and modify it to show increment | ||
other_estimator = initialize_j_blue_estimator((3, 3)) | ||
other_estimator.j_blue_estimator[0, 0] = 1.0 | ||
other_estimator.j_blue_estimator[1, 1] = 2.0 | ||
|
||
# Increment the first estimator with the second one | ||
test_estimator.increment(other_estimator) | ||
print("\nAfter incrementing with another estimator:") | ||
print(test_estimator.j_blue_estimator) | ||
|
||
# Save the estimator to a .npy file | ||
output_file = "j_blue_estimator.npy" | ||
np.save(output_file, test_estimator.j_blue_estimator) | ||
print(f"\nSaved estimator to {output_file}") |