1. Fazlul Shahriar
  2. cgo-cblas

Source

cgo-cblas / cblas / level1.go

// Copyright 2011 Fazlul Shahriar. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cblas

// #include <complex.h>
// #include <cblas.h>
import "C"

import "unsafe"

// Sdsdot returns the sum of alpha and the dot product x'*y.
func Sdsdot(alpha float32, x, y *Float32Vector) float32 {
	return float32(C.cblas_sdsdot(C.int(x.Size), C.float(alpha),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.float)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride)))
}

// Dsdot returns the dot product x'*y.
func Dsdot(x, y *Float32Vector) float64 {
	return float64(C.cblas_dsdot(C.int(x.Size),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.float)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride)))
}

// Sdot returns the dot product x'*y.
func Sdot(x, y *Float32Vector) float32 {
	return float32(C.cblas_sdot(C.int(x.Size),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.float)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride)))
}

// Ddot returns the dot product x'*y.
func Ddot(x, y *Float64Vector) float64 {
	return float64(C.cblas_ddot(C.int(x.Size),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.double)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride)))
}

// Cdotu returns the dot product x'*y.
func Cdotu(x, y *Complex64Vector) complex64 {
	var dot C.complexfloat
	C.cblas_cdotu_sub(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride), unsafe.Pointer(&dot))
	return complex64(dot)
}

// Cdotc returns the dot product of conjugate of x with y.
func Cdotc(x, y *Complex64Vector) complex64 {
	var dot C.complexfloat
	C.cblas_cdotc_sub(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride), unsafe.Pointer(&dot))
	return complex64(dot)
}

// Zdotu returns the dot product x'*y.
func Zdotu(x, y *Complex128Vector) complex128 {
	var dot C.complexdouble
	C.cblas_zdotu_sub(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride), unsafe.Pointer(&dot))
	return complex128(dot)
}

// Zdotc returns the dot product of conjugate of x with y.
func Zdotc(x, y *Complex128Vector) complex128 {
	var dot C.complexdouble
	C.cblas_zdotc_sub(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride), unsafe.Pointer(&dot))
	return complex128(dot)
}

// Snrm2 returns the Euclidean norm of x: sqrt(x'*x).
func Snrm2(x *Float32Vector) float32 {
	return float32(C.cblas_snrm2(C.int(x.Size),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Sasum returns the sum of abolute value of x.
func Sasum(x *Float32Vector) float32 {
	return float32(C.cblas_sasum(C.int(x.Size),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Dnrm2 returns the Euclidean norm of x: sqrt(x'*x).
func Dnrm2(x *Float64Vector) float64 {
	return float64(C.cblas_dnrm2(C.int(x.Size),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Dasum returns the sum of abolute value of x.
func Dasum(x *Float64Vector) float64 {
	return float64(C.cblas_dasum(C.int(x.Size),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Scnrm2 returns the Euclidean norm of x: sqrt(conjg(x')*x).
func Scnrm2(x *Complex64Vector) float32 {
	return float32(C.cblas_scnrm2(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

// Scasum returns the sum of the absolute value of real and imaginary parts of x.
func Scasum(x *Complex64Vector) float32 {
	return float32(C.cblas_scasum(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

// Dznrm2 returns the Euclidean norm of x: sqrt(conjg(x')*x).
func Dznrm2(x *Complex128Vector) float64 {
	return float64(C.cblas_dznrm2(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

// Dzasum returns the sum of the absolute value of real and imaginary parts of x.
func Dzasum(x *Complex128Vector) float64 {
	return float64(C.cblas_dzasum(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

// Isamax returns the index of the maximum absolute value of x.
func Isamax(x *Float32Vector) int {
	return int(C.cblas_isamax(C.int(x.Size),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Idamax returns the index of the maximum absolute value of x.
func Idamax(x *Float64Vector) int {
	return int(C.cblas_idamax(C.int(x.Size),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride)))
}

// Icamax returns the index of the maximum sum of the absolute value of
// real and imaginary parts of x.
func Icamax(x *Complex64Vector) int {
	return int(C.cblas_icamax(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

// Izamax returns the index of the maximum sum of the absolute value of
// real and imaginary parts of x.
func Izamax(x *Complex128Vector) int {
	return int(C.cblas_izamax(C.int(x.Size),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride)))
}

/*
void cblas_sswap(const int N, float *X, const int incX,
                 float *Y, const int incY);
void cblas_scopy(const int N, const float *X, const int incX,
                 float *Y, const int incY);
*/

// Saxpy updates y: y <- alpha*x + y.
func Saxpy(alpha float32, x, y *Float64Vector) {
	C.cblas_saxpy(C.int(x.Size), C.float(alpha),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.float)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride))
}

/*
void cblas_dswap(const int N, double *X, const int incX,
                 double *Y, const int incY);
void cblas_dcopy(const int N, const double *X, const int incX,
                 double *Y, const int incY);
*/

// Daxpy updates y: y <- alpha*x + y.
func Daxpy(alpha float64, x, y *Float64Vector) {
	C.cblas_daxpy(C.int(x.Size), C.double(alpha),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride),
		(*C.double)(unsafe.Pointer(&y.Data[0])), C.int(y.Stride))
}

/*
void cblas_cswap(const int N, void *X, const int incX,
                 void *Y, const int incY);
void cblas_ccopy(const int N, const void *X, const int incX,
                 void *Y, const int incY);
*/

// Caxpy updates y: y <- alpha*x + y.
func Caxpy(alpha complex64, x, y *Complex64Vector) {
	C.cblas_caxpy(C.int(x.Size), unsafe.Pointer(&alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride))
}

/*
void cblas_zswap(const int N, void *X, const int incX,
                 void *Y, const int incY);
void cblas_zcopy(const int N, const void *X, const int incX,
                 void *Y, const int incY);
*/

// Zaxpy updates y: y <- alpha*x + y.
func Zaxpy(alpha complex128, x, y *Complex128Vector) {
	C.cblas_zaxpy(C.int(x.Size), unsafe.Pointer(&alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride),
		unsafe.Pointer(&y.Data[0]), C.int(y.Stride))
}

/*
void cblas_srotg(float *a, float *b, float *c, float *s);
void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
void cblas_srot(const int N, float *X, const int incX,
                float *Y, const int incY, const float c, const float s);
void cblas_srotm(const int N, float *X, const int incX,
                float *Y, const int incY, const float *P);

void cblas_drotg(double *a, double *b, double *c, double *s);
void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
void cblas_drot(const int N, double *X, const int incX,
                double *Y, const int incY, const double c, const double s);
void cblas_drotm(const int N, double *X, const int incX,
                double *Y, const int incY, const double *P);
*/

// Sscal scales x by constant alpha.
func Sscal(alpha float32, x *Float32Vector) {
	C.cblas_sscal(C.int(x.Size), C.float(alpha),
		(*C.float)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride))
}

// Dscal scales x by constant alpha.
func Dscal(alpha float64, x *Float64Vector) {
	C.cblas_dscal(C.int(x.Size), C.double(alpha),
		(*C.double)(unsafe.Pointer(&x.Data[0])), C.int(x.Stride))
}

// Cscal scales x by constant alpha.
func Cscal(alpha complex64, x *Complex64Vector) {
	C.cblas_cscal(C.int(x.Size), unsafe.Pointer(&alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride))
}

// Zscal scales x by constant alpha.
func Zscal(alpha complex128, x *Complex128Vector) {
	C.cblas_zscal(C.int(x.Size), unsafe.Pointer(&alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride))
}

// Csscal scales x by constant alpha.
func Csscal(alpha float32, x *Complex64Vector) {
	C.cblas_csscal(C.int(x.Size), C.float(alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride))
}

// Zdscal scales x by constant alpha.
func Zdscal(alpha float64, x *Complex128Vector) {
	C.cblas_zdscal(C.int(x.Size), C.double(alpha),
		unsafe.Pointer(&x.Data[0]), C.int(x.Stride))
}