123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package neuralnetwork
- import (
- "encoding/binary"
- "fmt"
- "io"
- mat "gonum.org/v1/gonum/mat"
- )
- func saveDense(writer io.Writer, matrix *mat.Dense) {
- buffer, _ := matrix.MarshalBinary()
-
- bufferSize := make([]byte, 4)
- binary.LittleEndian.PutUint32(bufferSize, uint32(len(buffer)))
- writer.Write(bufferSize)
- _, err := writer.Write(buffer)
- check(err)
-
- printMatDense(matrix)
- }
- func printMatDense(matrix *mat.Dense) {
-
-
-
- }
- func readDense(reader io.Reader, matrix *mat.Dense) *mat.Dense {
- count := readInt(reader)
-
- matrix = &mat.Dense{}
- matrix.UnmarshalBinary(readByteArray(reader, count))
- printMatDense(matrix)
- return matrix
- }
- func readByteArray(reader io.Reader, size int) []byte {
-
- sizeBuffer := make([]byte, size)
- n1, err := reader.Read(sizeBuffer)
- check(err)
- fmt.Printf("readByteArray: size = %d \n", n1)
- return sizeBuffer
- }
- func readInt(reader io.Reader) int {
-
- count := make([]byte, 4)
- _, err := reader.Read(count)
- check(err)
- return int(binary.LittleEndian.Uint32(count))
- }
- func check(e error) {
- if e != nil {
- panic(e)
- }
- }
|