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
359 stars 49 forks source link

Remove redundant code from header copy func #109

Closed MarkKremer closed 3 years ago

MarkKremer commented 3 years ago

First merge my other PR because it uses the same fixed test helper.

This is just a dumb small PR. I removed some code that I thought was redundant:

if len(dst.Raw) == 0 || len(src.Raw) == 0 {
    return 0
}

This is an edge case and copy() takes care of this already. It's better to optimize for the usual case.

n := src.TypedLen(t)
if len(dst.Raw) < n {
    n = dst.TypedLen(t)
}

// handle struct{} type
if t.Size() == 0 {
    return n
}

Empty structs don't work with tensors. If you try to create one it will panic or error. It's Dtype is also not defined. Although you could still try to create one using WithBacking(). Maybe we could return a more explicit error if you try to create one at some point.

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.01%) to 73.021% when pulling b4f9cc49d15764976f8a2f02b62488d08f234592 on MarkKremer:markkremer_remove_redundant_code_from_header_copy_func into cb074974725cfacb47b7122fc4a2f8ed1004a883 on gorgonia:master.

chewxy commented 3 years ago

Not small or dumb. Waiting for this to go green then I'll merge