Skip to content

Fix various rustc and clippy warnings. #62

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 1 commit into from
Mar 4, 2017
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
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<T: TensorType> Deref for Buffer<T> {

impl<T: TensorType> DerefMut for Buffer<T> {
#[inline]
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] {
fn deref_mut(&mut self) -> &mut [T] {
self.as_mut()
}
}
Expand Down
44 changes: 20 additions & 24 deletions src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate libc;
extern crate tensorflow_sys as tf;

use libc::c_float;
Expand Down Expand Up @@ -144,9 +143,9 @@ impl Graph {
}

/// Iterates over the operations in the graph.
pub fn operation_iter<'a>(&'a self) -> OperationIter<'a> {
pub fn operation_iter(&self) -> OperationIter {
OperationIter {
graph: &self,
graph: self,
pos: 0,
}
}
Expand Down Expand Up @@ -492,9 +491,6 @@ impl<'a> Input<'a> {

////////////////////////

#[deprecated(note="Use Output instead.")]
type Port<'a> = Output<'a>;

/// A `Output` is one end of a graph edge.
/// It holds an operation and an index into the outputs of that operation.
#[derive(Debug,Copy,Clone)]
Expand Down Expand Up @@ -756,13 +752,13 @@ impl<'a> OperationDescription<'a> {
-> std::result::Result<(), NulError> {
let c_attr_name = try!(CString::new(attr_name));
unsafe {
match &value.0 {
&None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1),
&Some(ref dims) => {
match value.0 {
None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1),
Some(ref dims) => {
let c_dims: Vec<i64> = dims.iter()
.map(|x| match x {
&Some(d) => d,
&None => -1,
.map(|x| match *x {
Some(d) => d,
None => -1,
})
.collect();
tf::TF_SetAttrShape(self.inner,
Expand All @@ -783,28 +779,28 @@ impl<'a> OperationDescription<'a> {
let c_attr_name = try!(CString::new(attr_name));
// Convert Option<i64> in each shape to i64 with None becoming -1.
let c_dims: Vec<Option<Vec<i64>>> = value.iter()
.map(|x| match &x.0 {
&None => None,
&Some(ref dims) => {
.map(|x| match x.0 {
None => None,
Some(ref dims) => {
Some(dims.iter()
.map(|x| match x {
&None => -1,
&Some(d) => d,
.map(|x| match *x {
None => -1,
Some(d) => d,
})
.collect())
}
})
.collect();
let ptrs: Vec<*const i64> = c_dims.iter()
.map(|x| match x {
&None => ptr::null(),
&Some(ref dims) => dims.as_ptr(),
.map(|x| match *x {
None => ptr::null(),
Some(ref dims) => dims.as_ptr(),
})
.collect();
let lens: Vec<c_int> = value.iter()
.map(|x| match &x.0 {
&None => -1,
&Some(ref dims) => dims.len() as c_int,
.map(|x| match x.0 {
None => -1,
Some(ref dims) => dims.len() as c_int,
})
.collect();
unsafe {
Expand Down
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This crate provides Rust bindings for the
//! [TensorFlow](https://www.tensorflow.org) machine learning library.
//! [`TensorFlow`](https://www.tensorflow.org) machine learning library.

#![warn(missing_copy_implementations,
missing_debug_implementations,
Expand Down Expand Up @@ -343,6 +343,7 @@ c_enum!("Type of a single tensor element.", TF_DataType, DataType {
/// 16-bit floating point.
value Half = 19,

/// TensorFlow Resource (name, container, device,...)
value Resource = 20,
});

Expand Down Expand Up @@ -936,7 +937,7 @@ impl<T: TensorType> Deref for Tensor<T> {

impl<T: TensorType> DerefMut for Tensor<T> {
#[inline]
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] {
fn deref_mut(&mut self) -> &mut [T] {
&mut self.data
}
}
Expand Down Expand Up @@ -1010,7 +1011,7 @@ trait OperationTrait {
////////////////////////

/// Returns a string describing version information of the
/// TensorFlow library. TensorFlow using semantic versioning.
/// `TensorFlow` library. `TensorFlow` is using semantic versioning.
pub fn version() -> std::result::Result<String, Utf8Error> {
unsafe { CStr::from_ptr(tf::TF_Version()).to_str().map(|s| s.to_string()) }
}
Expand All @@ -1028,9 +1029,9 @@ pub struct Shape(Option<Vec<Option<i64>>>);
impl Shape {
/// Returns the number of dimensions if known, or None if unknown.
pub fn dims(&self) -> Option<usize> {
match self {
&Shape(None) => None,
&Shape(Some(ref v)) => Some(v.len()),
match *self {
Shape(None) => None,
Shape(Some(ref v)) => Some(v.len()),
}
}
}
Expand All @@ -1053,9 +1054,9 @@ impl Index<usize> for Shape {
type Output = Option<i64>;

fn index(&self, index: usize) -> &Option<i64> {
match &self.0 {
&None => &UNKNOWN_DIMENSION,
&Some(ref v) => {
match self.0 {
None => &UNKNOWN_DIMENSION,
Some(ref v) => {
if index < v.len() {
&v[index]
} else {
Expand Down
7 changes: 1 addition & 6 deletions src/session.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate tensorflow_sys as tf;

use tf;
use libc::c_int;
use std::marker;
use std::ptr;
Expand All @@ -21,9 +20,6 @@ pub struct Session {
inner: *mut tf::TF_Session,
}

#[deprecated(note = "Use Session instead.")]
type SessionWithGraph = Session;

impl Session {
/// Creates a session.
pub fn new(options: &SessionOptions, graph: &Graph) -> Result<Self> {
Expand Down Expand Up @@ -236,7 +232,6 @@ impl<'l> Drop for StepWithGraph<'l> {

#[cfg(test)]
mod tests {
extern crate tensorflow_sys as tf;
use super::*;
use super::super::DataType;
use super::super::Graph;
Expand Down