Skip to content

provide hooks for user-defined types #1

Open
@sbinet

Description

it should be possible for npyio.Write and npyio.Read to properly handle user-defined types, e.g. type MyMatrix struct {...}

probably by having said user-defined type implement an interface that allows to describe the internal data:

  • a way to expose equivalent data to npyio.Header.Descr
  • a way to expose the underlying data slice []T (where T is one of the scalar types that npyio supports)

Alternatively, have npyio expose npyio.Marshaler and npyio.Unmarshaler interfaces (which would then be tested for and used in npyio.Write and npyio.Read, respectively)
Tentatively:

type Type struct {
    Name    string // e.g. '<f8'
    Shape   []int
    Fortran bool
}

type Marshaler interface {
    MarshalNPy() (dtype Type, data []byte, err error)
}

type Unmarshaler interface {
    UnmarshalNPy(dtype Type, data []byte) error
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions