mirror of
https://github.com/gonum/gonum.git
synced 2025-11-02 11:24:13 +08:00
Sum of AbsVal implemented.
This commit is contained in:
18
asm/f32/axpy_amd64.go
Normal file
18
asm/f32/axpy_amd64.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Generated code do not edit. Run `go generate`.
|
||||
|
||||
// Copyright ©2015 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !noasm,!appengine
|
||||
|
||||
package f32
|
||||
|
||||
func AxpyIncTo(dst []float32, incDst, idst uintptr, alpha float32, x, y []float32, n, incX, incY, ix, iy uintptr) {
|
||||
for i := 0; i < int(n); i++ {
|
||||
dst[idst] = alpha*x[ix] + y[iy]
|
||||
ix += incX
|
||||
iy += incY
|
||||
idst += incDst
|
||||
}
|
||||
}
|
||||
25
asm/f32/dot_amd64.go
Normal file
25
asm/f32/dot_amd64.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Generated code do not edit. Run `go generate`.
|
||||
|
||||
// Copyright ©2015 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !noasm,!appengine
|
||||
|
||||
package f32
|
||||
|
||||
func DotUnitary(x, y []float32) (sum float32) {
|
||||
for i, v := range x {
|
||||
sum += y[i] * v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func DotInc(x, y []float32, n, incX, incY, ix, iy uintptr) (sum float32) {
|
||||
for i := 0; i < int(n); i++ {
|
||||
sum += y[iy] * x[ix]
|
||||
ix += incX
|
||||
iy += incY
|
||||
}
|
||||
return
|
||||
}
|
||||
40
asm/f32/scal_amd64.go
Normal file
40
asm/f32/scal_amd64.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Generated code do not edit. Run `go generate`.
|
||||
|
||||
// Copyright ©2016 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !noasm,!appengine
|
||||
|
||||
package f32
|
||||
|
||||
func ScalUnitary(alpha float32, x []float32) {
|
||||
for i := range x {
|
||||
x[i] *= alpha
|
||||
}
|
||||
}
|
||||
|
||||
func ScalUnitaryTo(dst []float32, alpha float32, x []float32) {
|
||||
for i, v := range x {
|
||||
dst[i] = alpha * v
|
||||
}
|
||||
}
|
||||
|
||||
// incX must be positive.
|
||||
func ScalInc(alpha float32, x []float32, n, incX uintptr) {
|
||||
var ix uintptr
|
||||
for i := 0; i < int(n); i++ {
|
||||
x[ix] *= alpha
|
||||
ix += incX
|
||||
}
|
||||
}
|
||||
|
||||
// incDst and incX must be positive.
|
||||
func ScalIncTo(dst []float32, incDst uintptr, alpha float32, x []float32, n, incX uintptr) {
|
||||
var idst, ix uintptr
|
||||
for i := 0; i < int(n); i++ {
|
||||
dst[idst] = alpha * x[ix]
|
||||
ix += incX
|
||||
idst += incDst
|
||||
}
|
||||
}
|
||||
37
asm/f64/abssum_amd64.s
Normal file
37
asm/f64/abssum_amd64.s
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright ©2016 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
//func AbsSum(x []float64) float64
|
||||
TEXT ·AbsSum(SB), NOSPLIT, $0
|
||||
MOVQ x_base+0(FP), SI
|
||||
MOVQ x_len+8(FP), DX
|
||||
XORQ AX, AX
|
||||
PXOR X0, X0
|
||||
PXOR X1, X1
|
||||
CMPQ DX, $1
|
||||
JL absum_end
|
||||
JE absum_tail
|
||||
absum_loop:
|
||||
MOVUPS (SI)(AX*8), X2
|
||||
ADDPD X2, X0
|
||||
ADDPD X1, X2
|
||||
MAXPD X2, X0
|
||||
MOVAPS X0, X1
|
||||
ADDQ $2, AX
|
||||
CMPQ AX, DX
|
||||
JL absum_loop
|
||||
JE absum_end
|
||||
absum_tail:
|
||||
MOVSD (SI)(AX*8), X2
|
||||
ADDSD X2, X0
|
||||
ADDSD X1, X2
|
||||
MAXSD X2, X0
|
||||
absum_end:
|
||||
MOVAPS X0, X1
|
||||
SHUFPD $0, X0, X0
|
||||
MAXSD X0, X1
|
||||
MOVSD X1, sum+24(FP)
|
||||
RET
|
||||
40
asm/f64/abssuminc_amd64.s
Normal file
40
asm/f64/abssuminc_amd64.s
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright ©2016 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
//func AbsSumInc(x []float64, n, incX int) (sum float64)
|
||||
TEXT ·AbsSumInc(SB), NOSPLIT, $0
|
||||
MOVQ x_base+0(FP), SI
|
||||
MOVQ n+24(FP), DX
|
||||
MOVQ incX+32(FP), CX
|
||||
SHLQ $3, CX
|
||||
XORQ AX, AX
|
||||
PXOR X0, X0
|
||||
PXOR X1, X1
|
||||
PXOR X4, X4
|
||||
CMPQ DX, $0
|
||||
JE absum_end
|
||||
absum_loop:
|
||||
MOVSD (SI), X2
|
||||
ADDSD X2, X0
|
||||
ADDSD X1, X2
|
||||
MOVSD (SI)(CX*1), X3
|
||||
ADDSD X3, X4
|
||||
ADDSD X5, X3
|
||||
MAXSD X2, X0
|
||||
MAXSD X3, X4
|
||||
MOVSD X0, X1
|
||||
MOVSD X4, X5
|
||||
ADDQ CX, SI
|
||||
ADDQ AX, SI
|
||||
CMPQ AX, DX
|
||||
JL absum_loop
|
||||
ADDSD X4, X0
|
||||
absum_end:
|
||||
MOVSD X1, X0
|
||||
SHUFPD $0, X0, X0
|
||||
MAXSD X0, X1
|
||||
MOVSD X1, sum+24(FP)
|
||||
RET
|
||||
@@ -6,10 +6,14 @@
|
||||
|
||||
package f64
|
||||
|
||||
func Add(dst, s []float64)
|
||||
func AbsSum(x []float64) (sum float64)
|
||||
|
||||
func AbsSumInc(x []float64, n, incX int) (sum float64)
|
||||
|
||||
func AddConst(alpha float64, x []float64)
|
||||
|
||||
func Add(dst, s []float64)
|
||||
|
||||
func AxpyUnitary(alpha float64, x, y []float64)
|
||||
|
||||
func AxpyUnitaryTo(dst []float64, alpha float64, x, y []float64)
|
||||
|
||||
@@ -6,8 +6,24 @@
|
||||
|
||||
package f64
|
||||
|
||||
import "math"
|
||||
|
||||
func AddConst(alpha float64, x []float64) {
|
||||
for i := range x {
|
||||
x[i] += alpha
|
||||
}
|
||||
}
|
||||
|
||||
func AbsSum(x []float64) (sum float64) {
|
||||
for _, v := range x {
|
||||
sum += math.Abs(v)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func AbsSumInc(x []float64, n, incX int) (sum float64) {
|
||||
for i := 0; i < n; i++ {
|
||||
sum += math.Abs(x[i*incX])
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user