| 213 | } |
| 214 | |
| 215 | std::shared_ptr<Array> RandomArrayGenerator::Boolean(int64_t size, |
| 216 | double true_probability, |
| 217 | double null_probability, |
| 218 | int64_t alignment, |
| 219 | MemoryPool* memory_pool) { |
| 220 | // The boolean generator does not care about the value distribution since it |
| 221 | // only calls the GenerateBitmap method. |
| 222 | using GenOpt = GenerateOptions<int, std::uniform_int_distribution<int>>; |
| 223 | |
| 224 | BufferVector buffers{2}; |
| 225 | // Need 2 distinct generators such that probabilities are not shared. |
| 226 | |
| 227 | // The "GenerateBitmap" function is written to generate validity bitmaps |
| 228 | // parameterized by the null probability, which is the probability of 0. For |
| 229 | // boolean data, the true probability is the probability of 1, so to use |
| 230 | // GenerateBitmap we must provide the probability of false instead. |
| 231 | GenOpt value_gen(seed(), 0, 1, 1 - true_probability); |
| 232 | |
| 233 | GenOpt null_gen(seed(), 0, 1, null_probability); |
| 234 | |
| 235 | int64_t null_count = 0; |
| 236 | buffers[0] = *AllocateEmptyBitmap(size, alignment, memory_pool); |
| 237 | null_gen.GenerateBitmap(buffers[0]->mutable_data(), size, &null_count); |
| 238 | |
| 239 | buffers[1] = *AllocateEmptyBitmap(size, alignment, memory_pool); |
| 240 | value_gen.GenerateBitmap(buffers[1]->mutable_data(), size, nullptr); |
| 241 | |
| 242 | auto array_data = ArrayData::Make(arrow::boolean(), size, buffers, null_count); |
| 243 | return std::make_shared<BooleanArray>(array_data); |
| 244 | } |
| 245 | |
| 246 | #define PRIMITIVE_RAND_IMPL(Name, CType, ArrowType, Distribution) \ |
| 247 | std::shared_ptr<Array> RandomArrayGenerator::Name( \ |