Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Jan 14, 2019
2 parents 5ed438b + 64df62f commit a06d791
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ The point of this package is to provide operations that are accelerated by SIMD.

# FAQ

### Why are there so many `a = a[:len(a)]` lines?
This is mainly done to eliminate bounds checking in a loop. The idea is the bounds of the slice is checked early on, and if need be, panics early. Then if everything is normal, there won't be bounds checking while in the loop.
### Why are there so many `b = b[:len(a)]` lines?
This is mainly done to eliminate bounds checking in a loop. The idea is the bounds of the slice is checked early on, and if need be, panics early. Then if everything is normal, there won't be bounds checking while in the loop. This also means that `b` must be at least `len(a)`, otherwise a panic will occur.

To check for boundschecking and bounds check elimination (an amazing feature that landed in Go 1.7), compile your programs with `-gcflags='-d=ssa/check_bce/debug=1'`.

Expand Down
4 changes: 0 additions & 4 deletions arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "github.com/chewxy/math32"
// Pow performs elementwise
// a̅ ^ b̅
func Pow(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
switch b[i] {
Expand All @@ -24,7 +23,6 @@ func Pow(a, b []float32) {
}

func Mod(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
a[i] = math32.Mod(v, b[i])
Expand Down Expand Up @@ -93,7 +91,6 @@ func PowOfR(a []float32, s float32) {

// Max takes two slices, a̅ + b̅, and compares them elementwise. The highest value is put into a̅.
func Max(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]

for i, v := range a {
Expand All @@ -106,7 +103,6 @@ func Max(a, b []float32) {

// Min takes two slices, a̅ + b̅ and compares them elementwise. The lowest value is put into a̅.
func Min(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]

for i, v := range a {
Expand Down
4 changes: 0 additions & 4 deletions go.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "github.com/chewxy/math32"

// Add performs a̅ + b̅. a̅ will be clobbered
func Add(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
a[i] = v + b[i]
Expand All @@ -15,7 +14,6 @@ func Add(a, b []float32) {

// Sub performs a̅ - b̅. a̅ will be clobbered
func Sub(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
a[i] = v - b[i]
Expand All @@ -24,7 +22,6 @@ func Sub(a, b []float32) {

// Mul performs a̅ × b̅. a̅ will be clobbered
func Mul(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
a[i] = v * b[i]
Expand All @@ -33,7 +30,6 @@ func Mul(a, b []float32) {

// Div performs a̅ ÷ b̅. a̅ will be clobbered
func Div(a, b []float32) {
a = a[:len(a)]
b = b[:len(a)]
for i, v := range a {
if b[i] == 0 {
Expand Down
12 changes: 0 additions & 12 deletions incr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "github.com/chewxy/math32"

// IncrAdd performs a̅ + b̅ and then adds it elementwise to the incr slice
func IncrAdd(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
Expand All @@ -14,7 +13,6 @@ func IncrAdd(a, b, incr []float32) {

// IncrSub performs a̅ = b̅ and then adds it elementwise to the incr slice
func IncrSub(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
Expand All @@ -24,7 +22,6 @@ func IncrSub(a, b, incr []float32) {

// IncrMul performs a̅ × b̅ and then adds it elementwise to the incr slice
func IncrMul(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
Expand All @@ -33,7 +30,6 @@ func IncrMul(a, b, incr []float32) {
}

func IncrDiv(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
Expand All @@ -47,7 +43,6 @@ func IncrDiv(a, b, incr []float32) {

// IncrDiv performs a̅ ÷ b̅. then adds it to incr
func IncrPow(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
Expand All @@ -68,7 +63,6 @@ func IncrPow(a, b, incr []float32) {

// IncrMod performs a̅ % b̅ then adds it to incr
func IncrMod(a, b, incr []float32) {
a = a[:len(a)]
b = b[:len(a)]
incr = incr[:len(a)]

Expand All @@ -80,7 +74,6 @@ func IncrMod(a, b, incr []float32) {
// Scale multiplies all values in the slice by the scalar and then increments the incr slice
// incr += a̅ * s
func IncrScale(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v * s
Expand All @@ -96,7 +89,6 @@ func IncrScaleInv(a []float32, s float32, incr []float32) {
/// IncrScaleInvR divides all numbers in the slice by a scalar and then increments the incr slice
// incr += s / a̅
func IncrScaleInvR(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += s / v
Expand All @@ -106,7 +98,6 @@ func IncrScaleInvR(a []float32, s float32, incr []float32) {
// IncrTrans adds all the values in the slice by a scalar and then increments the incr slice
// incr += a̅ + s
func IncrTrans(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v + s
Expand All @@ -122,7 +113,6 @@ func IncrTransInv(a []float32, s float32, incr []float32) {
// IncrTransInvR subtracts all the numbers in a slice from a scalar and then increments the incr slice
// incr += s - a̅
func IncrTransInvR(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += s - v
Expand All @@ -132,7 +122,6 @@ func IncrTransInvR(a []float32, s float32, incr []float32) {
// IncrPowOf performs elementwise power function and then increments the incr slice
// incr += a̅ ^ s
func IncrPowOf(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += math32.Pow(v, s)
Expand All @@ -142,7 +131,6 @@ func IncrPowOf(a []float32, s float32, incr []float32) {
// PowOfR performs elementwise power function below and then increments the incr slice.
// incr += s ^ a̅
func IncrPowOfR(a []float32, s float32, incr []float32) {
a = a[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += math32.Pow(s, v)
Expand Down

0 comments on commit a06d791

Please sign in to comment.