-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12aad49
commit 7a36505
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|