2013-09-22 16:58:21 +08:00
|
|
|
|
//! Matrix with dimensions unknown at compile-time.
|
|
|
|
|
|
2014-04-02 04:58:06 +08:00
|
|
|
|
#![allow(missing_doc)] // we hide doc to not have to document the $trhs double dispatch trait.
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2014-05-31 05:14:16 +08:00
|
|
|
|
use std::rand::Rand;
|
|
|
|
|
use std::rand;
|
2014-05-10 04:14:37 +08:00
|
|
|
|
use std::num::{One, Zero};
|
2014-01-10 03:48:30 +08:00
|
|
|
|
use traits::operations::ApproxEq;
|
2014-02-12 03:34:28 +08:00
|
|
|
|
use std::mem;
|
2013-10-06 22:54:09 +08:00
|
|
|
|
use structs::dvec::{DVec, DVecMulRhs};
|
2014-05-10 05:05:23 +08:00
|
|
|
|
use traits::operations::{Inv, Transpose, Mean, Cov};
|
2014-05-12 01:46:04 +08:00
|
|
|
|
use traits::structure::{Cast, ColSlice, RowSlice, Eye, Indexable};
|
2014-05-10 00:59:26 +08:00
|
|
|
|
use std::fmt::{Show, Formatter, Result};
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-05 06:01:10 +08:00
|
|
|
|
/// Matrix with dimensions unknown at compile-time.
|
2014-06-01 21:21:45 +08:00
|
|
|
|
#[deriving(TotalEq, PartialEq, Clone)]
|
2013-08-05 16:13:44 +08:00
|
|
|
|
pub struct DMat<N> {
|
2014-04-02 04:58:06 +08:00
|
|
|
|
nrows: uint,
|
|
|
|
|
ncols: uint,
|
|
|
|
|
mij: Vec<N>
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
double_dispatch_binop_decl_trait!(DMat, DMatMulRhs)
|
|
|
|
|
double_dispatch_binop_decl_trait!(DMat, DMatDivRhs)
|
|
|
|
|
double_dispatch_binop_decl_trait!(DMat, DMatAddRhs)
|
|
|
|
|
double_dispatch_binop_decl_trait!(DMat, DMatSubRhs)
|
2013-09-15 16:48:18 +08:00
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
mul_redispatch_impl!(DMat, DMatMulRhs)
|
|
|
|
|
div_redispatch_impl!(DMat, DMatDivRhs)
|
|
|
|
|
add_redispatch_impl!(DMat, DMatAddRhs)
|
|
|
|
|
sub_redispatch_impl!(DMat, DMatSubRhs)
|
2013-09-15 16:48:18 +08:00
|
|
|
|
|
2013-09-13 17:11:04 +08:00
|
|
|
|
impl<N> DMat<N> {
|
|
|
|
|
/// Creates an uninitialized matrix.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn new_uninitialized(nrows: uint, ncols: uint) -> DMat<N> {
|
2014-03-15 19:23:54 +08:00
|
|
|
|
let mut vec = Vec::with_capacity(nrows * ncols);
|
2013-12-16 19:04:02 +08:00
|
|
|
|
vec.set_len(nrows * ncols);
|
2013-09-13 17:11:04 +08:00
|
|
|
|
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: nrows,
|
|
|
|
|
ncols: ncols,
|
|
|
|
|
mij: vec
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 06:01:10 +08:00
|
|
|
|
impl<N: Zero + Clone> DMat<N> {
|
|
|
|
|
/// Builds a matrix filled with zeros.
|
2014-05-21 19:08:04 +08:00
|
|
|
|
///
|
2013-09-05 06:01:10 +08:00
|
|
|
|
/// # Arguments
|
|
|
|
|
/// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim`
|
|
|
|
|
/// components.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn new_zeros(nrows: uint, ncols: uint) -> DMat<N> {
|
2013-09-07 14:43:17 +08:00
|
|
|
|
DMat::from_elem(nrows, ncols, Zero::zero())
|
2013-09-05 06:01:10 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-05 06:01:10 +08:00
|
|
|
|
/// Tests if all components of the matrix are zeroes.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn is_zero(&self) -> bool {
|
|
|
|
|
self.mij.iter().all(|e| e.is_zero())
|
|
|
|
|
}
|
2013-10-14 16:22:32 +08:00
|
|
|
|
|
2013-10-17 03:44:33 +08:00
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
pub fn reset(&mut self) {
|
|
|
|
|
for mij in self.mij.mut_iter() {
|
|
|
|
|
*mij = Zero::zero();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-05 16:13:44 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-13 16:53:59 +08:00
|
|
|
|
impl<N: Rand> DMat<N> {
|
|
|
|
|
/// Builds a matrix filled with random values.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn new_random(nrows: uint, ncols: uint) -> DMat<N> {
|
|
|
|
|
DMat::from_fn(nrows, ncols, |_, _| rand::random())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 14:43:17 +08:00
|
|
|
|
impl<N: One + Clone> DMat<N> {
|
|
|
|
|
/// Builds a matrix filled with a given constant.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn new_ones(nrows: uint, ncols: uint) -> DMat<N> {
|
|
|
|
|
DMat::from_elem(nrows, ncols, One::one())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N: Clone> DMat<N> {
|
|
|
|
|
/// Builds a matrix filled with a given constant.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn from_elem(nrows: uint, ncols: uint, val: N) -> DMat<N> {
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: nrows,
|
|
|
|
|
ncols: ncols,
|
2014-03-15 19:23:54 +08:00
|
|
|
|
mij: Vec::from_elem(nrows * ncols, val)
|
2013-09-07 14:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
|
|
|
|
/// Builds a matrix filled with the components provided by a vector.
|
2013-10-18 04:40:44 +08:00
|
|
|
|
/// The vector contains the matrix data in row-major order.
|
|
|
|
|
/// Note that `from_col_vec` is a lot faster than `from_row_vec` since a `DMat` stores its data
|
|
|
|
|
/// in column-major order.
|
2013-09-22 20:22:17 +08:00
|
|
|
|
///
|
|
|
|
|
/// The vector must have at least `nrows * ncols` elements.
|
|
|
|
|
#[inline]
|
2013-10-18 04:40:44 +08:00
|
|
|
|
pub fn from_row_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat<N> {
|
|
|
|
|
let mut res = DMat::from_col_vec(ncols, nrows, vec);
|
|
|
|
|
|
|
|
|
|
// we transpose because the buffer is row_major
|
|
|
|
|
res.transpose();
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Builds a matrix filled with the components provided by a vector.
|
|
|
|
|
/// The vector contains the matrix data in column-major order.
|
|
|
|
|
/// Note that `from_col_vec` is a lot faster than `from_row_vec` since a `DMat` stores its data
|
|
|
|
|
/// in column-major order.
|
|
|
|
|
///
|
|
|
|
|
/// The vector must have at least `nrows * ncols` elements.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn from_col_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat<N> {
|
|
|
|
|
assert!(nrows * ncols == vec.len());
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: nrows,
|
|
|
|
|
ncols: ncols,
|
2014-03-15 19:23:54 +08:00
|
|
|
|
mij: Vec::from_slice(vec)
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-07 14:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N> DMat<N> {
|
|
|
|
|
/// Builds a matrix filled with a given constant.
|
|
|
|
|
#[inline(always)]
|
2013-11-27 18:16:16 +08:00
|
|
|
|
pub fn from_fn(nrows: uint, ncols: uint, f: |uint, uint| -> N) -> DMat<N> {
|
2013-09-07 14:43:17 +08:00
|
|
|
|
DMat {
|
|
|
|
|
nrows: nrows,
|
|
|
|
|
ncols: ncols,
|
2014-03-15 19:23:54 +08:00
|
|
|
|
mij: Vec::from_fn(nrows * ncols, |i| { let m = i % ncols; f(m, m - i * ncols) })
|
2013-09-07 14:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-08 23:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// The number of row on the matrix.
|
2013-09-18 20:22:29 +08:00
|
|
|
|
#[inline]
|
2013-09-08 23:19:50 +08:00
|
|
|
|
pub fn nrows(&self) -> uint {
|
|
|
|
|
self.nrows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The number of columns on the matrix.
|
2013-09-18 20:22:29 +08:00
|
|
|
|
#[inline]
|
2013-09-08 23:19:50 +08:00
|
|
|
|
pub fn ncols(&self) -> uint {
|
|
|
|
|
self.ncols
|
|
|
|
|
}
|
2013-09-18 20:22:29 +08:00
|
|
|
|
|
|
|
|
|
/// Transforms this matrix into an array. This consumes the matrix and is O(1).
|
2013-10-18 04:40:44 +08:00
|
|
|
|
/// The returned vector contains the matrix data in column-major order.
|
2013-09-18 20:22:29 +08:00
|
|
|
|
#[inline]
|
2014-03-15 19:23:54 +08:00
|
|
|
|
pub fn to_vec(self) -> Vec<N> {
|
2013-09-18 20:22:29 +08:00
|
|
|
|
self.mij
|
|
|
|
|
}
|
2013-10-18 04:40:44 +08:00
|
|
|
|
|
|
|
|
|
/// Gets a reference to this matrix data.
|
|
|
|
|
/// The returned vector contains the matrix data in column-major order.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn as_vec<'r>(&'r self) -> &'r [N] {
|
2014-03-15 19:23:54 +08:00
|
|
|
|
self.mij.as_slice()
|
2013-10-18 04:40:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Gets a mutable reference to this matrix data.
|
|
|
|
|
/// The returned vector contains the matrix data in column-major order.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn as_mut_vec<'r>(&'r mut self) -> &'r mut [N] {
|
2014-03-15 19:23:54 +08:00
|
|
|
|
self.mij.as_mut_slice()
|
2013-10-18 04:40:44 +08:00
|
|
|
|
}
|
2013-09-07 14:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 06:01:10 +08:00
|
|
|
|
// FIXME: add a function to modify the dimension (to avoid useless allocations)?
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2014-05-12 01:46:04 +08:00
|
|
|
|
impl<N: One + Zero + Clone> Eye for DMat<N> {
|
2013-09-05 06:01:10 +08:00
|
|
|
|
/// Builds an identity matrix.
|
2014-05-21 19:08:04 +08:00
|
|
|
|
///
|
2013-09-05 06:01:10 +08:00
|
|
|
|
/// # Arguments
|
2014-01-19 22:48:07 +08:00
|
|
|
|
/// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim`
|
|
|
|
|
/// components.
|
2013-09-05 06:01:10 +08:00
|
|
|
|
#[inline]
|
2014-05-12 01:46:04 +08:00
|
|
|
|
fn new_identity(dim: uint) -> DMat<N> {
|
2013-09-13 17:11:04 +08:00
|
|
|
|
let mut res = DMat::new_zeros(dim, dim);
|
2013-09-05 06:01:10 +08:00
|
|
|
|
|
|
|
|
|
for i in range(0u, dim) {
|
|
|
|
|
let _1: N = One::one();
|
2014-05-12 01:46:04 +08:00
|
|
|
|
res.set((i, i), _1);
|
2013-09-05 06:01:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
|
impl<N: Clone> DMat<N> {
|
2013-10-18 04:40:44 +08:00
|
|
|
|
#[inline(always)]
|
2013-08-05 16:13:44 +08:00
|
|
|
|
fn offset(&self, i: uint, j: uint) -> uint {
|
2013-10-18 04:40:44 +08:00
|
|
|
|
i + j * self.nrows
|
2013-08-05 16:13:44 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2014-05-12 01:46:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N: Clone> Indexable<(uint, uint), N> for DMat<N> {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
/// Changes the value of a component of the matrix.
|
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
2014-05-12 01:46:04 +08:00
|
|
|
|
/// * `rowcol` - 0-based tuple (row, col) to be changed
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2014-05-12 01:46:04 +08:00
|
|
|
|
fn set(&mut self, rowcol: (uint, uint), val: N) {
|
|
|
|
|
let (row, col) = rowcol;
|
2013-09-05 06:01:10 +08:00
|
|
|
|
assert!(row < self.nrows);
|
|
|
|
|
assert!(col < self.ncols);
|
2014-03-15 19:23:54 +08:00
|
|
|
|
|
|
|
|
|
let offset = self.offset(row, col);
|
|
|
|
|
*self.mij.get_mut(offset) = val
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
/// Just like `set` without bounds checking.
|
|
|
|
|
#[inline]
|
2014-05-12 01:46:04 +08:00
|
|
|
|
unsafe fn unsafe_set(&mut self, rowcol: (uint, uint), val: N) {
|
|
|
|
|
let (row, col) = rowcol;
|
2014-03-15 19:23:54 +08:00
|
|
|
|
let offset = self.offset(row, col);
|
|
|
|
|
*self.mij.as_mut_slice().unsafe_mut_ref(offset) = val
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
/// Reads the value of a component of the matrix.
|
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
2014-05-12 01:46:04 +08:00
|
|
|
|
/// * `rowcol` - 0-based tuple (row, col) to be read
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2014-05-12 01:46:04 +08:00
|
|
|
|
fn at(&self, rowcol: (uint, uint)) -> N {
|
|
|
|
|
let (row, col) = rowcol;
|
2013-09-05 06:01:10 +08:00
|
|
|
|
assert!(row < self.nrows);
|
|
|
|
|
assert!(col < self.ncols);
|
2014-05-12 01:46:04 +08:00
|
|
|
|
unsafe { self.unsafe_at((row, col)) }
|
2013-09-13 17:32:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Just like `at` without bounds checking.
|
|
|
|
|
#[inline]
|
2014-05-12 01:46:04 +08:00
|
|
|
|
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N {
|
|
|
|
|
let (row, col) = rowcol;
|
2014-03-15 19:23:54 +08:00
|
|
|
|
(*self.mij.as_slice().unsafe_ref(self.offset(row, col))).clone()
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2014-05-12 01:46:04 +08:00
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn swap(&mut self, rowcol1: (uint, uint), rowcol2: (uint, uint)) {
|
|
|
|
|
let (row1, col1) = rowcol1;
|
|
|
|
|
let (row2, col2) = rowcol2;
|
|
|
|
|
let offset1 = self.offset(row1, col1);
|
|
|
|
|
let offset2 = self.offset(row2, col2);
|
|
|
|
|
let count = self.mij.len();
|
|
|
|
|
assert!(offset1 < count);
|
2014-05-13 03:54:18 +08:00
|
|
|
|
assert!(offset2 < count);
|
2014-05-12 01:46:04 +08:00
|
|
|
|
self.mij.as_mut_slice().swap(offset1, offset2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn shape(&self) -> (uint, uint) {
|
|
|
|
|
(self.nrows, self.ncols)
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
impl<N: Clone + Mul<N, N> + Add<N, N> + Zero> DMatMulRhs<N, DMat<N>> for DMat<N> {
|
|
|
|
|
fn binop(left: &DMat<N>, right: &DMat<N>) -> DMat<N> {
|
|
|
|
|
assert!(left.ncols == right.nrows);
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
let mut res = unsafe { DMat::new_uninitialized(left.nrows, right.ncols) };
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
for i in range(0u, left.nrows) {
|
|
|
|
|
for j in range(0u, right.ncols) {
|
2013-08-28 20:22:12 +08:00
|
|
|
|
let mut acc: N = Zero::zero();
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
unsafe {
|
|
|
|
|
for k in range(0u, left.ncols) {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
acc = acc
|
|
|
|
|
+ left.unsafe_at((i, k)) * right.unsafe_at((k, j));
|
2013-09-13 17:32:30 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2014-05-12 01:46:04 +08:00
|
|
|
|
res.unsafe_set((i, j), acc);
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
res
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
|
impl<N: Clone + Add<N, N> + Mul<N, N> + Zero>
|
2013-09-15 16:48:18 +08:00
|
|
|
|
DMatMulRhs<N, DVec<N>> for DVec<N> {
|
|
|
|
|
fn binop(left: &DMat<N>, right: &DVec<N>) -> DVec<N> {
|
|
|
|
|
assert!(left.ncols == right.at.len());
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(left.nrows) };
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
for i in range(0u, left.nrows) {
|
2013-09-05 06:01:10 +08:00
|
|
|
|
let mut acc: N = Zero::zero();
|
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
for j in range(0u, left.ncols) {
|
2013-09-13 17:32:30 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
acc = acc + left.unsafe_at((i, j)) * right.unsafe_at(j);
|
2013-09-13 17:32:30 +08:00
|
|
|
|
}
|
2013-08-05 16:13:44 +08:00
|
|
|
|
}
|
2013-09-05 06:01:10 +08:00
|
|
|
|
|
2014-03-15 19:23:54 +08:00
|
|
|
|
*res.at.get_mut(i) = acc;
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
res
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
|
impl<N: Clone + Add<N, N> + Mul<N, N> + Zero>
|
2013-09-15 16:48:18 +08:00
|
|
|
|
DVecMulRhs<N, DVec<N>> for DMat<N> {
|
|
|
|
|
fn binop(left: &DVec<N>, right: &DMat<N>) -> DVec<N> {
|
|
|
|
|
assert!(right.nrows == left.at.len());
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(right.ncols) };
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
for i in range(0u, right.ncols) {
|
2013-09-05 06:01:10 +08:00
|
|
|
|
let mut acc: N = Zero::zero();
|
|
|
|
|
|
2013-09-15 16:48:18 +08:00
|
|
|
|
for j in range(0u, right.nrows) {
|
2013-09-13 17:32:30 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
acc = acc + left.unsafe_at(j) * right.unsafe_at((j, i));
|
2013-09-13 17:32:30 +08:00
|
|
|
|
}
|
2013-08-05 16:13:44 +08:00
|
|
|
|
}
|
2013-09-05 06:01:10 +08:00
|
|
|
|
|
2014-03-15 19:23:54 +08:00
|
|
|
|
*res.at.get_mut(i) = acc;
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
res
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
Rework of the traits for Vectors.
The goal is to make traits less fine-grained for vectors, and reduce the amount of `use`.
- Scalar{Mul, Div} are removed, replaced by Mul<N, V> and Div<N, V>,
- Ring and DivisionRing are removed. Use Num instead.
- VectorSpace, Dot, and Norm are removed, replaced by the new, higher-level traits.
Add four traits:
- Vec: common operations on vectors. Replaces VectorSpace and Dot.
- AlgebraicVec: Vec + the old Norm trait.
- VecExt: Vec + every other traits vectors implement.
- AlgebraicVecExt: AlgebraicVec + VecExt.
2013-08-19 00:33:25 +08:00
|
|
|
|
impl<N: Clone + Num>
|
2013-08-05 16:13:44 +08:00
|
|
|
|
Inv for DMat<N> {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn inv_cpy(m: &DMat<N>) -> Option<DMat<N>> {
|
|
|
|
|
let mut res : DMat<N> = m.clone();
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-10-14 16:22:32 +08:00
|
|
|
|
if res.inv() {
|
2013-08-05 16:13:44 +08:00
|
|
|
|
Some(res)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
None
|
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn inv(&mut self) -> bool {
|
2013-09-05 06:01:10 +08:00
|
|
|
|
assert!(self.nrows == self.ncols);
|
|
|
|
|
|
|
|
|
|
let dim = self.nrows;
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let mut res: DMat<N> = Eye::new_identity(dim);
|
2013-09-05 06:01:10 +08:00
|
|
|
|
let _0T: N = Zero::zero();
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
// inversion using Gauss-Jordan elimination
|
2013-08-05 16:13:44 +08:00
|
|
|
|
for k in range(0u, dim) {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
// search a non-zero value on the k-th column
|
|
|
|
|
// FIXME: would it be worth it to spend some more time searching for the
|
|
|
|
|
// max instead?
|
|
|
|
|
|
|
|
|
|
let mut n0 = k; // index of a non-zero entry
|
|
|
|
|
|
2014-01-23 08:22:23 +08:00
|
|
|
|
while n0 != dim {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
if unsafe { self.unsafe_at((n0, k)) } != _0T {
|
2013-08-05 16:13:44 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
|
|
|
|
n0 = n0 + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 19:08:04 +08:00
|
|
|
|
if n0 == dim {
|
2013-08-05 16:13:44 +08:00
|
|
|
|
return false
|
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
|
|
|
|
// swap pivot line
|
2013-08-05 16:13:44 +08:00
|
|
|
|
if n0 != k {
|
|
|
|
|
for j in range(0u, dim) {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
let off_n0_j = self.offset(n0, j);
|
|
|
|
|
let off_k_j = self.offset(k, j);
|
|
|
|
|
|
2014-03-15 19:23:54 +08:00
|
|
|
|
self.mij.as_mut_slice().swap(off_n0_j, off_k_j);
|
|
|
|
|
res.mij.as_mut_slice().swap(off_n0_j, off_k_j);
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let pivot = self.unsafe_at((k, k));
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
for j in range(k, dim) {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let selfval = self.unsafe_at((k, j)) / pivot;
|
|
|
|
|
self.unsafe_set((k, j), selfval);
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
for j in range(0u, dim) {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let resval = res.unsafe_at((k, j)) / pivot;
|
|
|
|
|
res.unsafe_set((k, j), resval);
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
for l in range(0u, dim) {
|
|
|
|
|
if l != k {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let normalizer = self.unsafe_at((l, k));
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
for j in range(k, dim) {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let selfval = self.unsafe_at((l, j)) - self.unsafe_at((k, j)) * normalizer;
|
|
|
|
|
self.unsafe_set((l, j), selfval);
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-09-18 20:22:29 +08:00
|
|
|
|
for j in range(0u, dim) {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let resval = res.unsafe_at((l, j)) - res.unsafe_at((k, j)) * normalizer;
|
|
|
|
|
res.unsafe_set((l, j), resval);
|
2013-09-18 20:22:29 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
*self = res;
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
true
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
|
impl<N: Clone> Transpose for DMat<N> {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2013-10-14 16:22:32 +08:00
|
|
|
|
fn transpose_cpy(m: &DMat<N>) -> DMat<N> {
|
|
|
|
|
if m.nrows == m.ncols {
|
|
|
|
|
let mut res = m.clone();
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
res.transpose();
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-10-14 16:22:32 +08:00
|
|
|
|
let mut res = unsafe { DMat::new_uninitialized(m.ncols, m.nrows) };
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2013-10-14 16:22:32 +08:00
|
|
|
|
for i in range(0u, m.nrows) {
|
|
|
|
|
for j in range(0u, m.ncols) {
|
2013-09-22 20:22:17 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
res.unsafe_set((j, i), m.unsafe_at((i, j)))
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
#[inline]
|
2013-08-05 16:13:44 +08:00
|
|
|
|
fn transpose(&mut self) {
|
2013-09-22 20:22:17 +08:00
|
|
|
|
if self.nrows == self.ncols {
|
|
|
|
|
for i in range(1u, self.nrows) {
|
|
|
|
|
for j in range(0u, self.ncols - 1) {
|
|
|
|
|
let off_i_j = self.offset(i, j);
|
|
|
|
|
let off_j_i = self.offset(j, i);
|
|
|
|
|
|
2014-03-15 19:23:54 +08:00
|
|
|
|
self.mij.as_mut_slice().swap(off_i_j, off_j_i);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 03:34:28 +08:00
|
|
|
|
mem::swap(&mut self.nrows, &mut self.ncols);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// FIXME: implement a better algorithm which does that in-place.
|
2013-10-14 16:22:32 +08:00
|
|
|
|
*self = Transpose::transpose_cpy(self);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
|
2013-10-10 04:59:44 +08:00
|
|
|
|
impl<N: Num + Cast<f32> + Clone> Mean<DVec<N>> for DMat<N> {
|
2013-10-17 03:44:33 +08:00
|
|
|
|
fn mean(m: &DMat<N>) -> DVec<N> {
|
|
|
|
|
let mut res: DVec<N> = DVec::new_zeros(m.ncols);
|
|
|
|
|
let normalizer: N = Cast::from(1.0f32 / Cast::from(m.nrows));
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2013-10-17 03:44:33 +08:00
|
|
|
|
for i in range(0u, m.nrows) {
|
|
|
|
|
for j in range(0u, m.ncols) {
|
2013-09-22 20:22:17 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
let acc = res.unsafe_at(j) + m.unsafe_at((i, j)) * normalizer;
|
|
|
|
|
res.unsafe_set(j, acc);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-05 06:01:10 +08:00
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 04:59:44 +08:00
|
|
|
|
impl<N: Clone + Num + Cast<f32> + DMatDivRhs<N, DMat<N>> + ToStr > Cov<DMat<N>> for DMat<N> {
|
2013-09-22 20:22:17 +08:00
|
|
|
|
// FIXME: this could be heavily optimized, removing all temporaries by merging loops.
|
2013-10-17 03:44:33 +08:00
|
|
|
|
fn cov(m: &DMat<N>) -> DMat<N> {
|
|
|
|
|
assert!(m.nrows > 1);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2013-10-17 03:44:33 +08:00
|
|
|
|
let mut centered = unsafe { DMat::new_uninitialized(m.nrows, m.ncols) };
|
|
|
|
|
let mean = Mean::mean(m);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
|
|
|
|
// FIXME: use the rows iterator when available
|
2013-10-17 03:44:33 +08:00
|
|
|
|
for i in range(0u, m.nrows) {
|
|
|
|
|
for j in range(0u, m.ncols) {
|
2013-09-22 20:22:17 +08:00
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
centered.unsafe_set((i, j), m.unsafe_at((i, j)) - mean.unsafe_at(j));
|
2013-09-22 20:22:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: return a triangular matrix?
|
2013-10-17 03:44:33 +08:00
|
|
|
|
let fnormalizer: f32 = Cast::from(m.nrows() - 1);
|
2013-10-10 04:59:44 +08:00
|
|
|
|
let normalizer: N = Cast::from(fnormalizer);
|
2013-09-22 20:22:17 +08:00
|
|
|
|
// FIXME: this will do 2 allocations for temporaries!
|
2013-10-14 16:22:32 +08:00
|
|
|
|
(Transpose::transpose_cpy(¢ered) * centered) / normalizer
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 04:14:37 +08:00
|
|
|
|
impl<N: Clone> ColSlice<DVec<N>> for DMat<N> {
|
|
|
|
|
fn col_slice(&self, col_id :uint, row_start: uint, row_end: uint) -> DVec<N> {
|
|
|
|
|
assert!(col_id < self.ncols);
|
|
|
|
|
assert!(row_start < row_end);
|
|
|
|
|
assert!(row_end <= self.nrows);
|
|
|
|
|
// we can init from slice thanks to the matrix being column major
|
|
|
|
|
let start= self.offset(row_start, col_id);
|
|
|
|
|
let stop = self.offset(row_end, col_id);
|
|
|
|
|
let slice = DVec::from_vec(
|
|
|
|
|
row_end - row_start, self.mij.slice(start, stop));
|
|
|
|
|
slice
|
|
|
|
|
}
|
2014-05-10 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 04:14:37 +08:00
|
|
|
|
impl<N: Clone> RowSlice<DVec<N>> for DMat<N> {
|
|
|
|
|
fn row_slice(&self, row_id :uint, col_start: uint, col_end: uint) -> DVec<N> {
|
|
|
|
|
assert!(row_id < self.nrows);
|
|
|
|
|
assert!(col_start < col_end);
|
|
|
|
|
assert!(col_end <= self.ncols);
|
|
|
|
|
let mut slice : DVec<N> = unsafe {
|
|
|
|
|
DVec::new_uninitialized(self.nrows)
|
|
|
|
|
};
|
|
|
|
|
let mut slice_idx = 0u;
|
|
|
|
|
for col_id in range(col_start, col_end) {
|
|
|
|
|
unsafe {
|
2014-05-12 01:46:04 +08:00
|
|
|
|
slice.unsafe_set(slice_idx, self.unsafe_at((row_id, col_id)));
|
2014-05-10 04:14:37 +08:00
|
|
|
|
}
|
|
|
|
|
slice_idx += 1;
|
|
|
|
|
}
|
|
|
|
|
slice
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-10 00:59:26 +08:00
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
|
impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2014-01-10 03:48:30 +08:00
|
|
|
|
fn approx_epsilon(_: Option<DMat<N>>) -> N {
|
|
|
|
|
ApproxEq::approx_epsilon(None::<N>)
|
2013-08-05 16:13:44 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2014-01-10 03:48:30 +08:00
|
|
|
|
fn approx_eq(a: &DMat<N>, b: &DMat<N>) -> bool {
|
|
|
|
|
let mut zip = a.mij.iter().zip(b.mij.iter());
|
2013-06-09 20:09:22 +08:00
|
|
|
|
|
2014-01-10 03:48:30 +08:00
|
|
|
|
zip.all(|(a, b)| ApproxEq::approx_eq(a, b))
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
|
2013-08-05 15:44:56 +08:00
|
|
|
|
#[inline]
|
2014-01-10 03:48:30 +08:00
|
|
|
|
fn approx_eq_eps(a: &DMat<N>, b: &DMat<N>, epsilon: &N) -> bool {
|
|
|
|
|
let mut zip = a.mij.iter().zip(b.mij.iter());
|
2013-06-09 20:09:22 +08:00
|
|
|
|
|
2014-01-10 03:48:30 +08:00
|
|
|
|
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
2013-08-05 15:44:56 +08:00
|
|
|
|
}
|
2013-05-31 17:28:42 +08:00
|
|
|
|
}
|
2013-09-22 20:22:17 +08:00
|
|
|
|
|
2014-05-10 00:59:26 +08:00
|
|
|
|
impl<N: Show + Clone> Show for DMat<N> {
|
|
|
|
|
fn fmt(&self, form:&mut Formatter) -> Result {
|
|
|
|
|
for i in range(0u, self.nrows()) {
|
|
|
|
|
for j in range(0u, self.ncols()) {
|
2014-05-17 03:04:35 +08:00
|
|
|
|
let _ = write!(form, "{} ", self.at((i, j)));
|
2014-05-10 00:59:26 +08:00
|
|
|
|
}
|
2014-05-17 03:04:35 +08:00
|
|
|
|
let _ = write!(form, "\n");
|
2014-05-10 00:59:26 +08:00
|
|
|
|
}
|
2014-05-17 03:04:35 +08:00
|
|
|
|
write!(form, "\n")
|
2014-05-10 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 20:22:17 +08:00
|
|
|
|
macro_rules! scalar_mul_impl (
|
|
|
|
|
($n: ident) => (
|
|
|
|
|
impl DMatMulRhs<$n, DMat<$n>> for $n {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn binop(left: &DMat<$n>, right: &$n) -> DMat<$n> {
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: left.nrows,
|
|
|
|
|
ncols: left.ncols,
|
|
|
|
|
mij: left.mij.iter().map(|a| a * *right).collect()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
macro_rules! scalar_div_impl (
|
|
|
|
|
($n: ident) => (
|
|
|
|
|
impl DMatDivRhs<$n, DMat<$n>> for $n {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn binop(left: &DMat<$n>, right: &$n) -> DMat<$n> {
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: left.nrows,
|
|
|
|
|
ncols: left.ncols,
|
|
|
|
|
mij: left.mij.iter().map(|a| a / *right).collect()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
macro_rules! scalar_add_impl (
|
|
|
|
|
($n: ident) => (
|
|
|
|
|
impl DMatAddRhs<$n, DMat<$n>> for $n {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn binop(left: &DMat<$n>, right: &$n) -> DMat<$n> {
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: left.nrows,
|
|
|
|
|
ncols: left.ncols,
|
|
|
|
|
mij: left.mij.iter().map(|a| a + *right).collect()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
macro_rules! scalar_sub_impl (
|
|
|
|
|
($n: ident) => (
|
|
|
|
|
impl DMatSubRhs<$n, DMat<$n>> for $n {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn binop(left: &DMat<$n>, right: &$n) -> DMat<$n> {
|
|
|
|
|
DMat {
|
|
|
|
|
nrows: left.nrows,
|
|
|
|
|
ncols: left.ncols,
|
|
|
|
|
mij: left.mij.iter().map(|a| a - *right).collect()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
scalar_mul_impl!(f64)
|
|
|
|
|
scalar_mul_impl!(f32)
|
|
|
|
|
scalar_mul_impl!(u64)
|
|
|
|
|
scalar_mul_impl!(u32)
|
|
|
|
|
scalar_mul_impl!(u16)
|
|
|
|
|
scalar_mul_impl!(u8)
|
|
|
|
|
scalar_mul_impl!(i64)
|
|
|
|
|
scalar_mul_impl!(i32)
|
|
|
|
|
scalar_mul_impl!(i16)
|
|
|
|
|
scalar_mul_impl!(i8)
|
|
|
|
|
scalar_mul_impl!(uint)
|
|
|
|
|
scalar_mul_impl!(int)
|
|
|
|
|
|
|
|
|
|
scalar_div_impl!(f64)
|
|
|
|
|
scalar_div_impl!(f32)
|
|
|
|
|
scalar_div_impl!(u64)
|
|
|
|
|
scalar_div_impl!(u32)
|
|
|
|
|
scalar_div_impl!(u16)
|
|
|
|
|
scalar_div_impl!(u8)
|
|
|
|
|
scalar_div_impl!(i64)
|
|
|
|
|
scalar_div_impl!(i32)
|
|
|
|
|
scalar_div_impl!(i16)
|
|
|
|
|
scalar_div_impl!(i8)
|
|
|
|
|
scalar_div_impl!(uint)
|
|
|
|
|
scalar_div_impl!(int)
|
|
|
|
|
|
|
|
|
|
scalar_add_impl!(f64)
|
|
|
|
|
scalar_add_impl!(f32)
|
|
|
|
|
scalar_add_impl!(u64)
|
|
|
|
|
scalar_add_impl!(u32)
|
|
|
|
|
scalar_add_impl!(u16)
|
|
|
|
|
scalar_add_impl!(u8)
|
|
|
|
|
scalar_add_impl!(i64)
|
|
|
|
|
scalar_add_impl!(i32)
|
|
|
|
|
scalar_add_impl!(i16)
|
|
|
|
|
scalar_add_impl!(i8)
|
|
|
|
|
scalar_add_impl!(uint)
|
|
|
|
|
scalar_add_impl!(int)
|
|
|
|
|
|
|
|
|
|
scalar_sub_impl!(f64)
|
|
|
|
|
scalar_sub_impl!(f32)
|
|
|
|
|
scalar_sub_impl!(u64)
|
|
|
|
|
scalar_sub_impl!(u32)
|
|
|
|
|
scalar_sub_impl!(u16)
|
|
|
|
|
scalar_sub_impl!(u8)
|
|
|
|
|
scalar_sub_impl!(i64)
|
|
|
|
|
scalar_sub_impl!(i32)
|
|
|
|
|
scalar_sub_impl!(i16)
|
|
|
|
|
scalar_sub_impl!(i8)
|
|
|
|
|
scalar_sub_impl!(uint)
|
|
|
|
|
scalar_sub_impl!(int)
|