Skip to content

Commit 1b4b157

Browse files
Merge pull request RustPython#207 from yodalee/math-implementation-with-statrs
Math implementation with statrs
2 parents ee2fb20 + 68892fb commit 1b4b157

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

vm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ serde_derive = "1.0.66"
1515
serde_json = "1.0.26"
1616
byteorder = "1.2.6"
1717
regex = "1"
18+
statrs = "0.10.0"

vm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern crate num_complex;
1515
extern crate num_traits;
1616
extern crate serde;
1717
extern crate serde_json;
18+
extern crate statrs;
1819

1920
extern crate rustpython_parser;
2021

vm/src/stdlib/math.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use super::super::pyobject::{
88
DictProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol,
99
};
1010
use super::super::VirtualMachine;
11+
use statrs::function::erf::{erf, erfc};
12+
use statrs::function::gamma::{gamma, ln_gamma};
1113
use std;
1214

1315
// Helper macro:
@@ -156,8 +158,7 @@ fn math_erf(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
156158
if x.is_nan() {
157159
Ok(vm.ctx.new_float(x))
158160
} else {
159-
// TODO: implement algorithm
160-
unimplemented!("TODO");
161+
Ok(vm.ctx.new_float(erf(x)))
161162
}
162163
}
163164

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

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

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

196195
if x.is_finite() {
197-
// TODO: implement algorithm
198-
unimplemented!("TODO");
196+
Ok(vm.ctx.new_float(ln_gamma(x)))
199197
} else {
200198
if x.is_nan() {
201199
Ok(vm.ctx.new_float(x))

0 commit comments

Comments
 (0)