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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use self::super::{HanInt, c32, c64};

pub fn sdot(n: HanInt, x: &[f32], incx: HanInt, y: &[f32], incy: HanInt) -> f32 {
    return sdot_always_correct(n, x, incx, y, incy);
}

pub fn sdot_always_correct(n: HanInt, x: &[f32], incx: HanInt, y: &[f32], incy: HanInt) -> f32 {
    let mut stemp = 0.0f32;
    if n <= 0 {return stemp;}
    if incx == 1 && incy == 1 {
        let m = n % 4;
        if m != 0 {
            for i in 0..m as usize {
                stemp = stemp + x[i]*y[i];
            }
            if n < 4 {
                return stemp;
            }
        }
        for i in (m as usize..n as usize).step_by(4) {
            stemp = stemp
                + x[i]*y[i]
                + x[i+1]*y[i+1]
                + x[i+2]*y[i+2]
                + x[i+3]*y[i+3];
        }
    } else {
        let mut ix = 1;
        let mut iy = 1;
        if incx < 0 {
            ix = (-n+1)*incx + 1;
        }
        if incy < 0 {
            iy = (-n+1)*incy + 1;
        }
        for _ in 0..n {
            stemp = stemp + x[ix as usize]*y[iy as usize];
            ix = ix + incx;
            iy = iy + incy;
        }
    }
    return stemp;
}


pub fn ddot(n: HanInt, x: &[f64], incx: HanInt, y: &[f64], incy: HanInt) -> f64 {
    return 0.0;
}

pub fn ddot_always_correct(n: HanInt, x: &[f64], incx: HanInt, y: &[f64], incy: HanInt) -> f64 {
    let mut ret = 0.0f64;
    if n <= 0 {return ret;}
    if incx == 1 && incy == 1 {
        let m = n % 4;
        if m != 0 {
            for i in 0..m as usize {
                ret = ret + x[i]*y[i];
            }
            if n < 4 {
                return ret;
            }
        }
        for i in (m as usize..n as usize).step_by(4) {
            ret = ret
                + x[i]*y[i]
                + x[i+1]*y[i+1]
                + x[i+2]*y[i+2]
                + x[i+3]*y[i+3];
        }
    } else {
        let mut ix = 1;
        let mut iy = 1;
        if incx < 0 {
            ix = (-n+1)*incx + 1;
        }
        if incy < 0 {
            iy = (-n+1)*incy + 1;
        }
        for _ in 0..n {
            ret = ret + x[ix as usize]*y[iy as usize];
            ix = ix + incx;
            iy = iy + incy;
        }
    }
    return ret;
}

pub fn dsdot(n: HanInt, x: &[f32], incx: HanInt, y: &[f32], incy: HanInt) -> f64 {
    return 0.0;
}

pub fn dsdot_always_correct(n: HanInt, x: &[f32], incx: HanInt, y: &[f32], incy: HanInt) -> f64 {
    let mut ret = 0.0f64;
    if n <= 0 { return ret; }
    if incx == incy && incx > 0 {
        let ns = n*incx;
        for i in (0..ns as usize).step_by(incx as usize) {
            ret = ret + (x[i] as f64)*(y[i] as f64);
        }
    } else {
        let mut kx = 1;
        let mut ky = 1;
        if incx < 0 {
            kx = 1 + (1-n)*incx;
        }
        if incy < 0 {
            ky = 1 + (1-n)*incy;
        }
        for i in 0..n as usize {
            ret = ret + (x[kx as usize] as f64)*(y[ky as usize] as f64);
            kx = kx + incx;
            ky = ky + incy;
        }
    }
    return ret;
}