1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2014 by SiegeLord
//
// All rights reserved. Distributed under LGPL 3.0. For full terms see the file LICENSE.

use un_ops::{UnOp, MatrixUnOp};
use traits::MatrixShape;

pub trait Inv where Self: Sized
{
	#[inline]
	fn inv(self) -> Self;
}

impl Inv for f64
{
	#[inline]
	fn inv(self) -> f64
	{
		1.0 / self
	}
}

macro_rules! un_fun
{
	($struct_name: ident, $trait_name: ident, $func_name: ident) =>
	{
		#[derive(Copy, Clone)]
		pub struct $struct_name;

		impl $struct_name
		{
			#[inline]
			pub fn new() -> $struct_name
			{
				$struct_name
			}
		}

		mod $func_name
		{
			#[allow(unused_imports)]
			use super::Inv;

			#[inline]
			pub fn $func_name(a: f64) -> f64
			{
				a.$func_name()
			}
		}

		impl UnOp for $struct_name
		{
			fn op(&self, a: f64) -> f64
			{
				$func_name::$func_name(a)
			}
		}

		pub trait $trait_name where Self: Sized
		{
			fn $func_name(self) -> MatrixUnOp<Self, $struct_name>;
		}

		impl<T: MatrixShape + Clone>
		$trait_name for
		T
		{
			fn $func_name(self) -> MatrixUnOp<T, $struct_name>
			{
				MatrixUnOp::new(self.clone(), $struct_name::new())
			}
		}
	}
}

un_fun!(AbsOp, MatrixAbsOp, abs);
un_fun!(AcosOp, MatrixAcosOp, acos);
un_fun!(AsinOp, MatrixAsinOp, asin);
un_fun!(AtanOp, MatrixAtanOp, atan);
un_fun!(CeilOp, MatrixCeilOp, ceil);
un_fun!(CosOp, MatrixCosOp, cos);
un_fun!(CoshOp, MatrixCoshOp, cosh);
un_fun!(ExpOp, MatrixExpOp, exp);
un_fun!(FloorOp, MatrixFloorOp, floor);
un_fun!(LnOp, MatrixLnOp, ln);
un_fun!(Log10Op, MatrixLog10Op, log10);
un_fun!(RoundOp, MatrixRoundOp, round);
un_fun!(SinOp, MatrixSinOp, sin);
un_fun!(SinhOp, MatrixSinhOp, sinh);
un_fun!(SqrtOp, MatrixSqrtOp, sqrt);
un_fun!(TanOp, MatrixTanOp, tan);
un_fun!(TanhOp, MatrixTanhOp, tanh);
un_fun!(InvOp, MatrixInvOp, inv);