From 2428dfa7ded0e3610de719d3e8bc16eaee07e863 Mon Sep 17 00:00:00 2001 From: Richard Townsend Date: Sat, 24 Mar 2018 00:17:44 +0000 Subject: [PATCH] Fix various other little errors --- base/serialize_instances.go | 16 +++++++++++----- meta/one_v_all.go | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/base/serialize_instances.go b/base/serialize_instances.go index 278f01e..7239776 100644 --- a/base/serialize_instances.go +++ b/base/serialize_instances.go @@ -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) diff --git a/meta/one_v_all.go b/meta/one_v_all.go index ded4239..e6a7e6f 100644 --- a/meta/one_v_all.go +++ b/meta/one_v_all.go @@ -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")