Skip to content

Commit 0bf498b

Browse files
committed
Updated to recent version of dependencies, passing tests
1 parent ef97b1e commit 0bf498b

File tree

5 files changed

+48
-98
lines changed

5 files changed

+48
-98
lines changed

Cargo.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ rand = ["randlib"]
2222

2323
[dependencies]
2424
rhai = ">=1.8.0"
25-
nalgebralib = { version = "0.32.1", optional = true, package = "nalgebra" }
26-
polars = { version = "0.27.2", optional = true }
27-
url = { version = "2.2.2", optional = true }
28-
temp-file = { version = "0.1.6", optional = true }
25+
nalgebralib = { version = "0.33.2", optional = true, package = "nalgebra" }
26+
polars = { version = "0.45.1", optional = true }
27+
url = { version = ">=2.0.0", optional = true }
28+
temp-file = { version = "0.1.9", optional = true }
2929
csv-sniffer = { version = "0.3.1", optional = true }
30-
minreq = { version = "2.6.0", features = ["json-using-serde", "https"], optional = true }
31-
randlib = { version = "0.8", optional = true, package = "rand" }
32-
smartstring = "1.0.1"
30+
minreq = { version = "2.13.0", features = ["json-using-serde", "https"], optional = true }
31+
randlib = { version = "0.8.5", optional = true, package = "rand" }
32+
smartstring = ">=1.0"
3333
linregress = { version = "0.5.0", optional = true }
3434

3535
[build-dependencies]
3636
rhai = ">=1.8.0"
37-
nalgebralib = { version = "0.32.1", optional = true, package = "nalgebra" }
38-
polars = { version = "0.27.2", optional = true }
39-
url = { version = "2.2.2", optional = true }
40-
temp-file = { version = "0.1.6", optional = true }
37+
nalgebralib = { version = "0.33.2", optional = true, package = "nalgebra" }
38+
polars = { version = "0.45.1", optional = true }
39+
url = { version = ">=2.0.0", optional = true }
40+
temp-file = { version = "0.1.9", optional = true }
4141
csv-sniffer = { version = "0.3.1", optional = true }
42-
minreq = { version = "2.6.0", features = ["json-using-serde", "https"], optional = true }
43-
randlib = { version = "0.8", optional = true, package = "rand" }
44-
serde_json = "1.0.82"
45-
serde = "1.0.140"
46-
smartstring = "1.0.1"
47-
linregress = { version = "0.5.0", optional = true }
42+
minreq = { version = "2.13.0", features = ["json-using-serde", "https"], optional = true }
43+
randlib = { version = "0.8.5", optional = true, package = "rand" }
44+
serde_json = ">=1.0.0"
45+
serde = ">=1.0.0"
46+
smartstring = ">=1.0.0"
47+
linregress = { version = "0.5.4", optional = true }
4848

4949
[package.metadata.docs.rs]
5050
all-features = true

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
# About `rhai-sci`
66

7-
This crate provides some basic scientific computing utilities for the [`Rhai`](https://rhai.rs/) scripting language, inspired by languages
7+
This crate provides some basic scientific computing utilities for the [`Rhai`](https://rhai.rs/) scripting language,
8+
inspired by languages
89
like MATLAB, Octave, and R. For a complete API reference, check [the docs](https://docs.rs/rhai-sci).
910

1011
# Install
@@ -15,15 +16,10 @@ To use the latest released version of `rhai-sci`, add this to your `Cargo.toml`:
1516
rhai-sci = "0.2.1"
1617
```
1718

18-
To use the bleeding edge instead, add this:
19-
20-
```toml
21-
rhai-sci = { git = "https://github.com/cmccomb/rhai-sci" }
22-
```
23-
2419
# Usage
2520

26-
Using this crate is pretty simple! If you just want to evaluate a single line of [`Rhai`](https://rhai.rs/), then you only need:
21+
Using this crate is pretty simple! If you just want to evaluate a single line of [`Rhai`](https://rhai.rs/), then you
22+
only need:
2723

2824
```rust
2925
use rhai::INT;
@@ -49,9 +45,9 @@ let value = engine.eval::<INT>("argmin([43, 42, -500])").unwrap();
4945

5046
# Features
5147

52-
| Feature | Default | Description |
53-
| ----------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54-
| `metadata` | Disabled | Enables exporting function metadata and is ___necessary for running doc-tests on Rhai examples___. |
55-
| `io` | Enabled | Enables the [`read_matrix`](#read_matrixfile_path-string---array) function but pulls in several additional dependencies (`polars`, `url`, `temp-file`, `csv-sniffer`, `minreq`). |
56-
| `nalgebra` | Enabled | Enables several functions ([`regress`](#regressx-array-y-array---map), [`inv`](#invmatrix-array---array), [`mtimes`](#mtimesmatrix1-array-matrix2-array---array), [`horzcat`](#horzcatmatrix1-array-matrix2-array---array), [`vertcat`](#vertcatmatrix1-array-matrix2-array---array), [`repmat`](#repmatmatrix-array-nx-i64-ny-i64---array), [`svd`](#svdmatrix-array---map), [`hessenberg`](#hessenbergmatrix-array---map), and [`qr`](#qrmatrix-array---map)) but brings in the `nalgebra` and `linregress` crates. |
57-
| `rand` | Enabled | Enables the [`rand`](#rand) function for generating random FLOAT values and random matrices, but brings in the `rand` crate. |
48+
| Feature | Default | Description |
49+
|------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
50+
| `metadata` | Disabled | Enables exporting function metadata and is ___necessary for running doc-tests on Rhai examples___. |
51+
| `io` | Enabled | Enables the [`read_matrix`](#read_matrixfile_path-string---array) function but pulls in several additional dependencies (`polars`, `url`, `temp-file`, `csv-sniffer`, `minreq`). |
52+
| `nalgebra` | Enabled | Enables several functions ([`regress`](#regressx-array-y-array---map), [`inv`](#invmatrix-array---array), [`mtimes`](#mtimesmatrix1-array-matrix2-array---array), [`horzcat`](#horzcatmatrix1-array-matrix2-array---array), [`vertcat`](#vertcatmatrix1-array-matrix2-array---array), [`repmat`](#repmatmatrix-array-nx-i64-ny-i64---array), [`svd`](#svdmatrix-array---map), [`hessenberg`](#hessenbergmatrix-array---map), and [`qr`](#qrmatrix-array---map)) but brings in the `nalgebra` and `linregress` crates. |
53+
| `rand` | Enabled | Enables the [`rand`](#rand) function for generating random FLOAT values and random matrices, but brings in the `rand` crate. |

src/matrices_and_arrays.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub mod matrix_functions {
378378

379379
#[cfg(all(feature = "io"))]
380380
pub mod read_write {
381-
use polars::prelude::{CsvReader, DataType, SerReader};
381+
use polars::prelude::{CsvReadOptions, DataType, SerReader};
382382
use rhai::{Array, Dynamic, EvalAltResult, ImmutableString, FLOAT};
383383

384384
/// Reads a numeric csv file from a url
@@ -406,11 +406,13 @@ pub mod matrix_functions {
406406

407407
let file_path_as_str = file_path.as_str();
408408

409-
match CsvReader::from_path(file_path_as_str) {
410-
Ok(csv) => {
411-
let x = csv
412-
.infer_schema(Some(10))
413-
.has_header(
409+
// Determine path is url
410+
let path_is_url = url::Url::parse(file_path_as_str);
411+
412+
match path_is_url {
413+
Err(_) => {
414+
let x = CsvReadOptions::default()
415+
.with_has_header(
414416
csv_sniffer::Sniffer::new()
415417
.sniff_path(file_path_as_str)
416418
.map_err(|err| {
@@ -423,14 +425,21 @@ pub mod matrix_functions {
423425
.header
424426
.has_header_row,
425427
)
426-
.finish()
428+
.try_into_reader_with_file_path(Some(file_path_as_str.into()))
427429
.map_err(|err| {
428430
EvalAltResult::ErrorSystem(
429431
format!("Cannot read file as CSV: {file_path_as_str}"),
430432
err.into(),
431433
)
432434
})?
433-
.drop_nulls(None)
435+
.finish()
436+
.map_err(|err| {
437+
EvalAltResult::ErrorSystem(
438+
format!("Cannot read file: {file_path_as_str}"),
439+
err.into(),
440+
)
441+
})?
442+
.drop_nulls::<String>(None)
434443
.map_err(|err| {
435444
EvalAltResult::ErrorSystem(
436445
format!("Cannot remove null values from file: {file_path_as_str}"),
@@ -439,7 +448,6 @@ pub mod matrix_functions {
439448
})?;
440449

441450
// Convert into vec of vec
442-
443451
let mut final_output = vec![];
444452
for series in x.get_columns() {
445453
let col: Vec<FLOAT> = series
@@ -473,7 +481,7 @@ pub mod matrix_functions {
473481

474482
Ok(matrix_as_array)
475483
}
476-
Err(_) => {
484+
Ok(_) => {
477485
if let Ok(_) = url::Url::parse(file_path_as_str) {
478486
let file_contents =
479487
minreq::get(file_path_as_str).send().map_err(|err| {

src/patterns.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
use rhai::{Array, Dynamic, EvalAltResult, Position, FLOAT, INT};
2-
#[cfg(feature = "smartcore")]
3-
use smartcorelib::linalg::basic::{
4-
arrays::Array as scArray, arrays::Array2 as scArray2, matrix::DenseMatrix,
5-
};
62

73
/// Matrix compatibility conditions
84
#[allow(dead_code)]
@@ -208,42 +204,6 @@ where
208204
}
209205
}
210206

211-
#[cfg(feature = "smartcore")]
212-
pub fn if_matrix_convert_to_dense_matrix_and_do<F, T>(
213-
matrix: &mut Array,
214-
mut f: F,
215-
) -> Result<T, Box<EvalAltResult>>
216-
where
217-
F: FnMut(DenseMatrix<FLOAT>) -> Result<T, Box<EvalAltResult>>,
218-
{
219-
if crate::validation_functions::is_matrix(matrix) {
220-
let matrix_as_vec = matrix
221-
.clone()
222-
.iter()
223-
.map(|x| {
224-
x.clone()
225-
.into_array()
226-
.unwrap()
227-
.iter()
228-
.map(|y| {
229-
if y.is::<FLOAT>() {
230-
y.clone().as_float().unwrap()
231-
} else {
232-
y.clone().as_int().unwrap() as FLOAT
233-
}
234-
})
235-
.collect::<Vec<FLOAT>>()
236-
})
237-
.collect::<Vec<Vec<FLOAT>>>();
238-
f(DenseMatrix::from_2d_vec(&matrix_as_vec))
239-
} else {
240-
Err(
241-
EvalAltResult::ErrorArithmetic(format!("The input must be a matrix."), Position::NONE)
242-
.into(),
243-
)
244-
}
245-
}
246-
247207
pub fn if_int_do_else_if_array_do<FA, FB, T>(
248208
d: Dynamic,
249209
mut f_int: FA,
@@ -272,20 +232,6 @@ pub fn array_to_vec_int(arr: &mut Array) -> Vec<INT> {
272232
.collect::<Vec<INT>>()
273233
}
274234

275-
#[cfg(feature = "smartcore")]
276-
pub fn dense_matrix_to_vec_dynamic(dm: DenseMatrix<FLOAT>) -> Vec<Dynamic> {
277-
let mut output = vec![];
278-
for idx in 0..dm.shape().0 {
279-
output.push(Dynamic::from_array(
280-
dm.get_row(idx)
281-
.iterator(0)
282-
.map(|x| Dynamic::from_float(x.clone()))
283-
.collect::<Vec<Dynamic>>(),
284-
));
285-
}
286-
output
287-
}
288-
289235
pub fn array_to_vec_float(arr: &mut Array) -> Vec<FLOAT> {
290236
arr.into_iter()
291237
.map(|el| el.as_float().unwrap())

src/statistics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,9 @@ pub mod stats {
542542
/// [0.8],
543543
/// [2.1]];
544544
/// let b = regress(x, y);
545-
/// assert_eq(b, #{"parameters": [5.551115123125783e-16, 1.0000000000000002],
546-
/// "pvalues": [1.0, 0.1091825535092476],
547-
/// "standard_errors": [0.1118033988749896, 0.17320508075688787]});
545+
/// assert_eq(b, #{"parameters": [-2.220446049250313e-16, 1.0000000000000002],
546+
/// "pvalues": [1.0, 0.10918255350924745],
547+
/// "standard_errors": [0.11180339887498947, 0.17320508075688767]});
548548
/// ```
549549
#[cfg(feature = "nalgebra")]
550550
#[rhai_fn(name = "regress", return_raw, pure)]

0 commit comments

Comments
 (0)