Skip to content
Closed
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
8 changes: 8 additions & 0 deletions c_glib/arrow-glib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ libarrow_glib_la_headers = \
int8-array.h \
int8-array-builder.h \
int8-data-type.h \
int8-tensor.h \
int16-array.h \
int16-array-builder.h \
int16-data-type.h \
Expand All @@ -88,10 +89,12 @@ libarrow_glib_la_headers = \
struct-array-builder.h \
struct-data-type.h \
table.h \
tensor.h \
type.h \
uint8-array.h \
uint8-array-builder.h \
uint8-data-type.h \
uint8-tensor.h \
uint16-array.h \
uint16-array-builder.h \
uint16-data-type.h \
Expand Down Expand Up @@ -152,6 +155,7 @@ libarrow_glib_la_sources = \
int8-array.cpp \
int8-array-builder.cpp \
int8-data-type.cpp \
int8-tensor.cpp \
int16-array.cpp \
int16-array-builder.cpp \
int16-data-type.cpp \
Expand All @@ -175,10 +179,12 @@ libarrow_glib_la_sources = \
struct-array-builder.cpp \
struct-data-type.cpp \
table.cpp \
tensor.cpp \
type.cpp \
uint8-array.cpp \
uint8-array-builder.cpp \
uint8-data-type.cpp \
uint8-tensor.cpp \
uint16-array.cpp \
uint16-array-builder.cpp \
uint16-data-type.cpp \
Expand Down Expand Up @@ -220,9 +226,11 @@ libarrow_glib_la_cpp_headers = \
data-type.hpp \
error.hpp \
field.hpp \
numeric-tensor.hpp \
record-batch.hpp \
schema.hpp \
table.hpp \
tensor.hpp \
type.hpp

libarrow_glib_la_cpp_headers += \
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/arrow-glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <arrow-glib/int8-array.h>
#include <arrow-glib/int8-array-builder.h>
#include <arrow-glib/int8-data-type.h>
#include <arrow-glib/int8-tensor.h>
#include <arrow-glib/int16-array.h>
#include <arrow-glib/int16-array-builder.h>
#include <arrow-glib/int16-data-type.h>
Expand All @@ -65,10 +66,12 @@
#include <arrow-glib/struct-array-builder.h>
#include <arrow-glib/struct-data-type.h>
#include <arrow-glib/table.h>
#include <arrow-glib/tensor.h>
#include <arrow-glib/type.h>
#include <arrow-glib/uint8-array.h>
#include <arrow-glib/uint8-array-builder.h>
#include <arrow-glib/uint8-data-type.h>
#include <arrow-glib/uint8-tensor.h>
#include <arrow-glib/uint16-array.h>
#include <arrow-glib/uint16-array-builder.h>
#include <arrow-glib/uint16-data-type.h>
Expand Down
2 changes: 2 additions & 0 deletions c_glib/arrow-glib/arrow-glib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#include <arrow-glib/error.hpp>
#include <arrow-glib/field.hpp>
#include <arrow-glib/float-array.hpp>
#include <arrow-glib/numeric-tensor.hpp>
#include <arrow-glib/record-batch.h>
#include <arrow-glib/schema.hpp>
#include <arrow-glib/table.hpp>
#include <arrow-glib/tensor.hpp>
#include <arrow-glib/type.hpp>

#include <arrow-glib/file.hpp>
Expand Down
105 changes: 105 additions & 0 deletions c_glib/arrow-glib/int8-tensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <arrow-glib/buffer.hpp>
#include <arrow-glib/int8-tensor.h>
#include <arrow-glib/numeric-tensor.hpp>

G_BEGIN_DECLS

/**
* SECTION: int8-tensor
* @short_description: 8-bit integer tensor class
*
* #GArrowInt8Tensor is a class for 8-bit integer tensor. It can store
* zero or more 8-bit integer data.
*/

G_DEFINE_TYPE(GArrowInt8Tensor, \
garrow_int8_tensor, \
GARROW_TYPE_TENSOR)

static void
garrow_int8_tensor_init(GArrowInt8Tensor *object)
{
}

static void
garrow_int8_tensor_class_init(GArrowInt8TensorClass *klass)
{
}

/**
* garrow_int8_tensor_new:
* @data: A #GArrowBuffer that contains tensor data.
* @shape: (array length=n_dimensions): A list of dimension sizes.
* @n_dimensions: The number of dimensions.
* @strides: (array length=n_strides) (nullable): A list of the number of
* bytes in each dimension.
* @n_strides: The number of strides.
* @dimention_names: (array length=n_dimention_names) (nullable): A list of
* dimension names.
* @n_dimention_names: The number of dimension names
*
* Returns: The newly created #GArrowInt8Tensor.
*
* Since: 0.3.0
*/
GArrowInt8Tensor *
garrow_int8_tensor_new(GArrowBuffer *data,
gint64 *shape,
gsize n_dimensions,
gint64 *strides,
gsize n_strides,
gchar **dimension_names,
gsize n_dimension_names)
{
auto tensor =
garrow::numeric_tensor_new<arrow::Int8Tensor>(data,
shape,
n_dimensions,
strides,
n_strides,
dimension_names,
n_dimension_names);
return GARROW_INT8_TENSOR(tensor);
}

/**
* garrow_int8_tensor_get_raw_data:
* @tensor: A #GArrowInt8Tensor.
* @n_data: (out): The number of data.
*
* Returns: (array length=n_data): The raw data in the tensor.
*
* Since: 0.3.0
*/
const gint8 *
garrow_int8_tensor_get_raw_data(GArrowInt8Tensor *tensor,
gint64 *n_data)
{
return garrow::numeric_tensor_get_raw_data<arrow::Int8Tensor, int8_t>(GARROW_TENSOR(tensor),
n_data);
}

G_END_DECLS
79 changes: 79 additions & 0 deletions c_glib/arrow-glib/int8-tensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.
*/

#pragma once

#include <arrow-glib/tensor.h>

G_BEGIN_DECLS

#define GARROW_TYPE_INT8_TENSOR \
(garrow_int8_tensor_get_type())
#define GARROW_INT8_TENSOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GARROW_TYPE_INT8_TENSOR, \
GArrowInt8Tensor))
#define GARROW_INT8_TENSOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GARROW_TYPE_INT8_TENSOR, \
GArrowInt8TensorClass))
#define GARROW_IS_INT8_TENSOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
GARROW_TYPE_INT8_TENSOR))
#define GARROW_IS_INT8_TENSOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), \
GARROW_TYPE_INT8_TENSOR))
#define GARROW_INT8_TENSOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GARROW_TYPE_INT8_TENSOR, \
GArrowInt8TensorClass))

typedef struct _GArrowInt8Tensor GArrowInt8Tensor;
typedef struct _GArrowInt8TensorClass GArrowInt8TensorClass;

/**
* GArrowInt8Tensor:
*
* It wraps `arrow::Int8Tensor`.
*/
struct _GArrowInt8Tensor
{
/*< private >*/
GArrowTensor parent_instance;
};

struct _GArrowInt8TensorClass
{
GArrowTensorClass parent_class;
};

GType garrow_int8_tensor_get_type(void) G_GNUC_CONST;

GArrowInt8Tensor *garrow_int8_tensor_new(GArrowBuffer *data,
gint64 *shape,
gsize n_dimensions,
gint64 *strides,
gsize n_strides,
gchar **dimention_names,
gsize n_dimention_names);

const gint8 *garrow_int8_tensor_get_raw_data(GArrowInt8Tensor *tensor,
gint64 *n_data);

G_END_DECLS
64 changes: 64 additions & 0 deletions c_glib/arrow-glib/numeric-tensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.
*/

#pragma once

#include <arrow-glib/tensor.hpp>

namespace garrow {
template <typename T>
GArrowTensor *numeric_tensor_new(GArrowBuffer *data,
gint64 *shape,
gsize n_dimensions,
gint64 *strides,
gsize n_strides,
gchar **dimention_names,
gsize n_dimention_names) {
auto arrow_data = garrow_buffer_get_raw(data);
std::vector<int64_t> arrow_shape;
for (gsize i = 0; i < n_dimensions; ++i) {
arrow_shape.push_back(shape[i]);
}
std::vector<int64_t> arrow_strides;
for (gsize i = 0; i < n_strides; ++i) {
arrow_strides.push_back(strides[i]);
}
std::vector<std::string> arrow_dimention_names;
for (gsize i = 0; i < n_dimention_names; ++i) {
arrow_dimention_names.push_back(dimention_names[i]);
}
auto arrow_numeric_tensor =
std::make_shared<T>(arrow_data,
arrow_shape,
arrow_strides,
arrow_dimention_names);
std::shared_ptr<arrow::Tensor> arrow_tensor = arrow_numeric_tensor;
auto tensor = garrow_tensor_new_raw(&arrow_tensor);
return tensor;
}

template <typename T, typename value_type>
const value_type *numeric_tensor_get_raw_data(GArrowTensor *tensor,
gint64 *n_data) {
auto arrow_tensor = garrow_tensor_get_raw(tensor);
auto arrow_numeric_tensor = static_cast<const T *>(arrow_tensor.get());
*n_data = arrow_numeric_tensor->size();
return arrow_numeric_tensor->raw_data();
}
}
Loading