Skip to content

Commit 67b3ddb

Browse files
committed
Add size method to accessor
1 parent 9355217 commit 67b3ddb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libtorchaudio/accessor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using torch::stable::Tensor;
99
template<unsigned int k, typename T, bool IsConst = true>
1010
class Accessor {
1111
int64_t strides[k];
12+
int64_t sizes[k];
1213
T *data;
1314

1415
public:
@@ -19,6 +20,7 @@ class Accessor {
1920
data = static_cast<T*>(raw_ptr);
2021
for (unsigned int i = 0; i < k; i++) {
2122
strides[i] = tensor.stride(i);
23+
sizes[i] = tensor.size(i);
2224
}
2325
}
2426

@@ -33,6 +35,10 @@ class Accessor {
3335
return data[ix];
3436
}
3537

38+
int64_t size(int dim) {
39+
return sizes[dim];
40+
}
41+
3642
template<bool C = IsConst>
3743
typename std::enable_if<!C, void>::type set_index(T value, ...) {
3844
va_list args;

0 commit comments

Comments
 (0)