Skip to content

Commit

Permalink
Added a check for valid reshapes
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Oct 30, 2020
1 parent a857266 commit 809c071
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dense.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (t *Dense) Engine() Engine { return t.e }

// Reshape reshapes a *Dense. If the tensors need to be materialized (either it's a view or transpose), it will be materialized before the reshape happens
func (t *Dense) Reshape(dims ...int) error {
if t.Shape().TotalSize() != Shape(dims).TotalSize() {
return errors.Errorf("Cannot reshape %v into %v", t.Shape(), dims)
}

if t.viewOf != 0 && t.o.IsNotContiguous() {
return errors.Errorf(methodNYI, "Reshape", "non-contiguous views")
}
Expand Down Expand Up @@ -335,6 +339,7 @@ func (t *Dense) sanity() error {
if t.viewOf == 0 && size != expected && !t.IsScalar() {
return errors.Wrap(errors.Errorf(shapeMismatch, t.Shape(), size), "sanity check failed")
}

// TODO: sanity check for views
return nil
}
Expand Down

0 comments on commit 809c071

Please sign in to comment.