vector_m Module

Attempt to play around with a vector object

A vector, has the following operations:

Addition with another vector Multiplication with a scalar Inner product Outer product Norm (which norm?) Projection of a onto b

The internal representaion of a vector is an allocatable array. This way we can use the fundamental data of an array within our specific class



Contents


Interfaces

public interface vector

Construct a vector object

Read more…
  • private pure function vector_constructor_int(array) result(this)

    Construct a vector from an array of integers

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in), dimension(:):: array

    input data

    Return Value type(vector)

  • private pure function vector_constructor_r32(array) result(this)

    Construct a vector from an array of single precision reals

    Arguments

    Type IntentOptional AttributesName
    real(kind=real32), intent(in), dimension(:):: array

    input data

    Return Value type(vector)

  • private pure function vector_constructor_r64(array) result(this)

    Construct a vector from an array of double precision reals

    Arguments

    Type IntentOptional AttributesName
    real(kind=real64), intent(in), dimension(:):: array

    input data

    Return Value type(vector)

  • private elemental function vector_constructor_dim(dim) result(this)

    Construct a vector by declaring its size Allocate an -dimensional vector and fill its values with 0

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: dim

    Return Value type(vector)

  • private elemental function vector_constructor_dim_value_int(dim, val) result(this)

    Construct a vector of dimension and fill its values with integer

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: dim

    integer, intent(in) :: val

    Return Value type(vector)

  • private elemental function vector_constructor_dim_value_r32(dim, val) result(this)

    Construct a vector of dimension and fill its values with single precision real

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: dim

    real(kind=real32), intent(in) :: val

    Return Value type(vector)

  • private elemental function vector_constructor_dim_value_r64(dim, val) result(this)

    Construct a vector of dimension and fill its values with double precision real

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: dim

    real(kind=real64), intent(in) :: val

    Return Value type(vector)

  • private elemental function vector_constructor_vector(v1) result(v2)

    Construct a vector from another vector

    Read more…

    Arguments

    Type IntentOptional AttributesName
    class(vector), intent(in) :: v1

    Return Value type(vector)

public interface operator(*)

Extend multiplication operator to allow a scalar times a vector such that

  • private elemental function int_times_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)

  • private elemental function r32_times_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    real(kind=real32), intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)

  • private elemental function r64_times_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    real(kind=real64), intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)

public interface operator(/)

Extend division operator to allow a scalar divided by a vector

  • private elemental function int_div_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    integer, intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)

  • private elemental function r32_div_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    real(kind=real32), intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)

  • private elemental function r64_div_vector(scalar, vec) result(v2)

    Arguments

    Type IntentOptional AttributesName
    real(kind=real64), intent(in) :: scalar
    class(vector), intent(in) :: vec

    Return Value type(vector)


Derived Types

type, public :: vector

Constructor

Construct a vector object

Read more…
private pure function vector_constructor_int(array)

Construct a vector from an array of integers

private pure function vector_constructor_r32(array)

Construct a vector from an array of single precision reals

private pure function vector_constructor_r64(array)

Construct a vector from an array of double precision reals

private elemental function vector_constructor_dim(dim)

Construct a vector by declaring its size Allocate an -dimensional vector and fill its values with 0

private elemental function vector_constructor_dim_value_int(dim, val)

Construct a vector of dimension and fill its values with integer

private elemental function vector_constructor_dim_value_r32(dim, val)

Construct a vector of dimension and fill its values with single precision real

private elemental function vector_constructor_dim_value_r64(dim, val)

Construct a vector of dimension and fill its values with double precision real

private elemental function vector_constructor_vector(v1)

Construct a vector from another vector

Read more…

Finalizations Procedures

final :: vector_destructor

Type-Bound Procedures

procedure, public :: size => vector_size

Return the number of elements of the currently allocated vector

procedure, public :: clear => clear_vector

Deallocate the data, set dim to 0

procedure, public :: print_info => vector_print_info

Print diagnostic information about the vector

procedure, public :: print => vector_print_coordinates

Print only the data stored in the vector object as a row vector

procedure, public :: at => vector_at_index

Return the element

generic, public :: set => set_int_, set_r32_, set_r64_

Set the value of the element at index

procedure, public :: length => vector_euclidiean_norm

Calculate the euclidean norm of a vector

procedure, public :: pnorm => vector_pnorm

Calculate the pnorm of a vector

procedure, public :: normalize => vector_normalize

Normalize the elements of the passed vector Normalize is a subroutine such that it alters the elements of the passed vector to avoid costs of copying involved with a function

procedure, public :: normalized => vector_normalized

Return a normalized vector pointing in the same direction as

Read more…
procedure, public :: orthogonalize => vector_orthogonalize

Orthogonalize a vector against a passed normalized vector

Read more…
procedure, public :: orthogonalized => vector_orthogonalized

Return a vector that is orthogonalized against a passed normalized vector

Read more…
procedure, public :: orthonormalize => vector_orthonormalize

Orthogonalize and normalize a vector against a passed normalized vector

Read more…
procedure, public :: orthonormalized => vector_orthonormalized

Return an orthogonalized and normalized vector against a passed normalized vector

Read more…
procedure, public :: householder_transform => vector_householder_sub

Rotate a passed vector about the hyper plane described by the passed normalized vector

Read more…
procedure, public :: id => vector_constructor_eye
procedure, public :: is_ortho => vector_is_orthogonal
procedure, public :: is_normal => vector_is_normal
procedure, public :: data => vector_as_array
procedure, public :: zero => vector_zero
procedure, public :: set_zero => vector_zero_sub
procedure, public :: allocated => vector_is_allocated
procedure, public :: alloc_ => allocate_vector_data
procedure, public :: dealloc_ => deallocate_vector_data
generic, public :: assignment(=) => from_array_int_, from_array_r32_, from_array_r64_, from_vector_, from_int_, from_r32_, from_r64_
generic, public :: operator(.dot.) => dot_
generic, public :: operator(.inner.) => dot_
generic, public :: operator(.outer.) => outer_
generic, public :: operator(.proj.) => proj_
generic, public :: operator(.hh.) => householder_
generic, public :: operator(.hhnorm.) => householder_normal_
generic, public :: operator(*) => scalar_mult_int_, scalar_mult_r32_, scalar_mult_r64_
generic, public :: operator(.o.) => hadamard_vec_
generic, public :: operator(/) => scalar_div_int_, scalar_div_r32_, scalar_div_r64_, div_vec_
generic, public :: operator(+) => plus_
generic, public :: operator(-) => minus_, unary_minus_
generic, public :: times => times_int_sub_, times_r32_sub_, times_r64_sub_, times_vec_sub_
generic, public :: div => div_int_sub_, div_r32_sub_, div_r64_sub_, div_vec_sub_
generic, public :: proj => project_onto_sub_
generic, public :: plus => plus_vector_sub_
generic, public :: minus => minus_vector_sub_