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
#' @param n1 number of rows
#' @param n2 number of columns
#' @param ... extra dimensions
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
@ -33,6 +39,12 @@ zeros <- function(n1, n2 = n1, ...) {
#' the `ones()` function on Matlab
#' @param n1 number of rows
#' @param n2 number of columns
#' @param ... extra dimensions
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}
\title{Matrix of ones}
\usage{
ones(n1, n2 = n1)
ones(n1, n2 = n1, ...)
}
\arguments{
\item{n1}{number of rows}
\item{n2}{number of columns}
\item{...}{extra dimensions}
}
\description{
wrapper of `zeros_or_ones()` that replicates the behavior of

View file

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