-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for stream log for model outputs with final dimension > 1.
- Loading branch information
1 parent
5e70e40
commit fbef303
Showing
3 changed files
with
236 additions
and
35 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,26 @@ | ||
package stream | ||
|
||
import "github.com/viant/tapper/io" | ||
|
||
const propertyKey string = "output" | ||
|
||
type KVStrings []string | ||
|
||
// implements github.com/viant/tapper/io.Encoder | ||
func (s KVStrings) Encode(m io.Stream) { | ||
m.PutStrings(propertyKey, []string(s)) | ||
} | ||
|
||
type KVInts []int | ||
|
||
// implements github.com/viant/tapper/io.Encoder | ||
func (s KVInts) Encode(m io.Stream) { | ||
m.PutInts(propertyKey, []int(s)) | ||
} | ||
|
||
type KVFloat64s []float64 | ||
|
||
// implements github.com/viant/tapper/io.Encoder | ||
func (s KVFloat64s) Encode(m io.Stream) { | ||
m.PutFloats(propertyKey, []float64(s)) | ||
} |
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
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,93 @@ | ||
package stream | ||
|
||
import ( | ||
"bytes" | ||
ejson "encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/viant/mly/service/domain" | ||
"github.com/viant/tapper/msg" | ||
"github.com/viant/tapper/msg/json" | ||
) | ||
|
||
type siP struct { | ||
O1 string `json:"out1"` | ||
} | ||
|
||
type muP struct { | ||
O1 []string `json:"out1"` | ||
} | ||
|
||
type mbP struct { | ||
O1 []struct { | ||
Ov []string `json:"output"` | ||
} `json:"out1"` | ||
} | ||
|
||
func TestWriteObject(t *testing.T) { | ||
p := msg.NewProvider(2048, 32, json.New) | ||
os := []domain.Output{{Name: "out1"}} | ||
|
||
testCases := []struct { | ||
name string | ||
out []interface{} | ||
verify func([]byte) | ||
}{ | ||
{ | ||
name: "single-single-dim", | ||
out: []interface{}{[][]string{ | ||
[]string{"a"}, | ||
}}, | ||
verify: func(b []byte) { | ||
p := new(siP) | ||
err := ejson.Unmarshal(b, &p) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
{ | ||
name: "single-multi-dim", | ||
out: []interface{}{[][]string{ | ||
[]string{"a", "b"}, | ||
}}, | ||
verify: func(b []byte) { | ||
p := new(muP) | ||
err := ejson.Unmarshal(b, &p) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
{ | ||
name: "batch-single-dim", | ||
out: []interface{}{[][]string{ | ||
[]string{"a"}, | ||
[]string{"b"}, | ||
}}, | ||
verify: func(b []byte) { | ||
p := new(muP) | ||
err := ejson.Unmarshal(b, &p) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
{ | ||
name: "batch-multi-dim", | ||
out: []interface{}{[][]string{ | ||
[]string{"a", "b"}, | ||
[]string{"c", "d"}, | ||
}}, | ||
verify: func(b []byte) { | ||
mbp := new(mbP) | ||
err := ejson.Unmarshal(b, &mbp) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
m := p.NewMessage() | ||
writeObject(m, false, tc.out, os) | ||
b := new(bytes.Buffer) | ||
m.WriteTo(b) | ||
tc.verify(b.Bytes()) | ||
m.Free() | ||
} | ||
} |