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

Add Extend Array Function #2771

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions tardis/transport/montecarlo/packet_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
("shell_id", int64[:]),
("interaction_type", int64[:]),
("num_interactions", int64),
("extend_factor", int64),
]


Expand Down Expand Up @@ -47,6 +48,8 @@
Type of interaction the rpacket undergoes
num_interactions : int
Internal counter for the interactions that a particular RPacket undergoes
extend_factor : int
The factor by which to extend the properties array when the size limit is reached
"""

def __init__(self, length):
Expand All @@ -61,34 +64,27 @@
self.shell_id = np.empty(self.length, dtype=np.int64)
self.interaction_type = np.empty(self.length, dtype=np.int64)
self.num_interactions = 0
self.extend_factor = 2

Check warning on line 67 in tardis/transport/montecarlo/packet_trackers.py

View check run for this annotation

Codecov / codecov/patch

tardis/transport/montecarlo/packet_trackers.py#L67

Added line #L67 was not covered by tests

def extend_array(self, array, array_length):
temp_array = np.empty(

Check warning on line 70 in tardis/transport/montecarlo/packet_trackers.py

View check run for this annotation

Codecov / codecov/patch

tardis/transport/montecarlo/packet_trackers.py#L70

Added line #L70 was not covered by tests
array_length * self.extend_factor, dtype=array.dtype
)
temp_array[:array_length] = array
return temp_array

Check warning on line 74 in tardis/transport/montecarlo/packet_trackers.py

View check run for this annotation

Codecov / codecov/patch

tardis/transport/montecarlo/packet_trackers.py#L73-L74

Added lines #L73 - L74 were not covered by tests

def track(self, r_packet):
if self.num_interactions >= self.length:
temp_length = self.length * 2
temp_status = np.empty(temp_length, dtype=np.int64)
temp_r = np.empty(temp_length, dtype=np.float64)
temp_nu = np.empty(temp_length, dtype=np.float64)
temp_mu = np.empty(temp_length, dtype=np.float64)
temp_energy = np.empty(temp_length, dtype=np.float64)
temp_shell_id = np.empty(temp_length, dtype=np.int64)
temp_interaction_type = np.empty(temp_length, dtype=np.int64)

temp_status[: self.length] = self.status
temp_r[: self.length] = self.r
temp_nu[: self.length] = self.nu
temp_mu[: self.length] = self.mu
temp_energy[: self.length] = self.energy
temp_shell_id[: self.length] = self.shell_id
temp_interaction_type[: self.length] = self.interaction_type

self.status = temp_status
self.r = temp_r
self.nu = temp_nu
self.mu = temp_mu
self.energy = temp_energy
self.shell_id = temp_shell_id
self.interaction_type = temp_interaction_type
self.length = temp_length
self.status = self.extend_array(self.status, self.length)
self.r = self.extend_array(self.r, self.length)
self.nu = self.extend_array(self.nu, self.length)
self.mu = self.extend_array(self.mu, self.length)
self.energy = self.extend_array(self.energy, self.length)
self.shell_id = self.extend_array(self.shell_id, self.length)
self.interaction_type = self.extend_array(

Check warning on line 84 in tardis/transport/montecarlo/packet_trackers.py

View check run for this annotation

Codecov / codecov/patch

tardis/transport/montecarlo/packet_trackers.py#L78-L84

Added lines #L78 - L84 were not covered by tests
self.interaction_type, self.length
)
self.length = self.length * self.extend_factor

Check warning on line 87 in tardis/transport/montecarlo/packet_trackers.py

View check run for this annotation

Codecov / codecov/patch

tardis/transport/montecarlo/packet_trackers.py#L87

Added line #L87 was not covered by tests

self.index = r_packet.index
self.seed = r_packet.seed
Expand Down
Loading