compute a general inner product of two Arrays
Array, list, or expression
function to reduce the results of calls to g
function applied to pairs of values from X and Y
(optional) one or more options
GeneralInnerProduct(X,f,g,Y) accepts two Arrays, X and Y, with N and M dimensions respectively and where the last dimension of X matches the first dimension of Y. The result is an Array with N+M-2 dimensions.
For each combination of the first N-1 indices of X and last M-1 indices of Y, the function g is applied to the corresponding pairs of the last dimension of X and the first of Y, and the values returned by those calls to g are accumulated by f.
When f is the addition function (`+`) and g the multiplication function (`*`), and X and Y are matrices or vectors, GeneralInnerProduct is equivalent to matrix/vector multiplication.
Unlike matrix multiplication, GeneralInnerProduct is not restricted to one- and two-dimensional Arrays, and is not restricted to multiplying values and adding the results.
If X or Y is a list, it is treated as a one-dimensional Array.
If X is not an Array or list, a one-dimensional Array whose dimension matches the first dimension of Y is created and filled with the value of X.
Similarly, if Y is not an Array or list, an Array matching the last dimension of X is created and filled with Y.
By default, the datatype of the resulting Array is determined by SuggestedDatatype based on the two inputs. Depending on f or g, this may not be suitable. For example, if X and Y have datatype integer and f and g are `+` and `*` respectively, the computed values might be too large to store in that datatype.
The option ':-datatype'=dt, where dt is a valid Array datatype, can be used to override the default datatype for the result.
If option evalhf or evalhf=true is passed, the arguments passed to each call to f and g are first evaluated to hardware floating-point using evalhf, as is the result returned by them. Furthermore, unless the datatype option was specified, the resulting Array has datatype float.
The subtype of the result depends on the subtypes of X and Y, as described by SuggestedSubtype. The option ':-subtype'=st', where st is a valid rtable subtype, overrides the default subtype.
The storage order of the result is based on the storage orders of X and Y, as described by SuggestedOrder. This can be overridden using the option :-order=ord, where ord is one of C_order or Fortran_order.
This function is part of the ArrayTools package, so it can be used in the short form GeneralInnerProduct(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[GeneralInnerProduct](..).
M1 ≔ LinearAlgebra:-RandomMatrix⁡3,2
M2 ≔ LinearAlgebra:-RandomMatrix⁡2,3
Using relation and Boolean functions to determine characteristics of a Vector:
V ≔ 1|2|4|8|16|32|64|128
Are all values less than 80?
Are any values less than 20?
Using relation and Boolean functions to determine characteristics of rows of a Matrix:
MN ≔ 1|2|3|4,5|6|0|7,8|9|10|11,0|0|0|0,12|13|14|15
Which are all zero?
Which contain at least one zero?
Which contain at least one nonzero element?
The order of X and Y can be reversed to test columns:
Which contain only values <= 13?
GeneralInnerProduct works with more than two dimensions.
A1 ≔ Array⁡a,b,c,d,e,f,g,h
A2 ≔ Array⁡1,2,3,4
R ≔ GeneralInnerProduct⁡A1,f,`/`,A2
The datatype option can be used if the default datatype would not be suitable for the result.
A ≔ Matrix⁡1,5,10,20,datatype=integer1
Error, (in ArrayTools:-GeneralInnerProduct) unable to store '210' when datatype=integer
GeneralInnerProduct can perform operations on ImageTools images. This example converts an RGB image to gray scale, primarily based on the green channel:
img ≔ SampleImage⁡3
bw ≔ GeneralInnerProduct⁡img,`+`,`*`,0.1,0.8,0.1,datatype=float8
The ArrayTools[GeneralInnerProduct] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
Download Help Document