Skip to content

Support cast float16 array to float32/float64 #424

Closed

Description

@Sunyue

Describe the enhancement requested

When trying to cast float16 array to float32/float64 using compute.CastToType(), I am getting error not implemented: function 'cast_float' has no kernel matching input types (float16). I tried a few other types which are also not possible.

Is it feasible to support casting from float16 in function compute.CastToType()? Thanks!

import (
	"testing"

	"github.com/apache/arrow-go/v18/arrow"
	"github.com/apache/arrow-go/v18/arrow/array"
	"github.com/apache/arrow-go/v18/arrow/compute"
	"github.com/apache/arrow-go/v18/arrow/float16"
	"github.com/apache/arrow-go/v18/arrow/memory"
	"github.com/stretchr/testify/require"
)

func Test_Types(t *testing.T) {
	t.Parallel()

	tt := []struct {
		name string
		to   arrow.DataType
	}{
		{
			name: "float32",
			to:   arrow.PrimitiveTypes.Float32,
		},
		{
			name: "float64",
			to:   arrow.PrimitiveTypes.Float64,
		},
	}

	for _, tc := range tt {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()

			ctx := t.Context()
			rq := require.New(t)

			builder := array.NewFloat16Builder(memory.DefaultAllocator)
			defer builder.Release()

			builder.AppendValues([]float16.Num{float16.New(1.1), float16.New(2.2), float16.New(3.3)}, nil)
			arr := builder.NewArray()

			defer arr.Release()

			_, err := compute.CastToType(ctx, arr, tc.to)
			rq.NoError(err, "failed to cast from float16 to %q", tc.to.Name())
		})
	}
}

Component(s)

Other

Activity

  1. added a commit that references this issue on Jul 9, 2025
    8598fb3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions