Skip to content

Let TENSORGET command return BLOB+META by default #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Depending on the specified reply format:
1. The tensor's shape as an Array consisting of an item per dimension
* **BLOB**: the tensor's binary data as a String. If used together with the **META** option, the binary data string will put after the metadata in the array reply.
* **VALUES**: Array containing the numerical representation of the tensor's data. If used together with the **META** option, the binary data string will put after the metadata in the array reply.

* Default: **META** and **BLOB** are returned by default, in case that non of the arguments above is specified.


**Examples**
Expand Down
3 changes: 3 additions & 0 deletions src/tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ uint ParseTensorGetArgs(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
RedisModule_WrongArity(ctx);
return fmt;
}
if (argc == 2) {
return TENSOR_BLOB | TENSOR_META;
}
for (int i = 2; i < argc; i++) {
const char *fmtstr = RedisModule_StringPtrLen(argv[i], NULL);
if (!strcasecmp(fmtstr, "BLOB")) {
Expand Down
10 changes: 10 additions & 0 deletions tests/flow/tests_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ def test_common_tensorget(env):
env.assertEqual(datatype.encode('utf-8'), tensor_dtype)
env.assertEqual([2], tensor_dim)

# Confirm that default reply format is META BLOB
for datatype in tested_datatypes:
_, tensor_dtype, _, tensor_dim, _, tensor_blob = con.execute_command('AI.TENSORGET', 'tensor_{0}'.format(datatype),
'META', 'BLOB')
_, tensor_dtype_default, _, tensor_dim_default, _, tensor_blob_default = con.execute_command('AI.TENSORGET',
'tensor_{0}'.format(datatype))
env.assertEqual(tensor_dtype, tensor_dtype_default)
env.assertEqual(tensor_dim, tensor_dim_default)
env.assertEqual(tensor_blob, tensor_blob_default)


def test_common_tensorget_error_replies(env):
con = env.getConnection()
Expand Down