gorgonia / tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Apache License 2.0
362 stars 49 forks source link

Fixed an issue with the leftTensor parameter leading to a bug for scalars #71

Closed bezineb5 closed 4 years ago

bezineb5 commented 4 years ago

Fix for #70 The issue was that the operation is performed in place on the first operand, but the output is passed as second operand. The solution was to always use the output as first operand, filling it with the scalar if needed.

I fear that the problem might still exist with iterators.

chewxy commented 4 years ago

Looking at this now

wzzhu commented 4 years ago

Any new progress on this? Thanks.

chewxy commented 4 years ago

My bad. SubScalar was broken and I was halfway fixing it and then life got in the way

chewxy commented 4 years ago

Will be fixed tomorrow

chewxy commented 4 years ago

There is some infelicities when UseUnsafe is used.... looking into it and fixing it.

Here's a good example:

func TestIssue72(t *testing.T) {
    a := New(FromScalar(3.14))
    b := 0.0

    bsa, err := Sub(b, a)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("%v", bsa)
    ret, err := Sub(b, bsa, UseUnsafe())
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("%v %v", ret, bsa)
}
chewxy commented 4 years ago

Closing this, and using #73 instead.