Skip to content

Commit

Permalink
add some utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Jun 16, 2015
1 parent 12aad49 commit 7a36505
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Check if the number of objectives is the same for given (sets of) points.
#
# We frequently need to check whether the dimension of an approximation set is
# equal to the dimension of the ideal point and/or nadir point. This does exactly
# that assertion for an arbitrary number of arguments.
#
# @param ... [any]
# Vectors or matrizes.
# @return Nothing. Stops if not all dimensions are equal.
assertSameDimensions = function(...) {
xs = list(...)
dims = sapply(xs, function(x) {
# we store vectors one per column
return(if (is.matrix(x)) nrow(x) else length(x))
})
if (!hasAllEqualElements(dims)) {
stopf("All point sets and points need to be of the same dimension.")
}
}

# Check whether all elements of an vector are equal.
#
# @param x [vector]
# Input vector.
# @return [logical(1)]
hasAllEqualElements = function(x) {
return(length(unique(x)) == 1)
}

0 comments on commit 7a36505

Please sign in to comment.