Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start flatten implementation and add tests (#45)
Implements `flatten` for all `Content` types that existed at the start of this PR (not `IndexedArray`) for `axis=0`. * start flatten implementation and add tests * [skip ci] correct EmptyArray * [skip ci] correct Record * [skip ci] correct RegularArray * [skip ci] correct RawArray * Example of an extreme (but legal) ListArray. * Keep version number ahead of latest release. * [skip ci] operations in cpu kernels * [skip ci] cleanup debugging messages * [skip ci] restructure functions * use offsets in calculations * [skip ci] address Jim's comments to fix ListArray and add more tests * flatten non contiguous NumpyArray Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
298 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// BSD 3-Clause License; see https://github.com/jpivarski/awkward-1.0/blob/master/LICENSE | ||
|
||
#ifndef AWKWARDCPU_OPERATIONS_H_ | ||
#define AWKWARDCPU_OPERATIONS_H_ | ||
|
||
#include "awkward/cpu-kernels/util.h" | ||
|
||
extern "C" { | ||
EXPORT_SYMBOL struct Error awkward_listarray32_flatten_length_64(int64_t* tolen, const int32_t* fromstarts, const int32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
EXPORT_SYMBOL struct Error awkward_listarrayU32_flatten_length_64(int64_t* tolen, const uint32_t* fromstarts, const uint32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
EXPORT_SYMBOL struct Error awkward_listarray64_flatten_length_64(int64_t* tolen, const int64_t* fromstarts, const int64_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
EXPORT_SYMBOL struct Error awkward_listarray32_flatten_64(int64_t* tocarry, const int32_t* fromstarts, const int32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
EXPORT_SYMBOL struct Error awkward_listarrayU32_flatten_64(int64_t* tocarry, const uint32_t* fromstarts, const uint32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
EXPORT_SYMBOL struct Error awkward_listarray64_flatten_64(int64_t* tocarry, const int64_t* fromstarts, const int64_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset); | ||
} | ||
|
||
#endif // AWKWARDCPU_GETITEM_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// BSD 3-Clause License; see https://github.com/jpivarski/awkward-1.0/blob/master/LICENSE | ||
|
||
#include <cstring> | ||
|
||
#include "awkward/cpu-kernels/operations.h" | ||
template <typename C> | ||
ERROR awkward_listarray_flatten_length(int64_t* tolen, const C* fromstarts, const C* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
*tolen = 0; | ||
for (int64_t i = 0; i < lenstarts; i++) { | ||
int64_t start = (C)fromstarts[startsoffset + i]; | ||
int64_t stop = (C)fromstops[stopsoffset + i]; | ||
if (start < 0 || stop < 0) { | ||
return failure("all start and stop values must be non-negative", kSliceNone, i); | ||
} | ||
int64_t length = stop - start; | ||
*tolen += length; | ||
} | ||
return success(); | ||
} | ||
ERROR awkward_listarray32_flatten_length_64(int64_t* tolen, const int32_t* fromstarts, const int32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten_length<int32_t>(tolen, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} | ||
ERROR awkward_listarrayU32_flatten_length_64(int64_t* tolen, const uint32_t* fromstarts, const uint32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten_length<uint32_t>(tolen, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} | ||
ERROR awkward_listarray64_flatten_length_64(int64_t* tolen, const int64_t* fromstarts, const int64_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten_length<int64_t>(tolen, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} | ||
|
||
template <typename C, typename T> | ||
ERROR awkward_listarray_flatten(T* tocarry, const C* fromstarts, const C* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
int64_t at = 0; | ||
for (int64_t i = 0; i < lenstarts; i++) { | ||
int64_t start = (C)fromstarts[startsoffset + i]; | ||
int64_t stop = (C)fromstops[stopsoffset + i]; | ||
if (start < 0 || stop < 0) { | ||
return failure("all start and stop values must be non-negative", kSliceNone, i); | ||
} | ||
int64_t length = stop - start; | ||
if (length > 0) { | ||
for(int64_t l = 0; l < length; l++) { | ||
tocarry[at] = start + l; | ||
++at; | ||
} | ||
} | ||
} | ||
return success(); | ||
} | ||
ERROR awkward_listarray32_flatten_64(int64_t* tocarry, const int32_t* fromstarts, const int32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten<int32_t, int64_t>(tocarry, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} | ||
ERROR awkward_listarrayU32_flatten_64(int64_t* tocarry, const uint32_t* fromstarts, const uint32_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten<uint32_t, int64_t>(tocarry, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} | ||
ERROR awkward_listarray64_flatten_64(int64_t* tocarry, const int64_t* fromstarts, const int64_t* fromstops, const int64_t lenstarts, int64_t startsoffset, int64_t stopsoffset) { | ||
return awkward_listarray_flatten<int64_t, int64_t>(tocarry, fromstarts, fromstops, lenstarts, startsoffset, stopsoffset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.