Skip to content

Commit

Permalink
Added more methods to PGsparsevec
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 20, 2024
1 parent c9f2996 commit 6352966
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/com/pgvector/PGsparsevec.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,33 @@ public float[] toArray() {
return vec;
}

/**
* Returns the number of dimensions
*
* @return the number of dimensions
*/
public int getDimensions() {
return dimensions;
}

/**
* Returns the non-zero indices
*
* @return the non-zero indices
*/
public int[] getIndices() {
return indices;
}

/**
* Returns the non-zero values
*
* @return the non-zero values
*/
public float[] getValues() {
return values;
}

/**
* Registers the sparsevec type
*
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/pgvector/PGsparsevecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,22 @@ void testGetValue() {
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
assertEquals("{1:1.0,3:2.0,5:3.0}/6", vec.getValue());
}

@Test
void testGetDimensions() {
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
assertEquals(6, vec.getDimensions());
}

@Test
void testGetIndices() {
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
assertArrayEquals(new int[] {0, 2, 4}, vec.getIndices());
}

@Test
void testGetValues() {
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
assertArrayEquals(new float[] {1, 2, 3}, vec.getValues());
}
}

0 comments on commit 6352966

Please sign in to comment.