Skip to content

Commit

Permalink
try to fix nan issue in Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebe-p committed Aug 23, 2024
1 parent 6da41b2 commit 7887492
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/analytical_rt_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
overwrite=True,
)

angle_in = np.linspace(0, 70, 2)
angle_in = np.linspace(0, 70, 6)

n_int_R_a = np.zeros((len(angle_in), len(wl)))
n_int_T_a = np.zeros((len(angle_in), len(wl)))
Expand Down
25 changes: 8 additions & 17 deletions rayflare/matrix_formalism/multiply_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Contact: p.pearce@unsw.edu.au

import numpy as np
from sparse import load_npz, COO, stack, einsum, dot
from sparse import load_npz, COO, stack, einsum
from rayflare.angles import make_angle_vector, fold_phi, overall_bin
import os
import xarray as xr
Expand Down Expand Up @@ -162,31 +162,22 @@ def make_D(alphas, thick, thetas):
# (GitHub: arsonwong)
def dot_wl(mat, vec):

# if len(mat.shape) == 3:
# result = einsum('ijk,ik->ij', mat, COO(vec)).todense()
#
# if len(mat.shape) == 2:
# result = einsum('jk,ik->ij', mat, COO(vec)).todense()
result = np.empty((vec.shape[0], mat.shape[1]))

if len(mat.shape) == 3:
for i1 in range(vec.shape[0]): # loop over wavelengths
result[i1, :] = dot(mat[i1], vec[i1])
result = einsum('ijk,ik->ij', mat, COO(vec)).todense()

if len(mat.shape) == 2:
for i1 in range(vec.shape[0]): # loop over wavelengths
result[i1, :] = dot(mat, vec[i1])
result = einsum('jk,ik->ij', mat, COO(vec)).todense()

if np.any(np.isnan(result)):
raise ValueError("NaNs in dot_wl result")

Check warning on line 172 in rayflare/matrix_formalism/multiply_matrices.py

View check run for this annotation

Codecov / codecov/patch

rayflare/matrix_formalism/multiply_matrices.py#L172

Added line #L172 was not covered by tests

return result


def dot_wl_u2d(mat, vec):
# result = einsum('jk,ik->ij', mat, COO(vec)).todense()
result = np.empty((vec.shape[0], vec.shape[1]))
for i1 in range(vec.shape[0]): # loop over wavelengths
result[i1, :] = dot(mat, vec[i1])

result = einsum('jk,ik->ij', mat, COO(vec)).todense()
if np.any(np.isnan(result)):
raise ValueError("NaNs in dot_wl_u2d result")

Check warning on line 180 in rayflare/matrix_formalism/multiply_matrices.py

View check run for this annotation

Codecov / codecov/patch

rayflare/matrix_formalism/multiply_matrices.py#L180

Added line #L180 was not covered by tests
return result


Expand Down

0 comments on commit 7887492

Please sign in to comment.