Skip to content

Commit

Permalink
add Network file
Browse files Browse the repository at this point in the history
  • Loading branch information
ChizhovVadim committed Oct 25, 2022
1 parent 020780b commit 7ca3fa1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/ChizhovVadim/CounterGo

go 1.15
go 1.17

require golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
14 changes: 7 additions & 7 deletions internal/evalbuilder/eval.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package evalbuilder

import (
"embed"
"fmt"
"log"
"os"
"path/filepath"
"sync"

counter "github.com/ChizhovVadim/CounterGo/pkg/eval/counter"
Expand All @@ -16,6 +14,9 @@ import (
weiss "github.com/ChizhovVadim/CounterGo/pkg/eval/weiss"
)

//go:embed n-28-5177.nn
var content embed.FS

var once sync.Once
var weights *nnue.Weights

Expand Down Expand Up @@ -47,15 +48,14 @@ func Build(key string) interface{} {
}

func loadWeights() (*nnue.Weights, error) {
var exePath, err = os.Executable()
var f, err = content.Open("n-28-5177.nn")
if err != nil {
return nil, err
}
var filePath = filepath.Join(filepath.Dir(exePath), "default.nn")
weights, err = nnue.LoadWeights(filePath)
defer f.Close()
weights, err = nnue.LoadWeights(f)
if err != nil {
return nil, err
}
log.Printf("Loaded nnue file %v", filePath)
return weights, nil
}
Binary file added internal/evalbuilder/n-28-5177.nn
Binary file not shown.
11 changes: 2 additions & 9 deletions pkg/eval/nnue/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import (
"encoding/binary"
"io"
"math"
"os"
)

func LoadWeights(path string) (*Weights, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()

func LoadWeights(f io.Reader) (*Weights, error) {
// Read headers
buf := make([]byte, 4)

_, err = io.ReadFull(f, buf)
_, err := io.ReadFull(f, buf)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7ca3fa1

Please sign in to comment.