Skip to content

Commit

Permalink
Issue fix 1773 and 1774 (#1789)
Browse files Browse the repository at this point in the history
1. Fix issue 1773 and issue 1774
In NDArray.set(NDArray index, Number value) add the feature of setting array values with integer indices, as shown in the use case #1773 as well as #1774.

2. Fix an issue in the document of built-from-source
  • Loading branch information
KexinFeng authored Jul 13, 2022
1 parent bca48ab commit cea6f94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions api/src/main/java/ai/djl/ndarray/NDArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ default void set(NDIndex index, Function<NDArray, NDArray> function) {
}

/**
* Sets the {@code NDArray} by boolean mask.
* Sets the {@code NDArray} by boolean mask or integer index.
*
* @param index the boolean {@code NDArray} that indicates what to get
* @param index the boolean or integer {@code NDArray} that indicates what to get
* @param value the value to replace with
*/
default void set(NDArray index, Number value) {
set(new NDIndex().addBooleanIndex(index), value);
set(new NDIndex("{}", index), value);
}

/**
Expand Down Expand Up @@ -526,7 +526,7 @@ default NDArray get(NDManager manager, NDIndex index) {
/**
* Returns a partial {@code NDArray}.
*
* @param index the boolean or int {@code NDArray} that indicates what to get
* @param index the boolean or integer {@code NDArray} that indicates what to get
* @return the partial {@code NDArray}
*/
default NDArray get(NDArray index) {
Expand Down
6 changes: 3 additions & 3 deletions docs/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ If you have another project and want to use a custom version of DJL in it, you c

```groovy
dependencies {
implementation platform("ai.djl:bom:0.17.0-SNAPSHOT")
implementation platform("ai.djl:bom:<UPCOMING VERSION>-SNAPSHOT")
}
```

Currently, the `<UPCOMING VERSION> = 0.19.0`.
This snapshot version is the same as the custom DJL repository.

You also need to change directory to `djl/bom`. Then build and publish it to maven local same as was done in `djl`.
You also need to change directory to `djl/bom`. Then build and publish it to maven local same as what was done in `djl`.

From there, you may have to update the Maven or Gradle build of the project importing DJL to also look at the local maven repository cache for your locally published versions of DJL. For Maven, no changes are necessary. If you are using Gradle, you will have to add the maven local repository such as this [example](https://github.com/deepjavalibrary/djl-demo/blob/135c969d66d98d1672852e53a37e52ca1da3e325/pneumonia-detection/build.gradle#L11):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ public void testSetNumber() {
expected =
manager.create(new int[] {666, 666, 3, 666, 666, 6, 7, 8, 9}, new Shape(3, 3));
Assert.assertEquals(original, expected);

original = manager.arange(1, 10).reshape(3, 3);
original.set(index, 666);
expected =
manager.create(
new int[] {666, 666, 666, 666, 666, 666, 7, 8, 9}, new Shape(3, 3));
Assert.assertEquals(original, expected);
}
}

Expand Down

0 comments on commit cea6f94

Please sign in to comment.