1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-26 13:49:14 +08:00

Fix various other little errors

This commit is contained in:
Richard Townsend 2018-03-24 00:17:44 +00:00
parent ff52c013eb
commit 2428dfa7de
2 changed files with 13 additions and 7 deletions

View File

@ -164,16 +164,19 @@ func DeserializeInstancesFromTarReader(tr *FunctionalTarReader, prefix string) (
// Finally, read the values out of the data section
for i := 0; i < rowCount; i++ {
for _, s := range specs {
for j, s := range specs {
r := ret.Get(s, i)
n, err := reader.Read(r)
if n != len(r) {
return nil, fmt.Errorf("Expected %d bytes (read %d) on row %d", len(r), n, i)
}
if err != nil {
return nil, fmt.Errorf("Read error: %s", err)
return nil, WrapError(fmt.Errorf("Expected %d bytes (read %d) on row %d", len(r), n, i))
}
ret.Set(s, i, r)
if err != nil {
if i == rowCount-1 && j == len(specs)-1 && err == io.EOF {
break
}
return nil, WrapError(fmt.Errorf("Read error in data section (at row %d from %d, attr %d from %d): %s", i, rowCount, j, len(specs), err))
}
}
}
@ -300,6 +303,9 @@ func SerializeInstancesToTarWriter(inst FixedDataGrid, tw *tar.Writer, prefix st
}
allSpecs := ResolveAttributes(inst, allAttrs)
if len(allSpecs) != len(allAttrs) {
return WrapError(fmt.Errorf("Error resolving all Attributes: resolved %d, expected %d", len(allSpecs), len(allAttrs)))
}
// First, estimate the amount of data we'll need...
dataLength := int64(0)

View File

@ -176,7 +176,7 @@ func (m *OneVsAllModel) LoadWithPrefix(reader *base.ClassifierDeserializer, pref
attrMap := make(map[base.Attribute]base.Attribute)
for j := 0; j < int(numAttrsInMapU64); j++ {
mapTupleKey := reader.Prefix(mapPrefix, fmt.Sprintf("%d"))
mapTupleKey := reader.Prefix(mapPrefix, fmt.Sprintf("%d", j))
mapKeyKeyKey := reader.Prefix(mapTupleKey, "KEY")
mapKeyValKey := reader.Prefix(mapTupleKey, "VAL")
@ -289,7 +289,7 @@ func (m *OneVsAllModel) SaveWithPrefix(writer *base.ClassifierSerializer, prefix
}
j := 0
for key := range f.attrs {
mapTupleKey := writer.Prefix(mapPrefix, fmt.Sprintf("%d"))
mapTupleKey := writer.Prefix(mapPrefix, fmt.Sprintf("%d", j))
mapKeyKeyKey := writer.Prefix(mapTupleKey, "KEY")
mapKeyValKey := writer.Prefix(mapTupleKey, "VAL")