Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment index within Sweeper.Next function #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mnist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ func TestLoad(t *testing.T) {
}
println(train.Count(), test.Count())
}

func TestSweeperNext(t *testing.T) {
train, _, err := Load("./data")
if err != nil {
t.Fatalf("load (%s)", err)
}
sweeper := train.Sweep()
var currentIndex = sweeper.i
sweeper.Next()
if currentIndex == sweeper.i {
t.Errorf("Next does not increase index")
}
}
6 changes: 4 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ type Sweeper struct {
// Next returns the next image and its label in the data set.
// If the end is reached, present is set to false.
func (sw *Sweeper) Next() (image RawImage, label Label, present bool) {
if sw.i >= len(sw.set.Images) {
var prevIndex = sw.i
sw.i += 1
if prevIndex >= len(sw.set.Images) {
return nil, 0, false
}
return sw.set.Images[sw.i], sw.set.Labels[sw.i], true
return sw.set.Images[prevIndex], sw.set.Labels[prevIndex], true
}

// Sweep creates a new sweep iterator over the data set
Expand Down