athena__concat_layer Module

Module containing implementation of a concatenation layer

This module implements a merge layer that concatenates multiple input tensors along a specified dimension (features for 2D, channels for 3D).

Mathematical operation: output = [input_1 || input_2 || ... || input_N]

where || denotes concatenation along the appropriate dimension. Output size along concatenation dimension = sum of input sizes. Gradients are split to corresponding input portions during backpropagation.


Uses


Interfaces

public interface concat_layer_type

Interface for setting up the concatenate layer

  • private module function layer_setup(input_layer_ids, input_rank, verbose) result(layer)

    Setup a concatenate layer

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in), dimension(:) :: input_layer_ids

    Input layer IDs

    integer, intent(in), optional :: input_rank

    Input rank

    integer, intent(in), optional :: verbose

    Verbosity level

    Return Value type(concat_layer_type)


Derived Types

type, public, extends(merge_layer_type) ::  concat_layer_type

Type for concatenate layer with overloaded procedures

Components

Type Visibility Attributes Name Initial
type(graph_type), public, allocatable, dimension(:) :: graph

Graph structure of input data

integer, public :: id

Unique identifier

logical, public :: inference = .false.

Inference mode

integer, public, allocatable, dimension(:) :: input_layer_ids

IDs of input layers

integer, public :: input_rank = 0

Rank of input data

integer, public, allocatable, dimension(:) :: input_shape

Input shape

integer, public, dimension(:,:), allocatable :: io_map

I/O mapping for the layer

integer, public :: merge_mode = 1

Integer code for fundamental merge method 1 = pointwise 2 = concatenate 3 = reduction 4 = parametric (NOT IMPLEMENTED)

character(len=20), public :: method

Merge method

character(len=:), public, allocatable :: name

Layer name

integer, public :: num_input_layers = 0

Number of input layers

class(array_type), public, allocatable, dimension(:,:) :: output

Output

integer, public :: output_rank = 0

Rank of output data

integer, public, allocatable, dimension(:) :: output_shape

Output shape

character(len=20), public :: subtype = repeat(" ", 20)
character(len=4), public :: type = 'base'

Layer type

logical, public :: use_graph_input = .false.

Use graph input

logical, public :: use_graph_output = .false.

Use graph output

Constructor

Interface for setting up the concatenate layer

private module function layer_setup (input_layer_ids, input_rank, verbose)

Setup a concatenate layer

Type-Bound Procedures

procedure, public, pass(this) :: build_from_onnx => build_from_onnx_base

Build layer from ONNX node and initialiser

procedure, public, pass(this) :: calc_input_shape => calc_input_shape_concat

Calculate input shape based on shapes of input layers

procedure, public, pass(this) :: combine => combine_concat
procedure, public, pass(this) :: emit_onnx_graph_inputs => emit_onnx_graph_inputs_base

Emit graph input tensor declarations for this layer

procedure, public, pass(this) :: emit_onnx_nodes => emit_onnx_nodes_base

Emit ONNX JSON nodes for this layer (format-aware and polymorphic)

procedure, public, pass(this) :: extract_output => extract_output_base

Extract the output of the layer as a standard real array

procedure, public, pass(this) :: forward => forward_base

Forward pass of layer

procedure, public, pass(this) :: forward_eval => forward_eval_base

Forward pass of layer and return output for evaluation

procedure, public, pass(this) :: get_attributes => get_attributes_base

Get the attributes of the layer (for ONNX export)

procedure, public, pass(this) :: get_num_params => get_num_params_base

Get the number of parameters in the layer

procedure, public, pass(this) :: init => init_concat

Initialise concatenate layer

procedure, public, pass(this) :: nullify_graph => nullify_graph_base

Nullify the forward pass data of the layer to free memory

Read more…
procedure, public, pass(this) :: print => print_base

Print the layer to a file with additional information

procedure, public, pass(this) :: print_to_unit => print_to_unit_concat

Print the layer to a file

procedure, public, pass(this) :: read => read_concat

Read the layer from a file

procedure, public, pass(this) :: set_graph => set_graph_base

Set the graph structure of the input data !! this is adjacency and edge weighting

procedure, public, pass(this) :: set_hyperparams => set_hyperparams_concat

Set the hyperparameters for concatenate layer

procedure, public, pass(this) :: set_rank => set_rank_base

Set the input and output ranks of the layer

procedure, public, pass(this) :: set_shape => set_shape_base

Set the input shape of the layer


Functions

public function read_concat_layer(unit, verbose) result(layer)

Read concatenate layer from file and return layer

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

Unit number

integer, intent(in), optional :: verbose

Verbosity level

Return Value class(base_layer_type), allocatable

Instance of the concatenate layer

private function calc_input_shape_concat(this, input_shapes) result(input_shape)

Calculate input shape based on shapes of input layers

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(in) :: this

Instance of the layer

integer, intent(in), dimension(:,:) :: input_shapes

Input shapes

Return Value integer, allocatable, dimension(:)

Calculated input shape

private module function layer_setup(input_layer_ids, input_rank, verbose) result(layer)

Setup a concatenate layer

Arguments

Type IntentOptional Attributes Name
integer, intent(in), dimension(:) :: input_layer_ids

Input layer IDs

integer, intent(in), optional :: input_rank

Input rank

integer, intent(in), optional :: verbose

Verbosity level

Return Value type(concat_layer_type)

Instance of the concatenate layer


Subroutines

private subroutine combine_concat(this, input_list)

Forward propagation for 2D input

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(inout) :: this

Instance of the concatenate layer

type(array_ptr_type), intent(in), dimension(:) :: input_list

Input values

private subroutine init_concat(this, input_shape, verbose)

Initialise concatenate layer

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(inout) :: this

Instance of the concatenate layer

integer, intent(in), dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level

private subroutine print_to_unit_concat(this, unit)

Print concatenate layer to unit

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(in) :: this

Instance of the concatenate layer

integer, intent(in) :: unit

File unit

private subroutine read_concat(this, unit, verbose)

Read concatenate layer from file

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(inout) :: this

Instance of the concatenate layer

integer, intent(in) :: unit

Unit number

integer, intent(in), optional :: verbose

Verbosity level

private subroutine set_hyperparams_concat(this, input_layer_ids, input_rank, verbose)

Set the hyperparameters for concatenate layer

Arguments

Type IntentOptional Attributes Name
class(concat_layer_type), intent(inout) :: this

Instance of the concatenate layer

integer, intent(in), dimension(:) :: input_layer_ids

Input layer IDs

integer, intent(in) :: input_rank

Input rank

integer, intent(in), optional :: verbose

Verbosity level