forked from sbrunk/storch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes sbrunk#29 Bonus additions: - Add `torch.multinomial` [RandomSamplingOps] - Add `torch.randint` [RandomSamplingOps] - Add `torch.gradient` [PointwiseOps] - Add `torch.nn.functional.oneHot`
- Loading branch information
Showing
16 changed files
with
2,413 additions
and
2,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 storch.dev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package torch | ||
package nn | ||
package functional | ||
|
||
import org.bytedeco.pytorch.global.torch as torchNative | ||
|
||
/** Takes LongTensor with index values of shape `(*)` and returns a tensor of shape `(*, | ||
* numClasses)` that have zeros everywhere except where the index of last dimension matches the | ||
* corresponding value of the input tensor, in which case it will be 1. | ||
*/ | ||
def oneHot(input: Tensor[Int64], numClasses: Long = -1): Tensor[Int64] = | ||
Tensor(torchNative.one_hot(input.native, numClasses)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2022 storch.dev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package torch | ||
|
||
/** BLAS and LAPACK Operations | ||
* | ||
* https://pytorch.org/docs/stable/torch.html#blas-and-lapack-operations | ||
*/ | ||
|
||
def matmul[D1 <: DType, D2 <: DType](t1: Tensor[D1], t2: Tensor[D2]): Tensor[Promoted[D1, D2]] = | ||
t1.matmul(t2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2022 storch.dev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package torch | ||
|
||
import org.bytedeco.pytorch.global.torch as torchNative | ||
|
||
/** Comparison Ops | ||
* | ||
* https://pytorch.org/docs/stable/torch.html#comparison-ops | ||
*/ | ||
|
||
def allclose( | ||
input: Tensor[?], | ||
other: Tensor[?], | ||
rtol: Double = 1e-05, | ||
atol: Double = 1e-08, | ||
equalNan: Boolean = false | ||
) = | ||
torchNative.allclose(input.native, other.native, rtol, atol, equalNan) |
Oops, something went wrong.