Skip to content

Commit

Permalink
Address PMD issues
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Nov 1, 2022
1 parent 0128ade commit 870fd60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 13 additions & 14 deletions api/src/main/java/ai/djl/nn/core/Multiplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
Expand Down Expand Up @@ -31,12 +31,13 @@

/**
* A Multiplication block performs an element-wise multiplication of inputs and weights as opposed
* to a {@link Linear} block which additionally sums up each element-wise multiplication. Similar to
* a {@link LinearCollection}, multiple split dimensions are supported but they remain optional
* (i.e. \(t\) can be zero). Other differences to a {@link Linear} block are that the weight has an
* additional dimension of size 1 interspersed (to broadcast the weight to every input of the batch
* when applying the internally used algebraic operation {@link NDArray#mul(NDArray)} ) and that
* biases are not supported.
* to a {@link Linear} block which additionally sums up each element-wise multiplication.
*
* <p>Similar to a {@link LinearCollection}, multiple split dimensions are supported but they remain
* optional (i.e. \(t\) can be zero). Other differences to a {@link Linear} block are that the
* weight has an additional dimension of size 1 interspersed (to broadcast the weight to every input
* of the batch when applying the internally used algebraic operation {@link NDArray#mul(NDArray)} )
* and that biases are not supported.
*
* <p>Caution: the output-channel is the left-most dimension as opposed to traditionally being the
* right-most dimension. As the output is one dimension larger than that of a {@link Linear} block,
Expand Down Expand Up @@ -131,13 +132,11 @@ protected void saveMetadata(DataOutputStream os) throws IOException {
@Override
public void loadMetadata(byte loadVersion, DataInputStream is)
throws IOException, MalformedModelException {
switch (loadVersion) {
case VERSION:
units = is.readLong();
inputFeatures = is.readLong();
break;
default:
throw new MalformedModelException("Unsupported encoding version: " + loadVersion);
if (loadVersion == VERSION) {
units = is.readLong();
inputFeatures = is.readLong();
} else {
throw new MalformedModelException("Unsupported encoding version: " + loadVersion);
}
inputShape = Shape.decode(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ public void testLinearCollection() throws IOException, MalformedModelException {
public void testMultiplication() throws IOException, MalformedModelException {

// 4 samples times 3 features
float[][] dataArr = new float[][] {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 10, 11}};
float[][] dataArr = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 10, 11}};

// 2 units times 3 features
float[][] weightArr = new float[][] {{0, 1, 2}, {10, 11, 12}};
float[][] weightArr = {{0, 1, 2}, {10, 11, 12}};

// store sum on Multiplication block's result
NDArray sum;
Expand Down

0 comments on commit 870fd60

Please sign in to comment.