Skip to content

Commit

Permalink
Apply clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elftausend committed Jan 29, 2024
1 parent 56187f0 commit efa548a
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 72 deletions.
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ fn has_device_unified_mem() -> bool {
.unified_mem
}

use std::path::{Path, PathBuf};

// https://github.com/coreylowman/cudarc/blob/main/build.rs
#[cfg(feature = "cuda")]
fn link_cuda() {
Expand Down
18 changes: 8 additions & 10 deletions src/buffer/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ impl Device for () {
}

#[inline(always)]
fn data_as_wrap<'a, T, S: crate::Shape>(
data: &'a Self::Data<T, S>,
) -> &'a Self::Wrap<T, Self::Base<T, S>> {
fn data_as_wrap<T, S: crate::Shape>(
data: &Self::Data<T, S>,
) -> &Self::Wrap<T, Self::Base<T, S>> {
data
}

fn data_as_wrap_mut<'a, T, S: crate::Shape>(
data: &'a mut Self::Data<T, S>,
) -> &'a mut Self::Wrap<T, Self::Base<T, S>> {
fn data_as_wrap_mut<T, S: crate::Shape>(
data: &mut Self::Data<T, S>,
) -> &mut Self::Wrap<T, Self::Base<T, S>> {
data
}
}
Expand Down Expand Up @@ -118,14 +118,12 @@ impl WrappedData for () {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
wrap
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
wrap
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ pub trait Device: OnDropBuffer + Sized {
// FIXME: probably a better way to realize these
fn base_to_data<T, S: Shape>(&self, base: Self::Base<T, S>) -> Self::Data<T, S>;
fn wrap_to_data<T, S: Shape>(&self, wrap: Self::Wrap<T, Self::Base<T, S>>) -> Self::Data<T, S>;
fn data_as_wrap<'a, T, S: Shape>(
data: &'a Self::Data<T, S>,
) -> &'a Self::Wrap<T, Self::Base<T, S>>;
fn data_as_wrap_mut<'a, T, S: Shape>(
data: &'a mut Self::Data<T, S>,
) -> &'a mut Self::Wrap<T, Self::Base<T, S>>;
fn data_as_wrap<T, S: Shape>(data: &Self::Data<T, S>) -> &Self::Wrap<T, Self::Base<T, S>>;
fn data_as_wrap_mut<T, S: Shape>(
data: &mut Self::Data<T, S>,
) -> &mut Self::Wrap<T, Self::Base<T, S>>;

/// Creates a new [`Buffer`] using `A`.
///
Expand Down Expand Up @@ -111,7 +109,7 @@ macro_rules! impl_device_traits {
$crate::impl_wrapped_data!($device);

#[cfg(feature = "graph")]
crate::pass_down_optimize_mem_graph!($device);
$crate::pass_down_optimize_mem_graph!($device);

$crate::pass_down_grad_fn!($device);
$crate::pass_down_tape_actions!($device);
Expand Down
10 changes: 4 additions & 6 deletions src/devices/cpu/cpu_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ impl<Mods: OnDropBuffer> Device for CPU<Mods> {
}

#[inline(always)]
fn data_as_wrap<'a, T, S: Shape>(
data: &'a Self::Data<T, S>,
) -> &'a Self::Wrap<T, Self::Base<T, S>> {
fn data_as_wrap<T, S: Shape>(data: &Self::Data<T, S>) -> &Self::Wrap<T, Self::Base<T, S>> {
data
}

#[inline(always)]
fn data_as_wrap_mut<'a, T, S: Shape>(
data: &'a mut Self::Data<T, S>,
) -> &'a mut Self::Wrap<T, Self::Base<T, S>> {
fn data_as_wrap_mut<T, S: Shape>(
data: &mut Self::Data<T, S>,
) -> &mut Self::Wrap<T, Self::Base<T, S>> {
data
}

Expand Down
1 change: 0 additions & 1 deletion src/devices/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ mod cpu_ptr;
mod ops;

pub use cpu_ptr::*;
pub use ops::*;
6 changes: 3 additions & 3 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ macro_rules! pass_down_grad_fn {
fn add_grad_fn<Args: $crate::Parents<N> + $crate::UpdateArgs, const N: usize>(
&self,
args: Args,
op: fn(&mut Args) -> crate::Result<()>,
op: fn(&mut Args) -> $crate::Result<()>,
) {
self.modules.add_grad_fn(args, op)
}
Expand Down Expand Up @@ -236,7 +236,7 @@ macro_rules! pass_down_add_operation {
fn add_op<Args: $crate::Parents<N> + $crate::UpdateArgs, const N: usize>(
&self,
args: Args,
operation: fn(&mut Args) -> crate::Result<()>,
operation: fn(&mut Args) -> $crate::Result<()>,
) -> $crate::Result<()> {
self.modules.add_op(args, operation)
}
Expand Down Expand Up @@ -388,7 +388,7 @@ macro_rules! pass_down_optimize_mem_graph {
fn optimize_mem_graph(
&self,
cache_traces: Option<&[$crate::TranslatedCacheTrace]>,
) -> crate::Result<()> {
) -> $crate::Result<()> {
self.modules.optimize_mem_graph(cache_traces)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<T> UpdateArg for NoId<T> {
#[inline]
#[cfg(not(feature = "no-std"))]
fn update_arg(
to_update: &mut Self,
_to_update: &mut Self,
_id: Option<UniqueId>,
_buffers: &mut std::collections::HashMap<
crate::UniqueId,
Expand Down
6 changes: 2 additions & 4 deletions src/modules/autograd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ impl<Mods: WrappedData> WrappedData for Autograd<Mods> {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
Mods::wrapped_as_base(wrap)
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
Mods::wrapped_as_base_mut(wrap)
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/modules/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ impl WrappedData for Base {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
wrap
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
wrap
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/modules/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ impl<Mods: WrappedData, SD: Device> WrappedData for CachedModule<Mods, SD> {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
Mods::wrapped_as_base(wrap)
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
Mods::wrapped_as_base_mut(wrap)
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/modules/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ impl<Mods: WrappedData> WrappedData for Fork<Mods> {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
Mods::wrapped_as_base(wrap)
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
Mods::wrapped_as_base_mut(wrap)
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/modules/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ impl<Mods: WrappedData> WrappedData for Graph<Mods> {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
Mods::wrapped_as_base(wrap)
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
Mods::wrapped_as_base_mut(wrap)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/modules/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ impl<Mods: AddOperation> AddOperation for Lazy<Mods> {
args: Args,
operation: fn(&mut Args) -> crate::Result<()>,
) -> crate::Result<()> {
Ok(self.graph.try_borrow_mut()
.expect("already borrowed: BorrowMutError - is the inner operation trying to add an operation as well?")
.add_operation(args, operation))
self.graph.try_borrow_mut()
.expect("already borrowed: BorrowMutError - is the inner operation trying to add an operation as well?")
.add_operation(args, operation);
Ok(())
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/modules/lazy/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ impl<Mods: WrappedData> WrappedData for Lazy<Mods> {
}

#[inline]
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base {
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base {
Mods::wrapped_as_base(wrap.data.as_ref().expect(MISSING_DATA))
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base {
Mods::wrapped_as_base_mut(wrap.data.as_mut().expect(MISSING_DATA))
}
}
Expand Down Expand Up @@ -71,7 +69,7 @@ impl<Data: PtrType, T> PtrType for LazyWrapper<Data, T> {
}
}

const MISSING_DATA: &'static str =
const MISSING_DATA: &str =
"This lazy buffer does not contain any data. Try with a buffer.replace() call.";

impl<Data: Deref<Target = [T]>, T> Deref for LazyWrapper<Data, T> {
Expand Down
1 change: 0 additions & 1 deletion src/static_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod macros;
mod static_devices;
mod to_device;

pub use macros::*;
pub use static_devices::*;

use crate::Device;
Expand Down
3 changes: 0 additions & 3 deletions src/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use crate::{
AddGradFn, Alloc, AsNoId, Buffer, Device, Eval, MayTapeActions, MayToCLSource, Resolve, Shape,
};

#[cfg(feature = "autograd")]
use crate::HasId;

/// Applies a function to a buffer and returns a new buffer.
pub trait ApplyFunction<T, S: Shape = (), D: Device = Self>: Device {
/// Applies a function to a buffer and returns a new buffer.
Expand Down
18 changes: 8 additions & 10 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ pub trait WrappedData {
type Wrap<T, Base: HasId + PtrType>: HasId + PtrType;

fn wrap_in_base<T, Base: HasId + PtrType>(&self, base: Base) -> Self::Wrap<T, Base>;
fn wrapped_as_base<'a, T, Base: HasId + PtrType>(wrap: &'a Self::Wrap<T, Base>) -> &'a Base;
fn wrapped_as_base_mut<'a, T, Base: HasId + PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base;
fn wrapped_as_base<T, Base: HasId + PtrType>(wrap: &Self::Wrap<T, Base>) -> &Base;
fn wrapped_as_base_mut<T, Base: HasId + PtrType>(wrap: &mut Self::Wrap<T, Base>) -> &mut Base;
}

#[macro_export]
Expand All @@ -25,16 +23,16 @@ macro_rules! impl_wrapped_data {
}

#[inline]
fn wrapped_as_base<'a, T, Base: $crate::HasId + $crate::PtrType>(
wrap: &'a Self::Wrap<T, Base>,
) -> &'a Base {
fn wrapped_as_base<T, Base: $crate::HasId + $crate::PtrType>(
wrap: &Self::Wrap<T, Base>,
) -> &Base {
Mods::wrapped_as_base(wrap)
}

#[inline]
fn wrapped_as_base_mut<'a, T, Base: $crate::HasId + $crate::PtrType>(
wrap: &'a mut Self::Wrap<T, Base>,
) -> &'a mut Base {
fn wrapped_as_base_mut<T, Base: $crate::HasId + $crate::PtrType>(
wrap: &mut Self::Wrap<T, Base>,
) -> &mut Base {
Mods::wrapped_as_base_mut(wrap)
}
}
Expand Down

0 comments on commit efa548a

Please sign in to comment.