forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-25163: [C#] Support half-float arrays. (apache#34618)
### Rationale for this change .NET 5 introduced the [`System.Half`](https://devblogs.microsoft.com/dotnet/introducing-the-half-type/) type, which represents 16-bit floats. This PR adds support for them in Apache Arrow. ### What changes are included in this PR? I multi-targeted the `Apache.Arrow` project to .NET 6 (because .NET 5 is unsupported) and added a `HalfFloatArray` type with a very similar implementation as the other floating-point array types. I also updated the README. ### Are these changes tested? Yes. I also refactored the array tests to reduce duplication among the various numeric types. ### Are there any user-facing changes? Yes. * Closes: apache#25163 Lead-authored-by: Theodore Tsirpanis <[email protected]> Co-authored-by: Eric Erhardt <[email protected]> Signed-off-by: Eric Erhardt <[email protected]>
- Loading branch information
Showing
12 changed files
with
159 additions
and
59 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
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
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
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,46 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Apache.Arrow.Types; | ||
using System; | ||
|
||
namespace Apache.Arrow | ||
{ | ||
public class HalfFloatArray : PrimitiveArray<Half> | ||
{ | ||
public class Builder : PrimitiveArrayBuilder<Half, HalfFloatArray, Builder> | ||
{ | ||
protected override HalfFloatArray Build( | ||
ArrowBuffer valueBuffer, ArrowBuffer nullBitmapBuffer, | ||
int length, int nullCount, int offset) => | ||
new HalfFloatArray(valueBuffer, nullBitmapBuffer, length, nullCount, offset); | ||
} | ||
|
||
public HalfFloatArray( | ||
ArrowBuffer valueBuffer, ArrowBuffer nullBitmapBuffer, | ||
int length, int nullCount, int offset) | ||
: this(new ArrayData(HalfFloatType.Default, length, nullCount, offset, | ||
new[] { nullBitmapBuffer, valueBuffer })) | ||
{ } | ||
|
||
public HalfFloatArray(ArrayData data) | ||
: base(data) | ||
{ | ||
data.EnsureDataType(ArrowTypeId.HalfFloat); | ||
} | ||
|
||
public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor); | ||
} | ||
} |
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
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
Oops, something went wrong.