Skip to content

Commit 67df9d5

Browse files
author
Oscar Torreno
authored
Adding the join method to the Array class (#27)
1 parent 7220d28 commit 67df9d5

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</properties>
77
<groupId>io.shapelets</groupId>
88
<artifactId>khiva</artifactId>
9-
<version>0.2.0</version>
9+
<version>0.2.2</version>
1010

1111
<name>khiva-java</name>
1212
<url>https://github.com/shapelets/khiva-java</url>

src/main/java/io/shapelets/khiva/Array.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ public Array(Array other) {
256256

257257
private native long[] nativeGetDims();
258258

259+
private native int nativeGetType();
260+
259261
private native long nativePrint();
260262

261263
private native DoubleComplex[] getDoubleComplexFromArray();
@@ -276,7 +278,7 @@ public Array(Array other) {
276278

277279
private native long[] getLongFromArray();
278280

279-
private native int nativeGetType();
281+
private native long[] join(int dim, long refRhs);
280282

281283
private native long[] add(long refRhs);
282284

@@ -434,6 +436,19 @@ public long[] getDims() {
434436
return nativeGetDims();
435437
}
436438

439+
/**
440+
* Joins this array with the one specified as parameter along the specified dimension.
441+
*
442+
* @param dim The dimension along which the join occurs.
443+
* @param rhs Right-hand side array for the operation.
444+
* @return The result of joining the given arrays along the specified dimension.
445+
*/
446+
public Array join(int dim, Array rhs) {
447+
long[] refs = join(dim, rhs.reference);
448+
rhs.reference = refs[0];
449+
return new Array(refs[1]);
450+
}
451+
437452
/**
438453
* Adds this array with the one passed as parameter.
439454
*

src/test/java/io/shapelets/khiva/ArrayTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,23 @@ public void testGetType() throws Exception {
485485
}
486486
}
487487

488+
@Test
489+
public void testJoin() throws Exception {
490+
float[] data1 = {1f, 2f, 3f, 4f};
491+
float[] data2 = {5f, 6f, 7f, 8f};
492+
long[] dims = {4, 1, 1, 1};
493+
try (Array a = new Array(data1, dims); Array b = new Array(data2, dims); Array c = a.join(1, b)) {
494+
float[] result = c.getData();
495+
float[] expected = {1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f};
496+
Assert.assertArrayEquals(result, expected, 1e-6f);
497+
}
498+
}
499+
488500
@Test
489501
public void testAdd() throws Exception {
490502
float[] data = {1f, 2f, 3f, 4f};
491503
long[] dims = {4, 1, 1, 1};
492504
try (Array a = new Array(data, dims); Array b = new Array(data, dims); Array c = a.add(b)) {
493-
494505
float[] result = c.getData();
495506
float[] expected = {2f, 4f, 6f, 8f};
496507
Assert.assertArrayEquals(result, expected, 1e-6f);

0 commit comments

Comments
 (0)