Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arrow/tensor/tensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func New(data arrow.ArrayData, shape, strides []int64, names []string) Interface
}

func newTensor(dtype arrow.DataType, data arrow.ArrayData, shape, strides []int64, names []string) *tensorBase {
if names == nil {
names = make([]string, len(shape))
}

tb := tensorBase{
dtype: dtype,
bw: int64(dtype.(arrow.FixedWidthDataType).BitWidth()) / 8,
Expand Down
18 changes: 18 additions & 0 deletions arrow/tensor/tensor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,21 @@ func TestInvalidTensor(t *testing.T) {
})

}

func TestTensorWithNilDimensionNames(t *testing.T) {
bld := array.NewFloat64Builder(memory.DefaultAllocator)
defer bld.Release()
bld.AppendValues([]float64{1, 2}, nil)
arr := bld.NewFloat64Array()
defer arr.Release()

tsr := tensor.New(arr.Data(), []int64{2}, nil, nil)
defer tsr.Release()

if got, want := tsr.DimNames(), []string{""}; !reflect.DeepEqual(got, want) {
t.Fatalf("invalid dim-names: got=%v, want=%v", got, want)
}
if got := tsr.DimName(0); got != "" {
t.Fatalf("invalid dim-name[0]: got=%q, want empty string", got)
}
}
Loading