-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR closes #752 and makes the oneHot and bin built-in functions available on matrices in DaphneLib. Features: - Use oneHot(info) to apply one-hot-encoding on matrices in DaphneLib. - Use bin(numBins, Min, Max) or bin(numBins) to apply binning on matrices in DaphneLib. Changes: - Add oneHot and bin built-in functions for matrices in DaphneLib. - Script-level test case is added in test/api/python/, ensuring that execution works as expected. - Update doc/DaphneLib/APIRef.md to add oneHot and bin built-in functions for matrices. Furthermore, as a follow-up to #666, the inc parameter of the seq function is now also optional in DaphneLib. - Update doc/DaphneLib/APIRef.md for seq() function with optional inc argument. - Make argument inc optional with default value 1 in seq() function in DaphneLib.
- Loading branch information
1 parent
ec1835d
commit ee40181
Showing
6 changed files
with
71 additions
and
2 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
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
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
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
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,24 @@ | ||
# Copyright 2023 The DAPHNE Consortium | ||
# | ||
# 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. | ||
|
||
arg_m = reshape(seq(-2, 5), 2, 4); | ||
info_m = [-1, 0, 5, 6](1, 4); | ||
print(oneHot(arg_m, info_m)); | ||
|
||
arg_m_2 = reshape(seq(10, 70, 10), 1, 7); | ||
print(bin(arg_m_2, 3)); | ||
print(bin(arg_m_2, 3, 10, 70)); | ||
|
||
arg_m_3 = t([5.0, 20.0, nan, 40.0, inf, 60.0, 100.0]); | ||
print(bin(arg_m_3, 3, 10.0, 70.0)); |
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,29 @@ | ||
# Copyright 2023 The DAPHNE Consortium | ||
# | ||
# 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. | ||
|
||
import math | ||
from daphne.context.daphne_context import DaphneContext | ||
|
||
dc = DaphneContext() | ||
|
||
arg_m_1 = dc.seq(-2, 5).reshape(2, 4) | ||
info_m = dc.seq(-1, 0).rbind(dc.seq(5, 6)).reshape(1, 4) | ||
arg_m_1.oneHot(info_m).print().compute() | ||
|
||
arg_m_2 = dc.seq(10, 70, 10).reshape(1, 7) | ||
arg_m_2.bin(3).print().compute() | ||
arg_m_2.bin(3, 10, 70).print().compute() | ||
|
||
arg_m_3 = dc.seq(5.0, 20.0, 15).rbind(dc.fill(math.nan, 1, 1)).rbind(dc.fill(40.0, 1, 1)).rbind(dc.fill(math.inf, 1, 1)).rbind(dc.seq(60.0, 100.0, 40)) | ||
arg_m_3.reshape(1, 7).bin(3, 10.0, 70.0).print().compute() |