gonum / matrix

Matrix packages for the Go language [DEPRECATED]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mat64: implement a stream-oriented binary (de)serialization

sbinet opened this issue · comments

the whole discussion about #342 and the []byte size implications made me think about implementing a more memory-wise efficient approach.

why not also provide:

// pseudo-code
func (d *Dense) MarshalBinaryStream(w io.Writer) error {
      binary.Write(w, littleEndian, nrows)
      binary.Write(w, littleEndian, ncols)
      for i := range nrows {
        for j := range ncols {
           binary.Write(w, littleEndian, data.at(i,j))
        }
      }
      return err
}

func (d *Dense) UnmarshalBinaryStream(r io.Reader) error {
   // ...
}

and then implement MarshalBinary in terms of MarshalBinaryStream.

people not wanting to get beaten by the possibly large temporary []byte slice could just use the stream oriented version.

I think this is reasonable. bikeshed: MarshalBinaryTo(io.Writer) error and UnmarshalBinaryFrom(io.Reader) error

SGTM.
I'll prepare a CL once #342 has landed.

They may as well return (n int, err error), right?

yes. they could.

Good point.