Skip to content

Commit

Permalink
bytedeco#391 In case of single dimension, do not calculate strides, s…
Browse files Browse the repository at this point in the history
…o we save some multiplications
  • Loading branch information
matteodg committed May 3, 2020
1 parent 8f436ab commit 32132d3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/org/bytedeco/javacpp/indexer/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
*/
public abstract class Index {

public static Index ONE = create(1);
public static Index create(long size) {
return new OneIndex(size);
}

public static Index create(long... sizes) {
return new StrideIndex(sizes, defaultStrides(sizes));
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/org/bytedeco/javacpp/indexer/OneIndex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.bytedeco.javacpp.indexer;

public class OneIndex extends Index {

private final long[] sizes;

/**
* TODO
*
* @param size
*/
protected OneIndex(long size) {
this.sizes = new long[]{size};
}

@Override
public long index(long i) {
return i;
}

@Override
public long index(long i, long j) {
return i;
}

@Override
public long index(long i, long j, long k) {
return i;
}

@Override
public long index(long... indices) {
return indices[0];
}

@Override
public long[] sizes() {
return sizes;
}
}

0 comments on commit 32132d3

Please sign in to comment.