-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from CortexFoundation/ucwong
cvm/synapse | numpy reader and writer update
- Loading branch information
Showing
9 changed files
with
716 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package inference | ||
|
||
import ( | ||
"fmt" | ||
"encoding/binary" | ||
) | ||
|
||
func (rdr *NpyReader) GetBytes() ([]byte, error) { | ||
|
||
data := make([]byte, rdr.nElt) | ||
err := binary.Read(rdr.r, rdr.Endian, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
{{- range . }} | ||
// Get{{ .TypeU }} returns the array data as a slice of {{ .TypeL }} values. | ||
func (rdr *NpyReader) Get{{ .TypeU }}() ([]{{ .TypeL }}, error) { | ||
|
||
if rdr.Dtype != "{{ .TypeCode }}" { | ||
return nil, fmt.Errorf("Reader does not contain {{ .TypeL }} data") | ||
} | ||
|
||
data := make([]{{ .TypeL }}, rdr.nElt) | ||
err := binary.Read(rdr.r, rdr.Endian, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} | ||
{{ end }} | ||
|
||
{{- range . }} | ||
// Write{{ .TypeU }} writes a slice of {{ .TypeL }} values in npy format. | ||
func (wtr *NpyWriter) Write{{ .TypeU }}(data []{{ .TypeL }}) error { | ||
|
||
err := wtr.writeHeader("{{ .TypeCode }}", len(data)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = binary.Write(wtr.w, wtr.Endian, data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
wtr.w.Close() | ||
|
||
return nil | ||
} | ||
{{ end }} | ||
|
Oops, something went wrong.