Improved handling of extra dimensions

This commit is contained in:
Waldir Leoncio 2020-03-18 11:42:41 +01:00
parent 8a73fe4bc1
commit 23e0d4a1a3
3 changed files with 20 additions and 4 deletions

View file

@ -24,8 +24,14 @@ zeros_or_ones <- function(n, x) {
#' the `zeros()` function on Matlab #' the `zeros()` function on Matlab
#' @param n1 number of rows #' @param n1 number of rows
#' @param n2 number of columns #' @param n2 number of columns
#' @param ... extra dimensions
zeros <- function(n1, n2 = n1, ...) { zeros <- function(n1, n2 = n1, ...) {
return(zeros_or_ones(c(n1, n2, ...), 0)) if (length(n1) == 1) {
n <- c(n1, n2, ...)
} else {
n <- n1
}
return(zeros_or_ones(n, 0))
} }
#' @title Matrix of ones #' @title Matrix of ones
@ -33,6 +39,12 @@ zeros <- function(n1, n2 = n1, ...) {
#' the `ones()` function on Matlab #' the `ones()` function on Matlab
#' @param n1 number of rows #' @param n1 number of rows
#' @param n2 number of columns #' @param n2 number of columns
#' @param ... extra dimensions
ones <- function(n1, n2 = n1, ...) { ones <- function(n1, n2 = n1, ...) {
return(zeros_or_ones(c(n1, n2, ...), 1)) if (length(n1) == 1) {
n <- c(n1, n2, ...)
} else {
n <- n1
}
return(zeros_or_ones(n, 1))
} }

View file

@ -4,12 +4,14 @@
\alias{ones} \alias{ones}
\title{Matrix of ones} \title{Matrix of ones}
\usage{ \usage{
ones(n1, n2 = n1) ones(n1, n2 = n1, ...)
} }
\arguments{ \arguments{
\item{n1}{number of rows} \item{n1}{number of rows}
\item{n2}{number of columns} \item{n2}{number of columns}
\item{...}{extra dimensions}
} }
\description{ \description{
wrapper of `zeros_or_ones()` that replicates the behavior of wrapper of `zeros_or_ones()` that replicates the behavior of

View file

@ -4,12 +4,14 @@
\alias{zeros} \alias{zeros}
\title{Matrix of zeros} \title{Matrix of zeros}
\usage{ \usage{
zeros(n1, n2 = n1) zeros(n1, n2 = n1, ...)
} }
\arguments{ \arguments{
\item{n1}{number of rows} \item{n1}{number of rows}
\item{n2}{number of columns} \item{n2}{number of columns}
\item{...}{extra dimensions}
} }
\description{ \description{
wrapper of `zeros_or_ones()` that replicates the behavior of wrapper of `zeros_or_ones()` that replicates the behavior of