Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Migrated other kernels.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Nov 25, 2021
1 parent a0c16e3 commit 865ad04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 64 deletions.
36 changes: 7 additions & 29 deletions src/compute/take/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
// 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.

use crate::{
array::{Array, BooleanArray, PrimitiveArray},
bitmap::{Bitmap, MutableBitmap},
Expand All @@ -35,21 +18,16 @@ fn take_values_validity<I: Index>(
values: &BooleanArray,
indices: &[I],
) -> (Bitmap, Option<Bitmap>) {
let mut validity = MutableBitmap::with_capacity(indices.len());

let validity_values = values.validity().unwrap();
let validity = indices
.iter()
.map(|index| validity_values.get_bit(index.to_usize()));
let validity = Bitmap::from_trusted_len_iter(validity);

let values_values = values.values();

let values = indices.iter().map(|index| {
let index = index.to_usize();
if validity_values.get_bit(index) {
validity.push(true);
} else {
validity.push(false);
}
values_values.get_bit(index)
});
let values = indices
.iter()
.map(|index| values_values.get_bit(index.to_usize()));
let buffer = Bitmap::from_trusted_len_iter(values);

(buffer, validity.into())
Expand Down
36 changes: 9 additions & 27 deletions src/compute/take/generic_binary.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// 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.
use crate::{
array::{GenericBinaryArray, Offset, PrimitiveArray},
bitmap::{Bitmap, MutableBitmap},
Expand Down Expand Up @@ -66,25 +50,23 @@ pub fn take_values_validity<O: Offset, I: Index, A: GenericBinaryArray<O>>(
values: &A,
indices: &[I],
) -> (Buffer<O>, Buffer<u8>, Option<Bitmap>) {
let validity_values = values.validity().unwrap();
let validity = indices
.iter()
.map(|index| validity_values.get_bit(index.to_usize()));
let validity = Bitmap::from_trusted_len_iter(validity);

let mut length = O::default();
let mut validity = MutableBitmap::with_capacity(indices.len());

let null_values = values.validity().unwrap();
let offsets = values.offsets();
let values_values = values.values();

let mut starts = MutableBuffer::<O>::with_capacity(indices.len());
let offsets = indices.iter().map(|index| {
let index = index.to_usize();
if null_values.get_bit(index) {
validity.push(true);
let start = offsets[index];
length += offsets[index + 1] - start;
starts.push(start);
} else {
validity.push(false);
starts.push(O::default());
}
let start = offsets[index];
length += offsets[index + 1] - start;
starts.push(start);
length
});
let offsets = std::iter::once(O::default()).chain(offsets);
Expand Down
12 changes: 4 additions & 8 deletions src/compute/take/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ fn take_values_validity<T: NativeType, I: Index>(
) -> (Buffer<T>, Option<Bitmap>) {
let values_validity = values.validity().unwrap();

let validity = indices.iter().map(|index| {
let index = index.to_usize();
values_validity.get_bit(index)
});
let validity = indices
.iter()
.map(|index| values_validity.get_bit(index.to_usize()));
let validity = MutableBitmap::from_trusted_len_iter(validity);

let values_values = values.values();
let values = indices.iter().map(|index| {
let index = index.to_usize();
values_values[index]
});
let values = indices.iter().map(|index| values_values[index.to_usize()]);
let buffer = MutableBuffer::from_trusted_len_iter(values);

(buffer.into(), validity.into())
Expand Down

0 comments on commit 865ad04

Please sign in to comment.