Skip to content

Math implementation with statrs #207

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ serde_derive = "1.0.66"
serde_json = "1.0.26"
byteorder = "1.2.6"
regex = "1"
statrs = "0.10.0"
1 change: 1 addition & 0 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern crate num_complex;
extern crate num_traits;
extern crate serde;
extern crate serde_json;
extern crate statrs;

extern crate rustpython_parser;

Expand Down
14 changes: 6 additions & 8 deletions vm/src/stdlib/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use super::super::pyobject::{
DictProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol,
};
use super::super::VirtualMachine;
use statrs::function::erf::{erf, erfc};
use statrs::function::gamma::{gamma, ln_gamma};
use std;

// Helper macro:
Expand Down Expand Up @@ -156,8 +158,7 @@ fn math_erf(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
if x.is_nan() {
Ok(vm.ctx.new_float(x))
} else {
// TODO: implement algorithm
unimplemented!("TODO");
Ok(vm.ctx.new_float(erf(x)))
}
}

Expand All @@ -168,8 +169,7 @@ fn math_erfc(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
if x.is_nan() {
Ok(vm.ctx.new_float(x))
} else {
// TODO: implement algorithm
unimplemented!("TODO");
Ok(vm.ctx.new_float(erfc(x)))
}
}

Expand All @@ -178,8 +178,7 @@ fn math_gamma(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let x = objfloat::get_value(value);

if x.is_finite() {
// TODO: implement algorithm
unimplemented!("TODO");
Ok(vm.ctx.new_float(gamma(x)))
} else {
if x.is_nan() || x.is_sign_positive() {
Ok(vm.ctx.new_float(x))
Expand All @@ -194,8 +193,7 @@ fn math_lgamma(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let x = objfloat::get_value(value);

if x.is_finite() {
// TODO: implement algorithm
unimplemented!("TODO");
Ok(vm.ctx.new_float(ln_gamma(x)))
} else {
if x.is_nan() {
Ok(vm.ctx.new_float(x))
Expand Down