|
7 | 7 | # |
8 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | # |
10 | | -# Unless required by applicable law or agreed to in writing, software |
| 10 | +# Unless required by applicable law or agreed to in writing, |
11 | 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 | # ============================================================================== |
16 | 16 |
|
17 | 17 | import numpy as np |
18 | | -from sklearnex.svm.poly_kernel import poly_kernel as skl_poly_kernel |
19 | | -from onedal.primitives import poly_kernel as onedal_poly_kernel |
| 18 | + |
| 19 | +from sklearnex.svm.poly_kernel import poly_kernel |
| 20 | + |
20 | 21 |
|
21 | 22 | def test_poly_kernel_basic(): |
22 | 23 | X = np.array([[1, 2], [3, 4]]) |
23 | 24 | Y = np.array([[5, 6], [7, 8]]) |
24 | 25 |
|
25 | | - # sklearnex interface result |
26 | | - K_skl = skl_poly_kernel(X, Y, gamma=0.5, coef0=1.0, degree=2) |
27 | | - # direct oneDAL result |
28 | | - K_onedal = onedal_poly_kernel(X, Y, gamma=0.5, coef0=1.0, degree=2) |
| 26 | + K = poly_kernel(X, Y, gamma=1.0, coef0=0.0, degree=2) |
| 27 | + |
| 28 | + # expected polynomial kernel manually |
| 29 | + expected = (np.dot(X, Y.T)) ** 2 |
| 30 | + assert np.allclose(K, expected), "Polynomial kernel computation is incorrect" |
29 | 31 |
|
30 | | - # check they are close |
31 | | - assert np.allclose(K_skl, K_onedal) |
| 32 | + |
| 33 | +def test_poly_kernel_default_Y(): |
| 34 | + X = np.array([[1, 2], [3, 4]]) |
| 35 | + K = poly_kernel(X) |
| 36 | + expected = (np.dot(X, X.T)) ** 3 # default degree=3 |
| 37 | + assert np.allclose(K, expected), "Polynomial kernel with Y=None is incorrect" |
0 commit comments