api / koma.matrix.common / MatrixBase / castOrCopy

castOrCopy

protected inline fun <DType, reified TOuter :Matrix<DType>, reified TInner> castOrCopy(mat:Matrix<DType>, makeOuter: (TInner) ->TOuter, outerFac:MatrixFactory<TOuter>):TOuter

Attempts to downcast a matrix to its specific subclass, accepting both inner wrapped types and outer types. Requires the TOuter constructor to be passed in because reified generics don't support ctor calls. If the passed mat cannot be cast, instead copies the data manually into a newly allocated matrix of the correct type.

Parameters

mat - The matrix we want to cast or copy-- can either be a Matrix or the output of getBaseMatrix for a backend (inner wrapped type).

makeOuter - A function that takes in an inner type and produces the outer matrix type that we are trying to cast or copy to

outerFac - The factory for the outer type we are trying to cast or copy to