Skip to content

Commit 925b3cb

Browse files
committed
add tf.bitwise.left_shift unit test #614.
1 parent 4309275 commit 925b3cb

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*****************************************************************************
2+
Copyright 2020 The TensorFlow.NET Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using Tensorflow.Operations;
18+
19+
namespace Tensorflow
20+
{
21+
public partial class tensorflow
22+
{
23+
public bitwise_ops bitwise = new bitwise_ops();
24+
}
25+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*****************************************************************************
2+
Copyright 2020 Haiping Chen. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Text;
20+
using static Tensorflow.Binding;
21+
22+
namespace Tensorflow.Operations
23+
{
24+
public class bitwise_ops
25+
{
26+
/// <summary>
27+
/// Elementwise computes the bitwise left-shift of `x` and `y`.
28+
/// https://www.tensorflow.org/api_docs/python/tf/bitwise/left_shift
29+
/// </summary>
30+
/// <param name="x"></param>
31+
/// <param name="y"></param>
32+
/// <param name="name"></param>
33+
/// <returns></returns>
34+
public Tensor left_shift(Tensor x, Tensor y, string name = null)
35+
{
36+
if (tf.Context.executing_eagerly())
37+
{
38+
var results = tf.Runner.TFE_FastPathExecute(tf.Context, tf.Context.DeviceName,
39+
"LeftShift", name,
40+
null,
41+
x, y);
42+
43+
return results[0];
44+
}
45+
46+
var _op = tf.OpDefLib._apply_op_helper("LeftShift", name, args: new { x, y });
47+
return _op.output;
48+
}
49+
}
50+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using Tensorflow;
7+
using static Tensorflow.Binding;
8+
9+
namespace TensorFlowNET.UnitTest.TF_API
10+
{
11+
[TestClass]
12+
public class BitwiseApiTest : TFNetApiTest
13+
{
14+
Tensor lhs = tf.constant(new int[] { -1, -5, -3, -14 });
15+
Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
16+
17+
[TestMethod]
18+
public void LeftShift()
19+
{
20+
var left_shift_result = tf.bitwise.left_shift(lhs, rhs);
21+
var expected = new int[] { -32, -5, -384, -28672 };
22+
var actual = left_shift_result.ToArray<int>();
23+
Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)