summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:38 +0000
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:38 +0000
commit14a486343aef55f97f54082d6b542dedebf6f3ba (patch)
tree000fcc4968578771ad265079eef7617d66de2cda /src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java
parent8300861dc4c62c5567a4e654976072f854217544 (diff)
Import Upstream version 0.6.0
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java
index ea178bbb..e29d9237 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/AbstractVectorDoubleDistanceFunction.java
@@ -73,8 +73,7 @@ public abstract class AbstractVectorDoubleDistanceFunction extends AbstractPrimi
* @throws IllegalArgumentException when dimensionalities are not the same.
*/
public static final int dimensionality(SpatialComparable o1, SpatialComparable o2) {
- final int dim1 = o1.getDimensionality();
- final int dim2 = o2.getDimensionality();
+ final int dim1 = o1.getDimensionality(), dim2 = o2.getDimensionality();
if (dim1 != dim2) {
throw new IllegalArgumentException("Objects do not have the same dimensionality.");
}
@@ -92,8 +91,42 @@ public abstract class AbstractVectorDoubleDistanceFunction extends AbstractPrimi
* @throws IllegalArgumentException when dimensionalities are not the same.
*/
public static final int dimensionality(SpatialComparable o1, SpatialComparable o2, int expect) {
- final int dim1 = o1.getDimensionality();
- final int dim2 = o2.getDimensionality();
+ final int dim1 = o1.getDimensionality(), dim2 = o2.getDimensionality();
+ if (dim1 != dim2 || dim1 != expect) {
+ throw new IllegalArgumentException("Objects do not have the expected dimensionality of " + expect);
+ }
+ return expect;
+ }
+
+ /**
+ * Get the common dimensionality of the two objects. Throw an
+ * {@link IllegalArgumentException} otherwise.
+ *
+ * @param o1 First vector / MBR
+ * @param o2 Second vector / MBR
+ * @return Common dimensionality
+ * @throws IllegalArgumentException when dimensionalities are not the same.
+ */
+ public static final int dimensionality(NumberVector<?> o1, NumberVector<?> o2) {
+ final int dim1 = o1.getDimensionality(), dim2 = o2.getDimensionality();
+ if (dim1 != dim2) {
+ throw new IllegalArgumentException("Objects do not have the same dimensionality.");
+ }
+ return dim1;
+ }
+
+ /**
+ * Get the common dimensionality of the two objects. Throw an
+ * {@link IllegalArgumentException} otherwise.
+ *
+ * @param o1 First vector / MBR
+ * @param o2 Second vector / MBR
+ * @param expect Expected dimensionality
+ * @return Common dimensionality
+ * @throws IllegalArgumentException when dimensionalities are not the same.
+ */
+ public static final int dimensionality(NumberVector<?> o1, NumberVector<?> o2, int expect) {
+ final int dim1 = o1.getDimensionality(), dim2 = o2.getDimensionality();
if (dim1 != dim2 || dim1 != expect) {
throw new IllegalArgumentException("Objects do not have the expected dimensionality of " + expect);
}