Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: polyMatrix
Version: 0.9.11
Version: 0.9.16
Title: Infrastructure for Manipulation Polynomial Matrices
Description:
Implementation of class "polyMatrix" for storing a matrix of polynomials and implements
Expand All @@ -20,7 +20,7 @@ Type: Package
Authors@R: c(
person("Tamas", "Prohle", email="prohlet@ludens.elte.hu", role="aut"),
person("Peter", "Prohle", email="prohlep@math.elte.hu", role="aut"),
person("Nikolai", "Ryzhkov", email="namezys@gmail.com", role=c("aut", "cre")),
person("Nikolai", "Ryzhkov", email="namezys@gmail.com", role=c("aut", "cre"), comment = c(ORCID = "0000-0003-4896-280X")),
person("Ildiko", "Laszlo", role="aut", comment = c(ORCID = "0000-0003-2324-8183")),
person("Ulas Onat", "Alakent", role="ctb")
)
Expand Down
42 changes: 22 additions & 20 deletions R/class_polyMatrix.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Title : Main class of polymatrix
# Objective : Definition of class
# Objective : The definition of the class
# Created by: namezys
# Created on: 2020. 10. 16.

Expand All @@ -15,15 +15,15 @@ setOldClass(P)
return("Negative number of columns")
}
if(ncol(object@coef) %% object@ncol != 0) {
return("Invalid coefficient matrix size")
return("Invalid matrix size and size of coef")
}
return(TRUE)
}

#' A class to represent matrix of polinomials
#' A class to represent a matrix of polynomials
#'
#' @slot coef A matrix of coefficients which are joined into one matrix from lower degree to higher
#' @slot ncol Actual number of columns in the polynomial matrix
#' @slot ncol The actual number of columns in the polynomial matrix
#'
#' @examples
#'
Expand All @@ -41,7 +41,7 @@ polyMatrixClass <- setClass(
)

.clean.coef <- function(coef, ncol) {
# clean up coef matrix by removing zero tails
# cleans up coef matrix by removing zero tails
stopifnot(ncol(coef) %% ncol == 0)
nr <- nrow(coef)
d <- ncol(coef) / ncol - 1
Expand Down Expand Up @@ -73,23 +73,25 @@ polyMatrixClass <- setClass(

#' Create polyMatrix object
#'
#' This function will create polynomial object fromm
#' This function will create a polynomial object from
#' coefficient matrix or signle value
#'
#' A coefficient matrix is a matrix which contains
#' matrices of coefficients from lower degree to higher
#' matrices of coefficients starting from lower degree to higher ones,
#' side-by-side
#'
#' @param data an matrix in case of creation from coefficient matrices or an numer/polynomial
#' @param nrow A numer of rows of matrix.
#' If data is a matrix, default value is the number of rows of data matrix.
#' In other case, it's a required parameter
#' @param ncol Must be positibe.
#' If data is a matrix, default value is the number of columns of data matrix.
#' In other ccase, it's a required parameter.
#' @param degree Degree of polynomials in coefficient matrix. Can't be negative.
#' If data is polynomail, degree can be evaluated automatcal.
#' In other case, default value is 0.
#' @param data A matrix containing matrices of coefficients
#' or a number or a polynomial
#' @param nrow The numer of rows of a polynomial matrix. Must be postive.
#' If data is a matrix, the default value is the number of rows of matrix `data`.
#' In other cases it is a required parameter.
#' @param ncol A number of columns of a polynomial matrix. Must be positive.
#' If data is a matrix, the default value is the number of columns of matrix `data`.
#' In other cases it is a required parameter.
#' @param degree Degree of polynomials in the coefficient matrix. Must be zero or positive.
#' If data is polynomial, degree can be evaluated automatcal.
#' In other case, default value is 0.
#'
#' @return new polynomial matrix of polyMatrix class
#' @export
polyMatrix <- function(data, nrow, ncol, degree) {
Expand All @@ -104,7 +106,7 @@ polyMatrix <- function(data, nrow, ncol, degree) {
ncol <- 1
}
if(!missing(degree) && degree < length(data) - 1) {
stop("Polynomail has higher degree than requested")
stop("Polynomial has higher degree than requested")
}
degree <- length(data) - 1
nrow <- as.integer(nrow)
Expand Down Expand Up @@ -158,7 +160,7 @@ polyMatrix <- function(data, nrow, ncol, degree) {
#' Check if object is polyMatrix
#'
#' @param x an \R object
#' @return TRUE if object is a polonial matrix
#' @return TRUE if object is a polynomial matrix
#' @examples
#' is.polyMatrix(c(1, 2, 3))
#' is.polyMatrix(polyMatrix(0, 2, 2))
Expand All @@ -176,4 +178,4 @@ is.polyMatrix <- function(x) {
}
}
return(polynom::as.polylist(result))
}
}
8 changes: 4 additions & 4 deletions R/class_polyMatrixCharPolynomial.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Title : Class of characteristic polinomail of polynomail matrix
# Title : Class of characteristic polynomial of a polynomial matrix
# Objective : We use polyMatrix to store polynomial coefficients
# Created by: namezys
# Created on: 2021. 05. 05.
Expand All @@ -8,14 +8,14 @@ PMCP <- "polyMatrixCharPolynomial"

.check.polyMatrixCharClass <- function (object) {
if (nrow(object@coef) != 1) {
return("Char polynomial matrix should contrains only one row")
return("Char polynomial matrix should contain only one row")
}
return(TRUE)
}

#' A class to repesent characteristic polynomial of polynomial matrix
#' A class to repesent characteristic polynomial of a polynomial matrix
#'
#' Characteristic polynomial of polynomial matrix is polynomial with polynomial coefficients
#' Characteristic polynomial of a polynomial matrix is a polynomial with polynomial coefficients
#' @export
polyMatrixCharClass <- setClass(
PMCP,
Expand Down
20 changes: 10 additions & 10 deletions R/method_adjoint.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Title : cofactor and adjoint matrix
# Title : cofactor and the adjoint matrix
# Created by: namezys
# Created on: 2021. 04. 29.

#' Cofactor of matrix
#' Cofactor of a matrix
#'
#' @param x an matrix
#' @param r,c the row and column
#' @return cofactor which is number or polynomial
#' @param x a matrix
#' @param r,c the rows and columns
#' @return cofactor which is a number or a polynomial
#'
#' @seealso [adjoint()]
#'
Expand Down Expand Up @@ -39,15 +39,15 @@ cofactor <- function(x, r, c) {
return(result)
}

#' Adjugate or classical adjoint of a square matrix
#' Adjungate or classical adjoint of a square matrix
#'
#' The adjugate or classical adjoint of a square matrix is the transpose of its cofactor matrix.
#' It is also occasionally known as adjunct matrix,[ though this nomenclature appears to have decreased in usage.
#' The adjungate or classical adjoint of a square matrix is the transpose of its cofactor matrix.
#' It is also occasionally known as adjunct matrix, though this nomenclature appears to have been decreased in usage.
#'
#' @param x an matrix
#' @param x a matrix
#'
#' @export
setGeneric("adjoint", .adjoint.generic)
#' @describeIn adjoint adjugate of polynomial matrix
#' @describeIn adjoint adjungate of polynomial matrix DON'T UNDERSTAND!!!
#' @export
setMethod("adjoint", signature(x = PM), .adjoint.polyMatrix)
28 changes: 14 additions & 14 deletions R/method_bind.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Title : row and column bind
# Objective : because core function use only "..." we have to redefine method to allow to use with polyMatrix in any
# poisition
# Title : row and column binding
# Objective : because core functions use only "..." we have to redefine the method
# in order to allow us to use with polyMatrix in any poisition of argument liist
# Created by: namezys
# Created on: 2020. 10. 23.

#' Combine polynial matrices by rows or coluns
#' Combine polynomial matrices by rows or columns
#'
#' @param ... (generalzed) vectors or mmatrices.
#' If any of objects are polynomail matrix
#' @param deparse.level details in base function, polynomial matrices doesn't use it
#' @param ... (generalized) vectors or matrices.
#' If any of the objects is a polynomail matrix
#' @param deparse.level details in the base function, polynomial matrices doesn't use this argument
#'
#' @return if at least one argument is a polynomail matrix,
#' the result will be combined polynomial matrix.
#' Overwise, base package implementatioon [base::cbind()] or [base::rbind()]
#' @return if at least one argument is a polynomial matrix,
#' the result will be a combined polynomial matrix.
#' Otherwise, the base package implementation [base::cbind()] or [base::rbind()]
#' will be called.
#'
#' @seealso [base::cbind()]
Expand Down Expand Up @@ -42,7 +42,7 @@ cbind <- function(..., deparse.level = 1) {
if(is.null(nr)) {
nr <- vnr
} else if(!is.null(vnr) && nr != vnr) {
stop("number of rows of matrices must match")
stop("the number of rows of the matrices must match")
}
vnc <- ncol(i)
if(is.null(vnc)) {
Expand All @@ -69,7 +69,7 @@ cbind <- function(..., deparse.level = 1) {
return(res)
}

#' @describeIn cbind row based bind
#' @describeIn cbind row based bind DON'T UNDERSTAND.. !!!
#'
#' @export
rbind <- function(..., deparse.level = 1) {
Expand Down Expand Up @@ -97,7 +97,7 @@ rbind <- function(..., deparse.level = 1) {
if(is.null(nc)) {
nc <- vnc
} else if(!is.null(vnc) && nc != vnc) {
stop("number of columns of matrices must match")
stop("the number of columns of the matrices must match")
}
vnr <- nrow(i)
if(is.null(vnr)) {
Expand All @@ -122,4 +122,4 @@ rbind <- function(..., deparse.level = 1) {
r <- r + vnr
}
return(res)
}
}
10 changes: 5 additions & 5 deletions R/method_charpolynom.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@
return(polyMatrixCharClass(coef=.char.step(x, diag(1, nrow(x), ncol(x)))))
}

#' Characteristic polynomial of matrix
#' Characteristic polynomial of a matrix
#'
#' @param x an matrix
#'
#' @export
setGeneric("charpolynom", function(x) {
stop("Matrix object is exppected")
stop("Matrix object is expected")
})
#' @describeIn charpolynom for numerical matrix it is a polynomial with numerical coefficients
#'
#' @return When the input is a numerical matrix of `matrix` class
#' then the value is a `polynomial` object.
#' the value is a `polynomial` object.
#'
#' @examples
#'
Expand All @@ -92,13 +92,13 @@ setMethod("charpolynom", signature(x="matrix"), .charpolynom.matrix)
setMethod("charpolynom", signature(x=P), function (x) {
return(charpolynom(polyMatrix(x)))
})
#' @describeIn charpolynom for polynomial matrix it has polynomial coefficients
#' @describeIn charpolynom for polynomial matrix has polynomial coefficients
#'
#' @details
#' The characteristic polynom of a polynomial matrix is a polynom with polynomial coefficients.
#'
#' @return When the input is a `polyMatrix` object
#' then a value is `polyMatrixCharClass` class object,
#' then the value is `polyMatrixCharClass` class object,
#'
#' @seealso [polyMatrixCharClass]
#' @export
Expand Down
14 changes: 7 additions & 7 deletions R/method_coef.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Title : Get coeffisient matrix by using "[[" operator
# Title : Gets coefficient matrix by using "[[" operator
# Created by: namezys
# Created on: 2020. 10. 16.

#' @describeIn polyMatrix get coefficient matrix by degree
#'
#' @param i the degree to extract matrix of coefficient
#' @param i the degree of the matrix of coefficient to be extracted
#' @examples
#'
#' # get coefficient matrix for degree 0
Expand All @@ -21,23 +21,23 @@
#' @export
setMethod("[[", signature(x = PM, i = "numeric"), function(x, i) {
if(length(i) != 1) {
stop("Only one coefficient matrix can be gotten")
stop("Only one coefficient matrix can be gotten at once")
}
if(i > degree(x) || i < 0) {
stop("degree out of bounds")
}
return(x@coef[, seq_len(ncol(x)) + ncol(x) * i])
})
#' @describeIn charpolynom get polynomial coefficient of characteristic
#' @describeIn charpolynom get polynomial coefficient of characteristic polynomial
#'
#' @param i the degree to extract polinomial coefficient
#' @param i the degree of the polynomial coefficient to be extract
#' @export
setMethod("[[", signature(x = PMCP), function(x, i) {
if(length(i) != 1) {
stop("Only one coefficient matrix can be gotten")
stop("Only one coefficient matrix can be gotten at once")
}
if(i + 1 > ncol(x@coef) || i < 0) {
stop("degree out of bounds")
}
return(x@coef[1, i + 1])
})
})
15 changes: 7 additions & 8 deletions R/method_degree.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Created by: namezys
# Created on: 2020. 10. 17.

#' Gets maximum degree of polynomial objects
#' Gets the maximum degree of polynomial objects
#'
#' Returns the maximum degree as an integer number.
#'
Expand All @@ -11,8 +11,7 @@
#' for polynomial objects.
#'
#' @details
#' By default, this function raises
#' error for unknown type of object.
#' By default, this function raises error for unknown type of object.
#'
#' @export
setGeneric("degree", function(x) {
Expand All @@ -22,7 +21,7 @@ setGeneric("degree", function(x) {
#' @describeIn degree a scalar argument always has zero degree
#'
#' @details
#' A numerical scalar has zero degree.
#' A numerical scalar can be treated as a polynomial with zero degree.
#'
#' @examples
#'
Expand All @@ -32,7 +31,7 @@ setGeneric("degree", function(x) {
#' @export
setMethod("degree", signature(x = NUM), function(x) {
if(length(x) != 1) {
stop("Numeric suquence is unsupported")
stop("Numeric sequence is unsupported")
}
return(0)
})
Expand Down Expand Up @@ -77,12 +76,12 @@ setMethod("degree", signature(x = P), function(x) { length(x) - 1 })
#'
#' @export
setMethod("degree", signature(x = PM), function(x) { as.integer(ncol(x@coef) / x@ncol - 1) })
#' @describeIn charpolynom the degree of char polynomail of polynomial matrix
#' @describeIn charpolynom the degree of char polynomial of polynomial matrix
#'
#' @export
setMethod("degree", signature(x = PMCP), function(x) { as.integer(ncol(x@coef) - 1) })

#' Degree of each item of matrix
#' Degree of each item of the matrix
#'
#' Returns a matrix obtained by applying a function [degree()]
#' for each element of the matrix.
Expand All @@ -94,7 +93,7 @@ setMethod("degree", signature(x = PMCP), function(x) { as.integer(ncol(x@coef) -
#'
#' @details
#' Degree of each item is calculated using [degree()] which is defined for polynomials
#' as the highest degree of the terms with non-zero coefficient.
#' as the highest degree of the terms with non-zero coefficients.
#'
#' For convenience this function is defined for any object,
#' but returns zero for non polynomial objects.
Expand Down
4 changes: 2 additions & 2 deletions R/method_det.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Title : deteminant of polyMatrix
# Title : determinant of polyMatrix
# Created by: namezys
# Created on: 2021. 04. 02.

.number.nonzero.item.in.row <- function(pm, r)
{
# We should it very fast, use coef matrix directly
# We should do it very fast, use coef matrix directly
positions <- ncol(pm) * 0:degree(pm)
result <- 0
for(i in seq_len(ncol(pm))) {
Expand Down
Loading