#[macro_export]
macro_rules! layer {
($($x:tt)*) => {
Box::new(Layer::$($x)*)
};
}
#[macro_export]
macro_rules! grad_storage {
($($x:tt)*) => {
std::rc::Rc::new(std::cell::RefCell::new(Box::new($($x)*)))
};
}
#[macro_export]
macro_rules! match_storage {
(binary $self:expr, $method:ident, $other:expr $(, $args:expr)*) => {
match ($self, $other) {
(Storage::Cpu(cpu_self), Storage::Cpu(cpu_other)) => {
Storage::Cpu(cpu_self.$method(cpu_other $(, $args)*))
}
_ => unimplemented!("Cross-device operations not supported"),
}
};
(unary $self:expr, $method:ident $(, $args:expr)*) => {
match $self {
Storage::Cpu(cpu) => Storage::Cpu(cpu.$method($($args),*)),
_ => unimplemented!("Device not supported"),
}
};
}
#[macro_export]
macro_rules! match_storage_assign {
(binary $self:expr, $method:ident, $other:expr $(, $args:expr)*) => {
match ($self, $other) {
(Storage::Cpu(cpu_self), Storage::Cpu(cpu_other)) => {
cpu_self.$method(cpu_other $(, $args)*)
}
_ => unimplemented!("Cross-device operations not supported"),
}
};
(unary $self:expr, $method:ident $(, $args:expr)*) => {
match $self {
Storage::Cpu(cpu) => cpu.$method($($args,)*),
_ => unimplemented!("Device not supported"),
}
};
}