Package

cogx

api

Permalink

package api

Visibility
  1. Public
  2. All

Type Members

  1. trait CogFunctionAPI extends SemanticError with ImplicitConversions

    Permalink

    Function API for Cog.

    Function API for Cog.

    Algebraic operators are defined in CogOperatorAPI.

  2. trait CogOperatorAPI extends AnyRef

    Permalink

    Cog API for operators (+, -, ...)

    Cog API for operators (+, -, ...)

    Because Scala does not support operator functions very well, we implement these as methods on Fields. A description of the Field class follows:

    Fields

    A field is a multidimensional array of tensors, where tensors are defined to be multidimensional arrays of numbers. The dimensionality of the field may be 0, 1, 2 or 3. The actual size of the field dimensions are called the "field shape." To make programming easier, the field shape is described using the terms layers, rows and columns. 3D fields uses all three values. 2D fields use only rows and columns and have layers set to 1 for convenience. 1D fields use only columns and have layers and rows set to 1 for convenience. 0D fields have only a single tensor and have no need for layers, rows or columns, but for convenience these values are set to 1.

    Tensors

    The dimensionality of a tensor is called its "order" which may be 0 (for scalars), 1 (vectors), or 2 (matrices). Tensors also have a shape which uses similar naming as for field shapes. For example, a matrix has rows and columns. All tensors within a given field have exactly the same shape.

    Operators

    Operators take one or more fields (which can be considered as immutable objects) and produce a result field. Each operator has a set of rules defining the legal combinations of fields it accepts as inputs, and how those inputs are combined to produce the output. Fortunately most operators use only one of a small set of different rules; the most common rules are now described:

    Algebraic binary operator rules

    Binary operators take two fields as inputs. Generally if one of them is a complex field, the other will be implicitly converted to a complex form (with zero imaginary components) before proceeding.

    The two inputs Fields are algebraically compatible if they satisfy one of the following four conditions (which also define the nature of their result):

    1. They have exactly the same field shape and tensor shape. In this case, corresponding elements of the two fields are combined to produce the result: a field with the same field shape and tensor shape as the two input fields.

    2. They have exactly the same field shape, but one of them is a scalar field and the other is a (non-scalar) tensor field. In this case the scalar at each location in the scalar field is combined with the tensor in the corresponding location in the tensor field. The result is a tensor field with the same field shape and tensor shape as the input tensor field.

    3. One of them is a 0-dimensional scalar field. In this case the single scalar of the 0D scalar field is combined with each element of every tensor in tensor field. The result is a tensor field with the same field shape and tensor shape as the input tensor field.

    4. One of them is a 0-dimensional tensor field (non-scalar). In this case, the tensor shape of the 0-dimensional field must exactly match the tensor shape of the other field. The tensor from the 0-dimensional field is combined element-wise with each of the tensors in the other field to produce the result, which has the same field shape and tensor shape of the larger input field.

    Algebraic unary operator rules

    Operators which take only one field as input (and an optional numeric constant) produce a result with the same field shape and tensor shape as the input field. If the input field is complex, the optional numeric constant is converted to complex (with zero imaginary part) before proceeding with the operation.

    Boolean result rules

    Operators which produce boolean results, such as the comparison operators, use 1.0f to represent true and 0.0f to represent false.

  3. trait ImplicitConversions extends AnyRef

    Permalink

    Implicit conversions needed to emulate static typing in Cog.

Ungrouped