Skip to content

Commit c2f9ca1

Browse files
committed
Build against pyo3 0.5
We were building against an alpha version of 0.5.0, but the API changed in the meanwhile.
1 parent b094386 commit c2f9ca1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "finalfrontier"
88
crate-type = ["cdylib"]
99

1010
[dependencies.pyo3]
11-
version = "0.5.0-alpha.1"
11+
version = "0.5"
1212
features = ["extension-module"]
1313

1414
[dependencies]

src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use failure::Error;
1313
use finalfrontier::similarity::{Analogy, Similarity};
1414
use finalfrontier::{MmapModelBinary, Model, ReadModelBinary};
1515
use ndarray::Axis;
16+
use pyo3::class::{basic::PyObjectProtocol, iter::PyIterProtocol};
17+
use pyo3::exceptions;
1618
use pyo3::prelude::*;
1719

1820
/// This is a binding for finalfrontier.
@@ -78,7 +80,7 @@ impl PyModel {
7880
let model = match load_model(path, mmap) {
7981
Ok(model) => Rc::new(model),
8082
Err(err) => {
81-
return Err(exc::IOError::py_err(err.to_string()));
83+
return Err(exceptions::IOError::py_err(err.to_string()));
8284
}
8385
};
8486

@@ -100,7 +102,7 @@ impl PyModel {
100102
) -> PyResult<Vec<PyObject>> {
101103
let results = match self.model.analogy(word1, word2, word3, limit) {
102104
Some(results) => results,
103-
None => return Err(exc::KeyError::py_err("Unknown word and n-grams")),
105+
None => return Err(exceptions::KeyError::py_err("Unknown word and n-grams")),
104106
};
105107

106108
let mut r = Vec::with_capacity(results.len());
@@ -110,7 +112,8 @@ impl PyModel {
110112
word: ws.word.to_owned(),
111113
similarity: ws.similarity.into_inner(),
112114
token,
113-
})?.into_object(py),
115+
})?
116+
.into_object(py),
114117
)
115118
}
116119

@@ -124,7 +127,7 @@ impl PyModel {
124127
fn embedding(&self, word: &str) -> PyResult<Vec<f32>> {
125128
match self.model.embedding(word) {
126129
Some(embedding) => Ok(embedding.to_vec()),
127-
None => Err(exc::KeyError::py_err("Unknown word and n-grams")),
130+
None => Err(exceptions::KeyError::py_err("Unknown word and n-grams")),
128131
}
129132
}
130133

@@ -133,7 +136,7 @@ impl PyModel {
133136
fn similarity(&self, py: Python, word: &str, limit: usize) -> PyResult<Vec<PyObject>> {
134137
let results = match self.model.similarity(word, limit) {
135138
Some(results) => results,
136-
None => return Err(exc::KeyError::py_err("Unknown word and n-grams")),
139+
None => return Err(exceptions::KeyError::py_err("Unknown word and n-grams")),
137140
};
138141

139142
let mut r = Vec::with_capacity(results.len());
@@ -143,7 +146,8 @@ impl PyModel {
143146
word: ws.word.to_owned(),
144147
similarity: ws.similarity.into_inner(),
145148
token,
146-
})?.into_object(py),
149+
})?
150+
.into_object(py),
147151
)
148152
}
149153

@@ -160,7 +164,8 @@ impl PyIterProtocol for PyModel {
160164
model: self.model.clone(),
161165
idx: 0,
162166
token,
163-
})?.into_object(py);
167+
})?
168+
.into_object(py);
164169

165170
Ok(iter)
166171
}

0 commit comments

Comments
 (0)