| 53 | |
| 54 | template<std::floating_point T> |
| 55 | std::unique_ptr<CompressionMetadata> getFloatMetadata(const std::vector<T>& bufferToCompress, |
| 56 | const std::shared_ptr<FloatCompression<T>>& alg) { |
| 57 | alp::state alpMetadata; |
| 58 | std::vector<T> samples(bufferToCompress.size()); |
| 59 | alp::AlpEncode<T>::init(bufferToCompress.data(), 0, bufferToCompress.size(), samples.data(), |
| 60 | alpMetadata); |
| 61 | const auto& [min, max] = std::minmax_element(bufferToCompress.begin(), bufferToCompress.end()); |
| 62 | if (alpMetadata.scheme == alp::SCHEME::ALP) { |
| 63 | if (alpMetadata.best_k_combinations.size() > |
| 64 | 1) { // Only if more than 1 found top combinations we sample and search |
| 65 | alp::AlpEncode<T>::find_best_exponent_factor_from_combinations( |
| 66 | alpMetadata.best_k_combinations, alpMetadata.k_combinations, |
| 67 | bufferToCompress.data(), alpMetadata.vector_size, alpMetadata.fac, alpMetadata.exp); |
| 68 | } else if (alpMetadata.best_k_combinations.size() > 0) { |
| 69 | alpMetadata.exp = alpMetadata.best_k_combinations[0].first; |
| 70 | alpMetadata.fac = alpMetadata.best_k_combinations[0].second; |
| 71 | } |
| 72 | } else { |
| 73 | return std::make_unique<CompressionMetadata>(StorageValue(*min), StorageValue(*max), |
| 74 | CompressionType::UNCOMPRESSED); |
| 75 | } |
| 76 | |
| 77 | const auto floatEncodedValues = |
| 78 | std::views::all(bufferToCompress) | std::views::transform([alpMetadata](double val) { |
| 79 | const auto encoded_value = |
| 80 | alp::AlpEncode<double>::encode_value(val, alpMetadata.fac, alpMetadata.exp); |
| 81 | const auto decoded_value = alp::AlpDecode<double>::decode_value(encoded_value, |
| 82 | alpMetadata.fac, alpMetadata.exp); |
| 83 | return val == decoded_value ? encoded_value : 0; |
| 84 | }); |
| 85 | std::vector<T> vec(floatEncodedValues.begin(), floatEncodedValues.end()); |
| 86 | const auto& [minEncoded, maxEncoded] = std::minmax_element(vec.begin(), vec.end()); |
| 87 | const auto physicalType = |
| 88 | std::is_same_v<T, double> ? PhysicalTypeID::DOUBLE : PhysicalTypeID::FLOAT; |
| 89 | return std::make_unique<CompressionMetadata>(StorageValue(*min), StorageValue(*max), |
| 90 | alg->getCompressionType(), alpMetadata, StorageValue(*minEncoded), |
| 91 | StorageValue(*maxEncoded), physicalType); |
| 92 | } |
| 93 | |
| 94 | template<std::floating_point T> |
| 95 | ColumnChunkMetadata compressBuffer(const std::vector<T>& bufferToCompress, |
no test coverage detected