ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
numpy_random.h
Go to the documentation of this file.
1#pragma once
2
3#include <nlohmann/json.hpp>
4#include <util/irep/expr.h>
9
10#include <map>
11#include <optional>
12#include <set>
13#include <string>
14#include <vector>
15
17
24{
25public:
26 numpy_random(python_converter &converter, const nlohmann::json &call);
27
28 static bool
29 is_random_call(const nlohmann::json &call, const nlohmann::json &ast);
30
31 exprt get();
32
35 static std::optional<std::vector<std::size_t>>
36 output_shape(const nlohmann::json &call, const nlohmann::json &ast);
37
41 static std::string
42 list_annotation(const nlohmann::json &call, const nlohmann::json &ast);
43
44private:
45 python_converter &converter_;
46 const nlohmann::json &call_;
48 std::string function_;
49 std::string name_;
50 locationt location_;
51 code_blockt block_;
53 std::map<std::string, exprt> values_;
54 std::string dtype_;
55 std::set<std::string> bound_;
58 std::string error_;
60 std::vector<long long> shape_;
61 bool sized_ = false;
62 static constexpr long long max_samples = 1024;
63 typet element_type_;
65 exprt population_;
66 bool replace_ = true;
67 bool has_probabilities_ = false;
68 std::vector<exprt> drawn_indices_;
69
70 exprt reject_unmodelled();
71 void bind_arguments();
72 void bind_positional();
73 void bind_keywords();
74 void bind(const std::string &param, const nlohmann::json &arg);
75 [[noreturn]] void reject_unpacked() const;
76 std::string missing_argument() const;
77 exprt read_population(const nlohmann::json &arg);
78 exprt materialize_population(const nlohmann::json &elements);
79 [[noreturn]] void reject_population() const;
80 bool holds_numpy_array(const nlohmann::json &arg) const;
81 bool read_replace(const nlohmann::json &arg) const;
82 bool read_probabilities(const nlohmann::json &arg);
83 long long population_size() const;
84 long long sample_count() const;
85 void validate_choice();
86 exprt sample_choice();
87 bool takes_dimensions() const;
88 void bind_dimensions();
89 void read_shape(const nlohmann::json &size);
90 [[noreturn]] void reject_shape() const;
91 void check_shape();
92 exprt sample_array();
93 void fill(const exprt &target);
94 exprt evaluate_once(const nlohmann::json &arg, const std::string &param);
95 exprt value(const std::string &param) const;
96
97 void validate();
98 void validate_randint();
99 exprt sample();
100 exprt sample_integer();
101 exprt sample_real();
102 exprt nan_from_parameters(const exprt &sample);
103
105 exprt fresh(const typet &type, const exprt &value = nil_exprt());
106 void assume(const exprt &cond);
107 void
108 raise_if(const exprt &cond, const std::string &exc, const std::string &msg);
109 exprt finish(const exprt &result);
110};
Definition std_code.h:49
Definition expr.h:34
Definition location.h:7
Definition std_expr.h:1168
static std::string list_annotation(const nlohmann::json &call, const nlohmann::json &ast)
"list" for a random call that returns an array, so the annotator types it and arithmetic on it as it ...
Definition numpy_random.cpp:247
exprt get()
Definition numpy_random.cpp:254
static bool is_random_call(const nlohmann::json &call, const nlohmann::json &ast)
Definition numpy_random.cpp:196
static std::optional< std::vector< std::size_t > > output_shape(const nlohmann::json &call, const nlohmann::json &ast)
The literal output shape of a random call that returns an array, read from the source; nullopt for a ...
Definition numpy_random.cpp:214
numpy_random(python_converter &converter, const nlohmann::json &call)
Definition numpy_random.cpp:185
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
Definition type.h:9
pthread_cond_t cond
Definition cuda.h:50
@ elements
The container's own elements: lists, sets, tuples, and a dict's internal keys/values lists.
Definition element_type_registry.h:24
void * value
Definition solidity_mapping.c:2