Skip to content

Commit

Permalink
Refactored safe solve
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspellegrinelli committed Jun 25, 2024
1 parent 9f4d5ae commit 2b6dd58
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/gleastsq/internal/nx.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ pub fn norm(a: NxTensor) -> NxTensor
pub fn unsafe_solve(a: NxTensor, b: NxTensor) -> NxTensor

pub fn solve(a: NxTensor, b: NxTensor) -> Result(NxTensor, String) {
case exception.rescue(fn() { unsafe_solve(a, b) }) {
Ok(r) -> Ok(r)
Error(exception.Errored(e)) -> {
use error <- result.map_error(exception.rescue(fn() { unsafe_solve(a, b) }))
case error {
exception.Errored(e) -> {
let error_msg = e |> dynamic.field(named: Message, of: dynamic.string)
Error(result.unwrap(error_msg, "Error solving matrix"))
result.unwrap(error_msg, "Error solving matrix")
}
_ -> panic as "Unexpected error while solving matrix"
}
Expand Down

0 comments on commit 2b6dd58

Please sign in to comment.