asm/c128: Stubs and tests for DscalInc.
MODIFY
internal/asm/c128/stubs_noasm.go
internal/asm/c128/stubs_noasm.go
@@ -65,3 +65,13 @@ func DscalUnitary(alpha float64, x []complex128) {
x[i] = complex(real(v)*alpha, imag(v))
}
}
+
+// DscalInc is
+// for i := 0; i < n; i++ {
+// x[i*inc] = complex(real(x[i*inc])*alpha, imag(x[i*inc]))
+// }
+func DscalInc(n int, alpha float64, x []complex128, inc int) {
+ for i := 0; i < n; i++ {
+ x[i*inc] = complex(real(x[i*inc])*alpha, imag(x[i*inc]))
+ }
+}

MODIFY
internal/asm/c128/stubs_test.go
internal/asm/c128/stubs_test.go
@@ -137,7 +137,7 @@ func TestAxpyInc(t *testing.T) {
var x_gd, y_gd complex128 = 1, 1
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
- test.x, test.y = guardIncVector(test.x, x_gd, uintptr(test.incX), xg_ln), guardIncVector(test.y, y_gd, uintptr(test.incY), yg_ln)
+ test.x, test.y = guardIncVector(test.x, x_gd, test.incX, xg_ln), guardIncVector(test.y, y_gd, test.incY, yg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
AxpyInc(test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
for i := range test.ex {
@@ -145,8 +145,8 @@ func TestAxpyInc(t *testing.T) {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, y[i*int(test.incY)], test.ex[i])
}
}
- checkValidIncGuard(t, test.x, x_gd, uintptr(test.incX), xg_ln)
- checkValidIncGuard(t, test.y, y_gd, uintptr(test.incY), yg_ln)
+ checkValidIncGuard(t, test.x, x_gd, test.incX, xg_ln)
+ checkValidIncGuard(t, test.y, y_gd, test.incY, yg_ln)
}
}
@@ -154,8 +154,8 @@ func TestAxpyIncTo(t *testing.T) {
var x_gd, y_gd, dst_gd complex128 = 1, 1, 0
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
- test.x, test.y = guardIncVector(test.x, x_gd, uintptr(test.incX), xg_ln), guardIncVector(test.y, y_gd, uintptr(test.incY), yg_ln)
- test.dst = guardIncVector(test.dst, dst_gd, uintptr(test.incDst), xg_ln)
+ test.x, test.y = guardIncVector(test.x, x_gd, test.incX, xg_ln), guardIncVector(test.y, y_gd, test.incY, yg_ln)
+ test.dst = guardIncVector(test.dst, dst_gd, test.incDst, xg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
dst := test.dst[xg_ln : len(test.dst)-xg_ln]
AxpyIncTo(dst, uintptr(test.incDst), test.idst, test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
@@ -164,9 +164,9 @@ func TestAxpyIncTo(t *testing.T) {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, dst[i*int(test.incDst)], test.ex[i])
}
}
- checkValidIncGuard(t, test.x, x_gd, uintptr(test.incX), xg_ln)
- checkValidIncGuard(t, test.y, y_gd, uintptr(test.incY), yg_ln)
- checkValidIncGuard(t, test.dst, dst_gd, uintptr(test.incDst), xg_ln)
+ checkValidIncGuard(t, test.x, x_gd, test.incX, xg_ln)
+ checkValidIncGuard(t, test.y, y_gd, test.incY, yg_ln)
+ checkValidIncGuard(t, test.dst, dst_gd, test.incDst, xg_ln)
}
}
@@ -229,3 +229,25 @@ func TestDscalUnitary(t *testing.T) {
}
}
}
+
+func TestDscalInc(t *testing.T) {
+ const xGdVal = -0.5
+ gdLn := 4
+ for i, test := range scalTests {
+ n := len(test.x)
+ for _, incX := range []int{1, 2, 3, 4, 7, 10} {
+ prefix := fmt.Sprintf("Test %v (x:%v)", i, incX)
+ xg := guardIncVector(test.x, xGdVal, incX, gdLn)
+ x := xg[gdLn : len(xg)-gdLn]
+
+ DscalInc(n, test.alpha, x, incX)
+
+ for i := range test.want {
+ if !same(x[i*incX], test.want[i]) {
+ t.Errorf(msgVal, prefix, i, x[i*incX], test.want[i])
+ }
+ }
+ checkValidIncGuard(t, xg, xGdVal, incX, gdLn)
+ }
+ }
+}

MODIFY
internal/asm/c128/util_test.go
internal/asm/c128/util_test.go
@@ -40,8 +40,7 @@ func isValidGuard(vec []complex128, guard_val complex128, guard_len int) bool {
return true
}
-func guardIncVector(vec []complex128, guard_val complex128, incV uintptr, guard_len int) (guarded []complex128) {
- inc := int(incV)
+func guardIncVector(vec []complex128, guard_val complex128, inc, guard_len int) (guarded []complex128) {
s_ln := len(vec) * inc
if inc < 0 {
s_ln = len(vec) * -inc
@@ -61,8 +60,7 @@ func guardIncVector(vec []complex128, guard_val complex128, incV uintptr, guard_
return guarded
}
-func checkValidIncGuard(t *testing.T, vec []complex128, guard_val complex128, incV uintptr, guard_len int) {
- inc := int(incV)
+func checkValidIncGuard(t *testing.T, vec []complex128, guard_val complex128, inc, guard_len int) {
s_ln := len(vec) - 2*guard_len
if inc < 0 {
s_ln = len(vec) * -inc

asm/c128: Stubs and tests for DscalInc.