fix code style

This commit is contained in:
liyang 2020-01-18 12:16:34 +08:00
parent b914c4262d
commit 1dab2b756d
2 changed files with 75 additions and 82 deletions

View File

@ -1,24 +1,23 @@
#include <Functions/IFunction.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnNullable.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypesNumber.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnsNumber.h>
#include <Columns/ColumnNullable.h>
#include <Common/FieldVisitors.h>
#include <Common/memcmpSmall.h>
#include <Common/assert_cast.h>
#include <Interpreters/castColumn.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/IFunction.h>
#include <Interpreters/Context.h>
#include <Interpreters/castColumn.h>
#include <Common/FieldVisitors.h>
#include <Common/assert_cast.h>
#include <Common/memcmpSmall.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
@ -32,7 +31,7 @@ class FunctionArrayScalarProduct : public IFunction
public:
static constexpr auto name = Name::name;
static FunctionPtr create(const Context & context) { return std::make_shared<FunctionArrayScalarProduct>(context); }
FunctionArrayScalarProduct(const Context & context_): context(context_) {}
FunctionArrayScalarProduct(const Context & context_) : context(context_) {}
private:
using ResultColumnType = ColumnVector<typename Method::ResultType>;
@ -40,16 +39,11 @@ private:
template <typename T>
bool executeNumber(Block & block, const ColumnNumbers & arguments, size_t result)
{
return executeNumberNumber<T, UInt8>(block, arguments, result)
|| executeNumberNumber<T, UInt16>(block, arguments, result)
|| executeNumberNumber<T, UInt32>(block, arguments, result)
|| executeNumberNumber<T, UInt64>(block, arguments, result)
|| executeNumberNumber<T, Int8>(block, arguments, result)
|| executeNumberNumber<T, Int16>(block, arguments, result)
|| executeNumberNumber<T, Int32>(block, arguments, result)
|| executeNumberNumber<T, Int64>(block, arguments, result)
|| executeNumberNumber<T, Float32>(block, arguments, result)
|| executeNumberNumber<T, Float64>(block, arguments, result);
return executeNumberNumber<T, UInt8>(block, arguments, result) || executeNumberNumber<T, UInt16>(block, arguments, result)
|| executeNumberNumber<T, UInt32>(block, arguments, result) || executeNumberNumber<T, UInt64>(block, arguments, result)
|| executeNumberNumber<T, Int8>(block, arguments, result) || executeNumberNumber<T, Int16>(block, arguments, result)
|| executeNumberNumber<T, Int32>(block, arguments, result) || executeNumberNumber<T, Int64>(block, arguments, result)
|| executeNumberNumber<T, Float32>(block, arguments, result) || executeNumberNumber<T, Float64>(block, arguments, result);
}
@ -58,29 +52,31 @@ private:
{
ColumnPtr col1 = block.getByPosition(arguments[0]).column->convertToFullColumnIfConst();
ColumnPtr col2 = block.getByPosition(arguments[1]).column->convertToFullColumnIfConst();
if (! col1 || ! col2)
if (!col1 || !col2)
return false;
const ColumnArray* col_array1 = checkAndGetColumn<ColumnArray>(col1.get());
const ColumnArray* col_array2 = checkAndGetColumn<ColumnArray>(col2.get());
if (! col_array1 || ! col_array2)
const ColumnArray * col_array1 = checkAndGetColumn<ColumnArray>(col1.get());
const ColumnArray * col_array2 = checkAndGetColumn<ColumnArray>(col2.get());
if (!col_array1 || !col_array2)
return false;
const ColumnVector<T> * col_nested1 = checkAndGetColumn<ColumnVector<T>>(col_array1->getData());
const ColumnVector<U> * col_nested2 = checkAndGetColumn<ColumnVector<U>>(col_array2->getData());
if (! col_nested1 || ! col_nested2)
if (!col_nested1 || !col_nested2)
return false;
auto col_res = ResultColumnType::create();
vector(col_nested1->getData(), col_array1->getOffsets(),
col_nested2->getData(), col_array2->getOffsets(), col_res->getData());
vector(col_nested1->getData(), col_array1->getOffsets(), col_nested2->getData(), col_array2->getOffsets(), col_res->getData());
block.getByPosition(result).column = std::move(col_res);
return true;
}
template <typename T, typename U>
static void vector(const PaddedPODArray<T> & data1, const ColumnArray::Offsets & offsets1,
const PaddedPODArray<U> & data2, const ColumnArray::Offsets & offsets2,
static void vector(
const PaddedPODArray<T> & data1,
const ColumnArray::Offsets & offsets1,
const PaddedPODArray<U> & data2,
const ColumnArray::Offsets & offsets2,
PaddedPODArray<typename Method::ResultType> & result)
{
size_t size = offsets1.size();
@ -88,7 +84,8 @@ private:
ColumnArray::Offset current_offset1 = 0;
ColumnArray::Offset current_offset2 = 0;
for (size_t i = 0; i < size; ++i) {
for (size_t i = 0; i < size; ++i)
{
size_t array1_size = offsets1[i] - current_offset1;
size_t array2_size = offsets2[i] - current_offset2;
result[i] = Method::apply(data1, current_offset1, array1_size, data2, current_offset2, array2_size);
@ -100,10 +97,7 @@ private:
public:
/// Get function name.
String getName() const override
{
return name;
}
String getName() const override { return name; }
size_t getNumberOfArguments() const override { return 2; }
@ -115,16 +109,15 @@ public:
{
const DataTypeArray * array_type = checkAndGetDataType<DataTypeArray>(arguments[i].get());
if (!array_type)
throw Exception("All argument for function " + getName() + " must be an array.",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception("All argument for function " + getName() + " must be an array.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
auto & nested_type = array_type->getNestedType();
WhichDataType which(nested_type);
bool is_number = which.isNativeInt() || which.isNativeUInt() || which.isFloat();
if (! is_number)
if (!is_number)
{
throw Exception(getName() + " cannot process values of type " + nested_type->getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
throw Exception(
getName() + " cannot process values of type " + nested_type->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
nested_types[i] = nested_type;
}
@ -135,19 +128,14 @@ public:
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /* input_rows_count */) override
{
if (!(executeNumber<UInt8>(block, arguments, result)
|| executeNumber<UInt16>(block, arguments, result)
|| executeNumber<UInt32>(block, arguments, result)
|| executeNumber<UInt64>(block, arguments, result)
|| executeNumber<Int8>(block, arguments, result)
|| executeNumber<Int16>(block, arguments, result)
|| executeNumber<Int32>(block, arguments, result)
|| executeNumber<Int64>(block, arguments, result)
|| executeNumber<Float32>(block, arguments, result)
|| executeNumber<Float64>(block, arguments, result)))
throw Exception{"Illegal column " + block.getByPosition(arguments[0]).column->getName()
+ " of first argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN};
if (!(executeNumber<UInt8>(block, arguments, result) || executeNumber<UInt16>(block, arguments, result)
|| executeNumber<UInt32>(block, arguments, result) || executeNumber<UInt64>(block, arguments, result)
|| executeNumber<Int8>(block, arguments, result) || executeNumber<Int16>(block, arguments, result)
|| executeNumber<Int32>(block, arguments, result) || executeNumber<Int64>(block, arguments, result)
|| executeNumber<Float32>(block, arguments, result) || executeNumber<Float64>(block, arguments, result)))
throw Exception{"Illegal column " + block.getByPosition(arguments[0]).column->getName() + " of first argument of function "
+ getName(),
ErrorCodes::ILLEGAL_COLUMN};
}
private:

View File

@ -1,12 +1,14 @@
#include <vector>
#include <algorithm>
#include <vector>
#include <Functions/FunctionFactory.h>
#include "arrayScalarProduct.h"
namespace DB
{
struct NameAUC { static constexpr auto name = "auc"; };
struct NameAUC
{
static constexpr auto name = "auc";
};
class AUCImpl
{
@ -22,20 +24,24 @@ public:
static DataTypePtr getReturnType(const DataTypePtr & /* nested_type1 */, const DataTypePtr & nested_type2)
{
WhichDataType which2(nested_type2);
if (! which2.isUInt8()) {
throw Exception(std::string(NameAUC::name) + "lable type must be UInt8",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
if (!which2.isUInt8())
{
throw Exception(std::string(NameAUC::name) + "lable type must be UInt8", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
return std::make_shared<DataTypeNumber<ResultType>>();
}
template <typename T, typename U>
static ResultType apply(const PaddedPODArray<T> & scores, ColumnArray::Offset score_offset, size_t score_len,
const PaddedPODArray<U> & labels, ColumnArray::Offset label_offset, size_t label_len)
static ResultType apply(
const PaddedPODArray<T> & scores,
ColumnArray::Offset score_offset,
size_t score_len,
const PaddedPODArray<U> & labels,
ColumnArray::Offset label_offset,
size_t label_len)
{
if (score_len != label_len)
throw Exception{"Unmatched length of arrays in " + std::string(NameAUC::name),
ErrorCodes::LOGICAL_ERROR};
throw Exception{"Unmatched length of arrays in " + std::string(NameAUC::name), ErrorCodes::LOGICAL_ERROR};
if (score_len == 0)
return {};
@ -52,8 +58,7 @@ public:
else
++num_neg;
}
std::sort(pairs.begin(), pairs.end(),
[](const auto & lhs, const auto & rhs) {return lhs.score < rhs.score; });
std::sort(pairs.begin(), pairs.end(), [](const auto & lhs, const auto & rhs) { return lhs.score < rhs.score; });
// Calculate AUC
size_t curr_cnt = 0;
@ -81,7 +86,7 @@ public:
last_score = pairs[i].score;
}
rank_sum += ResultType(curr_sum * curr_pos_cnt) / curr_cnt;
return (rank_sum - num_pos*(num_pos+1)/2)/(num_pos * num_neg);
return (rank_sum - num_pos * (num_pos + 1) / 2) / (num_pos * num_neg);
}
};