GeneralInnerProduct - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ArrayTools

  

GeneralInnerProduct

  

compute a general inner product of two Arrays

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

GeneralInnerProduct(X,f,g,Y,opts)

Parameters

X

-

Array, list, or expression

f

-

function to reduce the results of calls to g

g

-

function applied to pairs of values from X and Y

Y

-

Array, list, or expression

opts

-

(optional) one or more options

Description

• 

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[1] 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[8].

• 

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](..).

Examples

withArrayTools:

M1LinearAlgebra:-RandomMatrix3,2

M1

(4.1)

M2LinearAlgebra:-RandomMatrix2,3

M2

(4.2)

GeneralInnerProductM1,`+`,`*`,M2

(4.3)

LinearAlgebra:-MultiplyM1,M2

(4.4)

Using relation and Boolean functions to determine characteristics of a Vector:

V1|2|4|8|16|32|64|128

V

(4.5)

Are all values less than 80?

GeneralInnerProductV&comma;`and`&comma;`<`&comma;80

false

(4.6)

Are any values less than 20?

GeneralInnerProductV&comma;`or`&comma;`<`&comma;20

true

(4.7)

Using relation and Boolean functions to determine characteristics of rows of a Matrix:

MN1|2|3|4&comma;5|6|0|7&comma;8|9|10|11&comma;0|0|0|0&comma;12|13|14|15

MN

(4.8)

Which are all zero?

GeneralInnerProductMN&comma;`and`&comma;`=`&comma;0

(4.9)

Which contain at least one zero?

GeneralInnerProductMN&comma;`or`&comma;`=`&comma;0

(4.10)

Which contain at least one nonzero element?

GeneralInnerProductMN&comma;`or`&comma;`<>`&comma;0

(4.11)

The order of X and Y can be reversed to test columns:

Which are all zero?

GeneralInnerProduct0&comma;`and`&comma;`=`&comma;MN

(4.12)

Which contain at least one zero?

GeneralInnerProduct0&comma;`or`&comma;`=`&comma;MN

(4.13)

Which contain only values <= 13?

GeneralInnerProduct13&comma;`and`&comma;`>=`&comma;MN

(4.14)

GeneralInnerProduct works with more than two dimensions.

A1Arraya&comma;b&comma;c&comma;d&comma;e&comma;f&comma;g&comma;h

A2Array1&comma;2&comma;3&comma;4

A2

(4.15)

RGeneralInnerProductA1&comma;f&comma;`/`&comma;A2

R1,R2

?,?

(4.16)

The datatype option can be used if the default datatype would not be suitable for the result.

AMatrix1&comma;5&comma;10&comma;20&comma;datatype=integer1

A

(4.17)

GeneralInnerProductA&comma;`+`&comma;`*`&comma;A

Error, (in ArrayTools:-GeneralInnerProduct) unable to store '210' when datatype=integer[1]

GeneralInnerProductA&comma;`+`&comma;`*`&comma;A&comma;datatype=integer2

(4.18)

GeneralInnerProduct can perform operations on ImageTools images. This example converts an RGB image to gray scale, primarily based on the green channel:

withImageTools&colon;

imgSampleImage3

bwGeneralInnerProductimg&comma;`+`&comma;`*`&comma;0.1&comma;0.8&comma;0.1&comma;datatype=float8

Embedbw

Compatibility

• 

The ArrayTools[GeneralInnerProduct] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

See Also

ArrayTools

ArrayTools[GeneralOuterProduct]

ArrayTools[SuggestedDatatype]

ArrayTools[SuggestedOrder]

ArrayTools[SuggestedSubtype]