Skip to content

Commit 6352966

Browse files
committed
Added more methods to PGsparsevec
1 parent c9f2996 commit 6352966

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/main/java/com/pgvector/PGsparsevec.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,33 @@ public float[] toArray() {
220220
return vec;
221221
}
222222

223+
/**
224+
* Returns the number of dimensions
225+
*
226+
* @return the number of dimensions
227+
*/
228+
public int getDimensions() {
229+
return dimensions;
230+
}
231+
232+
/**
233+
* Returns the non-zero indices
234+
*
235+
* @return the non-zero indices
236+
*/
237+
public int[] getIndices() {
238+
return indices;
239+
}
240+
241+
/**
242+
* Returns the non-zero values
243+
*
244+
* @return the non-zero values
245+
*/
246+
public float[] getValues() {
247+
return values;
248+
}
249+
223250
/**
224251
* Registers the sparsevec type
225252
*

src/test/java/com/pgvector/PGsparsevecTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,22 @@ void testGetValue() {
4040
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
4141
assertEquals("{1:1.0,3:2.0,5:3.0}/6", vec.getValue());
4242
}
43+
44+
@Test
45+
void testGetDimensions() {
46+
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
47+
assertEquals(6, vec.getDimensions());
48+
}
49+
50+
@Test
51+
void testGetIndices() {
52+
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
53+
assertArrayEquals(new int[] {0, 2, 4}, vec.getIndices());
54+
}
55+
56+
@Test
57+
void testGetValues() {
58+
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
59+
assertArrayEquals(new float[] {1, 2, 3}, vec.getValues());
60+
}
4361
}

0 commit comments

Comments
 (0)