This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[Numpy] FFI for linalg ops #17795
Merged
Merged
[Numpy] FFI for linalg ops #17795
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file np_eigvals.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_eigvals.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_eigvals-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.eigvals") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_eigvals"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.eigvalsh") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_eigvalsh"); | ||
nnvm::NodeAttrs attrs; | ||
op::EigvalshParam param; | ||
param.UPLO = *((args[1].operator std::string()).c_str()); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::EigvalshParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file np_inv.cc | ||
* \brief Implementation of the API of functions in src/operator/tensor/la_op.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.inv") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_inv"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file np_pinv.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_pinv.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_pinv-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
inline static void _npi_pinv(runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_pinv"); | ||
op::PinvParam param; | ||
nnvm::NodeAttrs attrs; | ||
param.hermitian = args[2].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::PinvParam>(&attrs); | ||
int num_inputs = 2; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*(), args[1].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
} | ||
|
||
inline static void _npi_pinv_scalar_rcond(runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_pinv_scalar_rcond"); | ||
op::PinvScalarRcondParam param; | ||
nnvm::NodeAttrs attrs; | ||
param.rcond = args[1].operator double(); | ||
param.hermitian = args[2].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::PinvScalarRcondParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
} | ||
|
||
MXNET_REGISTER_API("_npi.pinv") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
if (args[1].type_code() == kDLFloat || args[1].type_code() == kDLInt) { | ||
_npi_pinv_scalar_rcond(args, ret); | ||
} else { | ||
_npi_pinv(args, ret); | ||
} | ||
}); | ||
|
||
} // namespace mxnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file np_potrf.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_potrf.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_potrf-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.cholesky") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_cholesky"); | ||
nnvm::NodeAttrs attrs; | ||
op::LaCholeskyParam param; | ||
param.lower = args[1].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::LaCholeskyParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file np_solve.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_solve.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.solve") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_solve"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 2; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*(), args[1].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.