auto temp_link_p = WSLoopbackOpen(env_p, &err);
if (err != WSEOK) { /* error ... */ }
array_meterp am;
long depth;
mlapi__token leaf_token; // this token seems unused
if (!WSGetArrayTypeWithDepthAndLeafType(link_p, temp_link_p, &am, &depth, &leaf_token)) {
/* error ... */
}
size_t total_size = 1;
const char *head_p;
int argcount;
vector<int> shape;
vector<string> heads;
for (int i=0; i<depth; ++i) {
WSGetFunction(temp_link_p, &head_p, &argcount);
total_size *= argcount;
shape.push_back(argcount);
heads.push_back(string(head_p));
WSReleaseSymbol(link_p, head_p);
}
auto elem_token = WSGetRawType(link_p);
switch (elem_token) {
case WSTK_CDOUBLE:
total_size *= sizeof(double);
break;
case WSTK_CFLOAT:
total_size *= sizeof(float);
break;
/* case ... */
default:
/* error ... */
break;
}
void *array_data = malloc(total_size);
WSGetBinaryNumberArrayData(link_p, am, array_data, total_size, elem_token);
WSReleaseGetArrayState(link_p, temp_link_p, am);
WSClose(temp_link_p);
for (int i=0; i<16; ++i) {
printf("%f\n", ((double*)array_data)[i]);
}
/* do stuff with array */
free(array_data);
vector<int> shape;
vector<string> heads;
size_t total_size = 1;
const char *head_p;
int argcount;
int elem_token;
auto mark = WSCreateMark(link_p);
do {
WSGetFunction(link_p, &head_p, &argcount);
total_size *= argcount;
shape.push_back(argcount);
heads.push_back(string(head_p));
WSReleaseSymbol(link_p, head_p);
elem_token = WSGetRawType(link_p);
} while (elem_token == WSTKFUNC);
switch (elem_token) {
case WSTK_CDOUBLE:
total_size *= sizeof(double);
break;
case WSTK_CFLOAT:
total_size *= sizeof(float);
break;
/* case ... */
default:
/* error ... */
break;
}
WSSeekToMark(link_p, mark, 0);
WSDestroyMark(link_p, mark);
void *array_data;
long *received_dims;
char **received_heads;
long received_depth;
WSGetBinaryNumberArray(
link_p, &array_data, &received_dims, &received_heads, &received_depth, elem_token);
/* do stuff with array */
// there is a int/long mismatch on received_dims, I don't understand why
WSReleaseBinaryNumberArray(
link_p, array_data, (int*)received_dims, received_heads, total_size, elem_token);
free(array_data);
array_meterp
is pointer to an opaque internal struct, likely holding array metadata.WSGetBinaryNumberArray*
is using platform specific type tokens. They can be found inwstp.h
.As of WSTP v4,
WSGet*Array
(e.g WSGetInteger64Array) are wrappers toWSGetBinaryNumberArray
.Temporary link in method 1 just store function heads, attempts to retrieve full exrepssion may fail.
Generally the heads in each level are "List".
The last head can be "Complex" in case of complex data type. E.g a complex unitary matrix would have 3 depth levels
List
,List
, andComplex
.