-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add interface to build npy_array_list objects from C * rename to deepcopy * deepcopy and shallow copy * fix readme * add copying example to workflow * left a note in copying.c for having the same data as copying_read.c --------- Co-authored-by: alcubierre-drive <>
- Loading branch information
1 parent
80a0b2c
commit cab5548
Showing
7 changed files
with
129 additions
and
15 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
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,25 @@ | ||
#include "npy_array_list.h" | ||
|
||
// the first block must be the same as in copying_read.c | ||
int main(int argc, char *argv[]) | ||
{ | ||
const char* fname = (argc != 2) ? "copy.npz" : argv[1]; | ||
|
||
const double data[] = {0,1,2, 3,4,5}; | ||
const int32_t idata[] = {0,1, 2,3, | ||
4,5, 6,7, | ||
8,9, 10,11}; | ||
const char names[][8] = { "double", "int" }; | ||
|
||
npy_array_list_t* list = NULL; | ||
|
||
// the first npy_array_t* holds a reference to the data array | ||
list = npy_array_list_append( list, | ||
NPY_ARRAY_BUILDER_COPY(data, SHAPE(2,3), NPY_DTYPE_FLOAT64), names[0] ); | ||
// the second npy_array_t* holds a copy of the data array (hence DEEPCOPY) | ||
list = npy_array_list_append( list, | ||
NPY_ARRAY_BUILDER_DEEPCOPY(idata, SHAPE(3,2,2), NPY_DTYPE_INT32), names[1] ); | ||
|
||
npy_array_list_save_compressed( fname, list, ZIP_CM_DEFAULT, 0 ); | ||
npy_array_list_free( list ); | ||
} |
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,58 @@ | ||
#include "npy_array_list.h" | ||
|
||
#include <string.h> | ||
#define MIN(x,y) ((x)<(y)?(x):(y)) | ||
|
||
// the first block must be the same as in copying.c | ||
int main(int argc, char *argv[]) | ||
{ | ||
const char* fname = (argc != 2) ? "copy.npz" : argv[1]; | ||
|
||
const double data[] = {0,1,2, 3,4,5}; | ||
const int32_t idata[] = {0,1, 2,3, | ||
4,5, 6,7, | ||
8,9, 10,11}; | ||
const char names[][8] = { "double", "int" }; | ||
|
||
// we load the file and check whether it contains the same data | ||
npy_array_list_t *list = npy_array_list_load( fname ); | ||
|
||
int errors = 0; | ||
int visited_data = 0, | ||
visited_idata = 0; | ||
npy_array_list_t *elem = list; | ||
while (elem != NULL) { | ||
npy_array_t* ary = elem->array; | ||
size_t ary_sz = npy_array_calculate_datasize( ary ); | ||
|
||
char* cmp = NULL; | ||
size_t cmp_sz = 0; | ||
|
||
if (!strcmp( elem->filename, names[0] )) { | ||
cmp = (char*)data; | ||
cmp_sz = sizeof(data); | ||
visited_data++; | ||
} else if (!strcmp( elem->filename, names[1] )) { | ||
cmp = (char*)idata; | ||
cmp_sz = sizeof(idata); | ||
visited_idata++; | ||
} | ||
|
||
errors += (cmp_sz != ary_sz); | ||
if (cmp != NULL) { | ||
errors += (memcmp( ary->data, cmp, MIN(cmp_sz,ary_sz) ) != 0); | ||
} else { | ||
errors++; | ||
} | ||
|
||
elem = elem->next; | ||
} | ||
|
||
errors += (visited_data != 1); | ||
errors += (visited_idata != 1); | ||
|
||
npy_array_list_free( list ); | ||
|
||
// we return the number of errors/inconsistencies | ||
return errors; | ||
} |
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