VECTOR_MUL

Multiplies two vector blobs and returns a single vector blob.

It is a scalar function.

Syntax

VECTOR_MUL(vector_expression, vector_expression)

Arguments

  • vector_expression: An expression that evaluates to a vector. The vector must be encoded as a blob containing packed single-precision or double-precision floating-point numbers in little-endian byte order.

Return Type

A blob containing packed single-precision floating-point numbers in little-endian byte order.

Remarks

A vector can be of any length, but the input blob length must be divisible by the packed vector element size (1, 2, 4 or 8 bytes, depending on the vector element).

You can specify the data type of the vector elements in which this operation is performed on the vector by adding a suffix to the function. Omitting the suffix from the function is equivalent to suffixing it with _F32. All operations are done using the specified data type. The following table lists the suffixes and their data type.

Suffix

Data Type

_I8

8-bit signed integer

_I16

16-bit signed integer

_I32

32-bit signed integer

_I64

64-bit signed integer

_F32

32-bit floating-point number (IEEE standard format)

_F64

64-bit floating-point number (IEEE standard format)

Examples

The following queries use the JSON_ARRAY_UNPACK() function to view the output in JSON format.

Multiplying Two Vectors

The following example multiplies two vectors using the VECTOR_MUL function:

SELECT JSON_ARRAY_UNPACK(VECTOR_MUL(JSON_ARRAY_PACK('[12.1,2.2]'),JSON_ARRAY_PACK('[8.3,4.6]'))) AS "Result";
+-------------------------+
| Result                  |
+-------------------------+
| [100.430008,10.1199999] |
+-------------------------+

You can also view the vector blob in hexadecimal format using the HEX() function.

SELECT HEX(VECTOR_MUL(JSON_ARRAY_PACK('[12.1,2.2]'),JSON_ARRAY_PACK('[8.3,4.6]'))) AS "Result";
+------------------+
| Result           |
+------------------+
| 2ADCC84285EB2141 |
+------------------+

Typecasting the Data using Suffixes

To perform this operation on vectors specified in a format other than the default 32-bit floating point number, specify a suffix with the VECTOR_MUL() function. For example,

SELECT JSON_ARRAY_UNPACK_I16(VECTOR_MUL_I16(JSON_ARRAY_PACK_I16('[6,2]'),JSON_ARRAY_PACK_I16('[8,4]'))) AS "Result";
+--------+
| Result |
+--------+
| [48,8] |
+--------+

Last modified: December 19, 2023

Was this article helpful?