2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
2019-06-06 14:21:15 +02:00
|
|
|
*
|
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
2021-02-01 13:31:45 +01:00
|
|
|
* See the NOTICE file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2019-06-06 14:21:15 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
|
|
|
// @author raver119@gmail.com
|
|
|
|
//
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/op_boilerplate.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#if NOT_EXCLUDED(OP_set_seed)
|
|
|
|
|
|
|
|
#include <ops/declarable/CustomOperations.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <legacy/NativeOps.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-06-06 14:21:15 +02:00
|
|
|
namespace ops {
|
|
|
|
CUSTOM_OP_IMPL(set_seed, -2, 1, false, 0, -2) {
|
2019-08-15 12:54:47 +02:00
|
|
|
// REQUIRE_TRUE(block.getRNG() != nullptr, 0, "RNG should be defined in Graph");
|
|
|
|
auto rng = block.getRng(); //.getRNG();
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
Nd4jLong seed = 0;
|
|
|
|
if (block.getIArguments()->size() > 0) {
|
|
|
|
seed = INT_ARG(0);
|
|
|
|
} else if (block.width() > 0) {
|
|
|
|
auto input = INPUT_VARIABLE(0);
|
|
|
|
REQUIRE_TRUE(input->isScalar(),0 ,"SetSeed: Seed operand should be scalar");
|
|
|
|
seed = input->e<Nd4jLong>(0);
|
|
|
|
} else {
|
|
|
|
REQUIRE_TRUE(false, 0, "SetSeed: either IArg or scalr input should be provided");
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this approach isn't really good for cuda, since it'll assume that CUDA might get nullptr instead of stream
|
2019-08-15 12:54:47 +02:00
|
|
|
//refreshBuffer(nullptr, seed, (Nd4jPointer) rng);
|
|
|
|
rng.setSeed((int)seed);
|
2019-06-06 14:21:15 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_SHAPE_FN(set_seed) {
|
2020-06-06 14:26:55 +02:00
|
|
|
auto newshape = ConstantShapeHelper::getInstance().scalarShapeInfo(block.dataType());
|
2019-06-06 14:21:15 +02:00
|
|
|
return SHAPELIST(newshape);
|
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_TYPES(set_seed) {
|
|
|
|
getOpDescriptor()
|
|
|
|
->setAllowedInputTypes({ALL_INTS})
|
|
|
|
->setAllowedOutputTypes({ALL_FLOATS});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 13:34:08 +02:00
|
|
|
#endif
|