Skip to content

Commit 948ff7d

Browse files
committed
Do not use instantiate NumericTensor<T> in tensor.cc
Change-Id: Icefc4ad36e686fa5f4a65d9fd6ac02e9bd98427b
1 parent a688a3e commit 948ff7d

File tree

3 files changed

+31
-67
lines changed

3 files changed

+31
-67
lines changed

cpp/src/arrow/sparse_tensor.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,18 @@ class SparseTensorConverter<TYPE, SparseCSRIndex>
264264
// ----------------------------------------------------------------------
265265
// Instantiate templates
266266

267-
#define INSTANTIATE_SPARSE_TENSOR_CONVERTER(IndexType) \
268-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<UInt8Type, IndexType>; \
269-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<UInt16Type, IndexType>; \
270-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<UInt32Type, IndexType>; \
271-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<UInt64Type, IndexType>; \
272-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<Int8Type, IndexType>; \
273-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<Int16Type, IndexType>; \
274-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<Int32Type, IndexType>; \
275-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<Int64Type, IndexType>; \
276-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<HalfFloatType, IndexType>; \
277-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<FloatType, IndexType>; \
278-
template class ARROW_TEMPLATE_EXPORT SparseTensorConverter<DoubleType, IndexType>
267+
#define INSTANTIATE_SPARSE_TENSOR_CONVERTER(IndexType) \
268+
template class SparseTensorConverter<UInt8Type, IndexType>; \
269+
template class SparseTensorConverter<UInt16Type, IndexType>; \
270+
template class SparseTensorConverter<UInt32Type, IndexType>; \
271+
template class SparseTensorConverter<UInt64Type, IndexType>; \
272+
template class SparseTensorConverter<Int8Type, IndexType>; \
273+
template class SparseTensorConverter<Int16Type, IndexType>; \
274+
template class SparseTensorConverter<Int32Type, IndexType>; \
275+
template class SparseTensorConverter<Int64Type, IndexType>; \
276+
template class SparseTensorConverter<HalfFloatType, IndexType>; \
277+
template class SparseTensorConverter<FloatType, IndexType>; \
278+
template class SparseTensorConverter<DoubleType, IndexType>
279279

280280
INSTANTIATE_SPARSE_TENSOR_CONVERTER(SparseCOOIndex);
281281
INSTANTIATE_SPARSE_TENSOR_CONVERTER(SparseCSRIndex);

cpp/src/arrow/tensor.cc

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -123,50 +123,4 @@ Type::type Tensor::type_id() const { return type_->id(); }
123123

124124
bool Tensor::Equals(const Tensor& other) const { return TensorEquals(*this, other); }
125125

126-
// ----------------------------------------------------------------------
127-
// NumericTensor
128-
129-
template <typename TYPE>
130-
NumericTensor<TYPE>::NumericTensor(const std::shared_ptr<Buffer>& data,
131-
const std::vector<int64_t>& shape)
132-
: NumericTensor(data, shape, {}, {}) {}
133-
134-
template <typename TYPE>
135-
NumericTensor<TYPE>::NumericTensor(const std::shared_ptr<Buffer>& data,
136-
const std::vector<int64_t>& shape,
137-
const std::vector<int64_t>& strides)
138-
: NumericTensor(data, shape, strides, {}) {}
139-
140-
template <typename TYPE>
141-
NumericTensor<TYPE>::NumericTensor(const std::shared_ptr<Buffer>& data,
142-
const std::vector<int64_t>& shape,
143-
const std::vector<int64_t>& strides,
144-
const std::vector<std::string>& dim_names)
145-
: Tensor(TypeTraits<TYPE>::type_singleton(), data, shape, strides, dim_names) {}
146-
147-
template <typename TYPE>
148-
int64_t NumericTensor<TYPE>::CalculateValueOffset(
149-
const std::vector<int64_t>& index) const {
150-
int64_t offset = 0;
151-
for (size_t i = 0; i < index.size(); ++i) {
152-
offset += index[i] * strides_[i];
153-
}
154-
return offset;
155-
}
156-
157-
// ----------------------------------------------------------------------
158-
// Instantiate templates
159-
160-
template class ARROW_TEMPLATE_EXPORT NumericTensor<UInt8Type>;
161-
template class ARROW_TEMPLATE_EXPORT NumericTensor<UInt16Type>;
162-
template class ARROW_TEMPLATE_EXPORT NumericTensor<UInt32Type>;
163-
template class ARROW_TEMPLATE_EXPORT NumericTensor<UInt64Type>;
164-
template class ARROW_TEMPLATE_EXPORT NumericTensor<Int8Type>;
165-
template class ARROW_TEMPLATE_EXPORT NumericTensor<Int16Type>;
166-
template class ARROW_TEMPLATE_EXPORT NumericTensor<Int32Type>;
167-
template class ARROW_TEMPLATE_EXPORT NumericTensor<Int64Type>;
168-
template class ARROW_TEMPLATE_EXPORT NumericTensor<HalfFloatType>;
169-
template class ARROW_TEMPLATE_EXPORT NumericTensor<FloatType>;
170-
template class ARROW_TEMPLATE_EXPORT NumericTensor<DoubleType>;
171-
172126
} // namespace arrow

cpp/src/arrow/tensor.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "arrow/buffer.h"
2727
#include "arrow/type.h"
28+
#include "arrow/type_traits.h"
2829
#include "arrow/util/macros.h"
2930
#include "arrow/util/visibility.h"
3031

@@ -121,22 +122,25 @@ class ARROW_EXPORT Tensor {
121122
};
122123

123124
template <typename TYPE>
124-
class ARROW_EXPORT NumericTensor : public Tensor {
125+
class NumericTensor : public Tensor {
125126
public:
126127
using TypeClass = TYPE;
127128
using value_type = typename TypeClass::c_type;
128129

130+
/// Constructor with non-negative strides and dimension names
131+
NumericTensor(const std::shared_ptr<Buffer>& data, const std::vector<int64_t>& shape,
132+
const std::vector<int64_t>& strides,
133+
const std::vector<std::string>& dim_names)
134+
: Tensor(TypeTraits<TYPE>::type_singleton(), data, shape, strides, dim_names) {}
135+
129136
/// Constructor with no dimension names or strides, data assumed to be row-major
130-
NumericTensor(const std::shared_ptr<Buffer>& data, const std::vector<int64_t>& shape);
137+
NumericTensor(const std::shared_ptr<Buffer>& data, const std::vector<int64_t>& shape)
138+
: NumericTensor(data, shape, {}, {}) {}
131139

132140
/// Constructor with non-negative strides
133141
NumericTensor(const std::shared_ptr<Buffer>& data, const std::vector<int64_t>& shape,
134-
const std::vector<int64_t>& strides);
135-
136-
/// Constructor with non-negative strides and dimension names
137-
NumericTensor(const std::shared_ptr<Buffer>& data, const std::vector<int64_t>& shape,
138-
const std::vector<int64_t>& strides,
139-
const std::vector<std::string>& dim_names);
142+
const std::vector<int64_t>& strides)
143+
: NumericTensor(data, shape, strides, {}) {}
140144

141145
const value_type& Value(const std::vector<int64_t>& index) const {
142146
int64_t offset = CalculateValueOffset(index);
@@ -145,7 +149,13 @@ class ARROW_EXPORT NumericTensor : public Tensor {
145149
}
146150

147151
protected:
148-
int64_t CalculateValueOffset(const std::vector<int64_t>& index) const;
152+
int64_t CalculateValueOffset(const std::vector<int64_t>& index) const {
153+
int64_t offset = 0;
154+
for (size_t i = 0; i < index.size(); ++i) {
155+
offset += index[i] * strides_[i];
156+
}
157+
return offset;
158+
}
149159
};
150160

151161
} // namespace arrow

0 commit comments

Comments
 (0)