NumPy API Compatibility#
NKIPy provides NumPy-compatible APIs that allow you to use familiar NumPy functions with NKIPy tensors. When you call a NumPy function on an NKIPy tensor, it automatically dispatches to the corresponding NKIPy operation.
Usage Example#
import numpy as np
from nkipy.core import ops
# Inside a traced kernel, you can use NumPy functions directly:
# result = np.add(tensor_a, tensor_b) # Dispatches to ops.add
# result = np.matmul(tensor_a, tensor_b) # Dispatches to ops.matmul
Supported NumPy Functions#
Binary Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Comparison Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unary Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reduction Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
|
|
Linear Algebra#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
Transform Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Creation Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
Indexing Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
|
|
|
|
Broadcast and Copy Operations#
NumPy Function |
NKIPy Operation |
|---|---|
|
|
|
|
Unsupported NumPy Operations#
The following NumPy operations are not supported due to hardware limitations:
NumPy Function |
Reason |
|---|---|
|
not supported on hardware |
|
not supported |
|
not supported, use np.copy for “y = +x” operation |
|
not a supported activation |
Workarounds#
For some unsupported operations, workarounds exist:
np.mod/np.remainder: Usea - b * np.floor(a/b)np.positive: Usenp.copy(x)for they = +xoperation