Skip to content

Commit

Permalink
Bugfix: return correct nbytes value for multidimensional NumPy arra…
Browse files Browse the repository at this point in the history
…ys (#928)

* Test: test for #927

* Bugfix: fix #927
  • Loading branch information
agoose77 authored Jun 15, 2021
1 parent 2590928 commit 7c8ae87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libawkward/array/NumpyArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@ namespace awkward {
void
NumpyArray::nbytes_part(std::map<size_t, int64_t>& largest) const {
int64_t len = 1;
if (!shape_.empty()) {
len = shape_[0];
for (auto size: shape_) {
len *= size;
}
size_t x = (size_t)ptr_.get();
auto it = largest.find(x);
Expand Down
13 changes: 13 additions & 0 deletions tests/test_0927-numpy-array-nbytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

from __future__ import absolute_import

import pytest # noqa: F401
import numpy as np # noqa: F401
import awkward as ak # noqa: F401


def test():
np_data = np.random.random(size=(4, 100 * 1024 * 1024 // 8 // 4))
array = ak.from_numpy(np_data, regulararray=False)
assert np_data.nbytes == array.nbytes

0 comments on commit 7c8ae87

Please sign in to comment.