Skip to content

Commit

Permalink
Long vector + numpy support
Browse files Browse the repository at this point in the history
  • Loading branch information
kno10 committed Apr 16, 2024
1 parent c0e11f1 commit e5c96e5
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 58 deletions.
27 changes: 25 additions & 2 deletions elki-core-data/src/main/java/elki/data/ByteVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ByteVector implements NumberVector {
/**
* Static instance (object factory).
*/
public static final ByteVector.Factory STATIC = new ByteVector.Factory();
public static final ByteVector.Factory FACTORY = new ByteVector.Factory();

/**
* Serializer for up to 127 dimensions.
Expand Down Expand Up @@ -140,6 +140,29 @@ public String toString() {
return featureLine.toString();
}

/**
* Copy a byte array into a new vector.
*
* @param vals Values
* @return Wrapped vector
*/
public static ByteVector copy(byte[] vals) {
return new ByteVector(vals);
}

/**
* Wrap a byte array as vector (without copying).
* <p>
* Note: modifying the array afterwards can lead to problems if the data has,
* e.g., been added to an index, which relies on them being immutable!
*
* @param vals Values
* @return Wrapped vector
*/
public static ByteVector wrap(byte[] vals) {
return new ByteVector(vals, true);
}

/**
* Factory for Byte vectors.
*
Expand Down Expand Up @@ -186,7 +209,7 @@ public Class<? super ByteVector> getRestrictionClass() {
public static class Par implements Parameterizer {
@Override
public ByteVector.Factory make() {
return STATIC;
return FACTORY;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions elki-core-data/src/main/java/elki/data/IntegerVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IntegerVector implements NumberVector {
/**
* Static instance (object factory).
*/
public static final IntegerVector.Factory STATIC = new IntegerVector.Factory();
public static final IntegerVector.Factory FACTORY = new IntegerVector.Factory();

/**
* Serializer for up to 127 dimensions.
Expand Down Expand Up @@ -142,7 +142,7 @@ public String toString() {
}

/**
* Copy a double array into a new vector.
* Copy an integer array into a new vector.
*
* @param vals Values
* @return Wrapped vector
Expand All @@ -152,7 +152,7 @@ public static IntegerVector copy(int[] vals) {
}

/**
* Wrap a double array as vector (without copying).
* Wrap an integer array as vector (without copying).
* <p>
* Note: modifying the array afterwards can lead to problems if the data has,
* e.g., been added to an index, which relies on them being immutable!
Expand Down Expand Up @@ -210,7 +210,7 @@ public Class<? super IntegerVector> getRestrictionClass() {
public static class Par implements Parameterizer {
@Override
public IntegerVector.Factory make() {
return STATIC;
return FACTORY;
}
}
}
Expand Down
Loading

0 comments on commit e5c96e5

Please sign in to comment.