ONE - On-device Neural Engine
Loading...
Searching...
No Matches
RandomizeAction Struct Referencefinal
Collaboration diagram for RandomizeAction:

Public Member Functions

void run (TensorContext &ctx) override
 
- Public Member Functions inherited from nnkit::Action
virtual ~Action ()=default
 

Detailed Description

Definition at line 26 of file Randomize.cpp.

Member Function Documentation

◆ run()

void RandomizeAction::run ( TensorContext ctx)
inlineoverridevirtual

Implements nnkit::Action.

Definition at line 28 of file Randomize.cpp.

29 {
30 int seed = std::chrono::system_clock::now().time_since_epoch().count();
31
32 std::minstd_rand rand(seed);
33 std::normal_distribution<float> dist(0.0f, 2.0f);
34
35 for (uint32_t n = 0; n < ctx.size(); ++n)
36 {
38
39 auto fn = [&dist, &rand](const TensorContext &ctx, uint32_t n, Accessor<float> &t) {
42
43 for (IndexEnumerator e{ctx.shape(n)}; e.valid(); e.advance())
44 {
45 t.at(e.current()) = dist(rand);
46 }
47 };
48
49 ctx.getMutableFloatTensor(n, fn);
50 }
51 }
virtual uint32_t size(void) const =0

References nnkit::TensorContext::size().

Referenced by package.infer.session::inference().


The documentation for this struct was generated from the following file: