forked from modular/mojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_interop.py
36 lines (27 loc) · 1.12 KB
/
simple_interop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2023, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# 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.
# ===----------------------------------------------------------------------=== #
# Simple python program to test interop
import importlib
import sys
import subprocess
if not importlib.find_loader("numpy"):
print("Numpy not found, installing...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "numpy"])
import numpy as np
from timeit import timeit
def test_interop_func():
print("Hello from Python!")
a = np.array([1, 2, 3])
print("I can even print a numpy array: ", a)
if __name__ == "__main__":
print(timeit(lambda: test_interop_func(), number=1))