mirror of https://github.com/llvm/torch-mlir
Add create_array_from_tensor and copy_to_tensor ops.
parent
b2708e4687
commit
f6721c173d
|
@ -88,8 +88,14 @@ def Numpy_NdArrayType : DialectType<Numpy_Dialect,
|
|||
// Type predicates
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Any tensor type legal for numpy ops.
|
||||
def Numpy_AnyTensor : TensorOf<[AnyType]>;
|
||||
|
||||
// Any type, at any stage of analysis that can represent a numpy array.
|
||||
def Numpy_AnyArray : TensorOf<[AnyType]>;
|
||||
def Numpy_AnyArray : AnyTypeOf<[
|
||||
Numpy_AnyTensor,
|
||||
Numpy_NdArrayType
|
||||
]>;
|
||||
|
||||
def Numpy_SliceTupleElement : AnyTypeOf<[
|
||||
// Supports both "Index Arrays" and "Boolean mask index arrays".
|
||||
|
|
|
@ -34,6 +34,46 @@ def Numpy_NarrowOp : Numpy_Op<"narrow", []> {
|
|||
}];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// NdArray type handling
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
def Numpy_CopyToArray : Numpy_Op<"create_array_from_tensor", [NoSideEffect]> {
|
||||
let summary = "Creates an ndarray from a tensor.";
|
||||
let description = [{
|
||||
Creates a new ndarray that will contain the data of the given tensor.
|
||||
}];
|
||||
let arguments = (ins
|
||||
Numpy_AnyTensor:$source
|
||||
);
|
||||
let results = (outs
|
||||
Numpy_AnyArray:$dest
|
||||
);
|
||||
let assemblyFormat = [{
|
||||
$source attr-dict `:` functional-type($source, $dest)
|
||||
}];
|
||||
}
|
||||
|
||||
def Numpy_CopyToTensor : Numpy_Op<"copy_to_tensor", []> {
|
||||
let summary = "Copies an ndarray, yielding a value-typed tensor.";
|
||||
let description = [{
|
||||
The semantics of this operation connote a copy of the data in the source
|
||||
ndarray, producing a destination value that will have the value in the
|
||||
ndarray at the point of the copy. Of course, downstream transformations
|
||||
are free to rearrange things to elide the copy or otherwise eliminate the
|
||||
need for it.
|
||||
}];
|
||||
let arguments = (ins
|
||||
Numpy_NdArrayType:$source
|
||||
);
|
||||
let results = (outs
|
||||
Numpy_AnyTensor:$dest
|
||||
);
|
||||
let assemblyFormat = [{
|
||||
$source attr-dict `:` functional-type($source, $dest)
|
||||
}];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// Universal function ops (ufunc)
|
||||
// See: https://docs.scipy.org/doc/numpy/reference/ufuncs.html
|
||||
|
|
Loading…
Reference in New Issue