• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP lookupType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中lookupType函数的典型用法代码示例。如果您正苦于以下问题:PHP lookupType函数的具体用法?PHP lookupType怎么用?PHP lookupType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lookupType函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: CreateView

function CreateView($args, $targs)
{
    grokit_assert(\count($args) == 1, 'CreateView supports exactly 1 input');
    $type = $args[0];
    grokit_assert($type->is('array'), 'CreateView cannot create view on non-array type');
    $innerType = $type->get('type');
    $size = $type->get('size');
    $viewType = lookupType('BASE::FixedArrayView', ['type' => $innerType, 'size' => $size]);
    $funcname = generate_name('CreateView_');
    ?>

<?php 
    echo $viewType;
    ?>
 <?php 
    echo $funcname;
    ?>
( const <?php 
    echo $type;
    ?>
 &array ) {
	return <?php 
    echo $viewType;
    ?>
(array.data());
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcname, 'input' => $args, 'result' => $viewType, 'deterministic' => false];
}
开发者ID:gokulp,项目名称:grokit,代码行数:30,代码来源:CreateView.h.php


示例2: _defineStdMathFunction

function _defineStdMathFunction($name, $args, $ret, $lib)
{
    $f = function () use($name, $args, $ret, $lib) {
        $inputs = [];
        $count = 0;
        foreach ($args as $arg) {
            $inputs['arg' . $count] = lookupType($arg);
            $count += 1;
        }
        $retType = lookupType($ret);
        $hash = \grokit\hashComplex(['BASE::' . $name, $args, $ret]);
        ?>
inline <?php 
        echo $retType;
        ?>
 <?php 
        echo $name;
        ?>
( <?php 
        echo typed_args($inputs);
        ?>
 ) {
    return std::<?php 
        echo $name;
        ?>
(<?php 
        echo args($inputs);
        ?>
);
}
<?php 
        return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $inputs, 'result' => $retType, 'deterministic' => true, 'system_headers' => $lib, 'hash' => $hash];
    };
    declareFunction($name, $args, $f);
}
开发者ID:gokulp,项目名称:grokit,代码行数:35,代码来源:Number-Funcs.h.php


示例3: Hash

function Hash($args, array $t_args = [])
{
    $funcName = generate_name('Hash_');
    $retType = lookupType('base::BIGINT');
    echo $retType;
    ?>
 <?php 
    echo $funcName;
    ?>
( <?php 
    echo const_typed_ref_args($args);
    ?>
 ) {
    uint64_t hashVal = H_b;
<?php 
    foreach ($args as $name => $type) {
        ?>
    hashVal = CongruentHash(<?php 
        echo $name;
        ?>
, hashVal);
<?php 
    }
    // foreach argument
    ?>
    return static_cast<<?php 
    echo $retType;
    ?>
>(hashVal);
}
<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcName, 'result' => $retType, 'system_headers' => ['cinttypes'], 'user_headers' => ['HashFunctions.h'], 'deterministic' => true];
}
开发者ID:gokulp,项目名称:grokit,代码行数:33,代码来源:Hash-Funcs.h.php


示例4: type

 public function type()
 {
     if (!is_null($this->type)) {
         return lookupType($this->type->name(), $this->type->template_args());
     }
     if (is_null($this->type_ast)) {
         return null;
     }
     return parseType($this->type_ast);
 }
开发者ID:gokulp,项目名称:grokit,代码行数:10,代码来源:grokit_attman.php


示例5: Contains

function Contains($args, $targs)
{
    grokit_assert(\count($args) == 1, 'Contains supports exactly 1 input, ' . \count($args) . ' given');
    grokit_assert(array_key_exists('values', $targs), 'Contains() requires a "values" template argument');
    $inputName = 'contains_input';
    $inputType = $args[0];
    $boolType = lookupType('base::bool');
    $typename = generate_name('_ContainsType');
    $funcname = generate_name('Contains');
    $sys_headers = ['cstddef'];
    $use_mct = get_default($targs, 'use.mct', false);
    if ($use_mct) {
        $sys_headers[] = 'mct/closed-hash-set.hpp';
        $setType = 'mct::closed_hash_set<' . $inputType . ', KeyHash>';
    } else {
        $sys_headers[] = 'unordered_set';
        $setType = 'std::unordered_set<' . $inputType . ', KeyHash>';
    }
    $values = $targs['values'];
    grokit_assert(is_array($values), 'Contains(): values argument must be an array of strings');
    $quotedValues = [];
    $escapeChars = "\"'\n\r\t\\";
    foreach ($values as $index => $val) {
        grokit_assert(is_string($val), "Contains(): Value at index {$index} is not a string");
        $quotedValues[] = '"' . addcslashes($val, $escapeChars) . '"';
    }
    $nVals = \count($quotedValues);
    ?>

class <?php 
    echo $typename;
    ?>
 {
public:
	struct KeyHash {
		std::size_t operator () (const <?php 
    echo $inputType;
    ?>
 & val) const {
			return static_cast<std::size_t>(Hash(val));
		}
	};

	using Set = <?php 
    echo $setType;
    ?>
;

	// Singleton
	static const <?php 
    echo $typename;
    ?>
 instance;

private:
	static const char* str_values[<?php 
    echo $nVals;
    ?>
];

	Set values;

	<?php 
    echo $typename;
    ?>
():
		values()
	{
		<?php 
    echo $inputType;
    ?>
 temp;
		for( auto str : str_values ) {
			FromString(temp, str);
			values.insert(temp);
		}
	}

public:
	bool exists(const <?php 
    echo $inputType;
    ?>
 & <?php 
    echo $inputName;
    ?>
) const {
		return values.count(<?php 
    echo $inputName;
    ?>
) > 0;
	}
};

const <?php 
    echo $typename;
    ?>
 <?php 
    echo $typename;
    ?>
::instance;
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:Contains.h.php


示例6: BloomFilter

/**
 *  A GLA that estimates the cardinality of a dataset using a bloom filter of
 *  a configurable size.
 *
 *  Note: This filter has very high performance, so long as all of the states
 *  fit into cache, preferably L1 or L2, but L3 is also fine. Once the states
 *  are large enough that all of them cannot fit inside L3 cache at the same
 *  time, performance takes a nose dive (4x loss minimum).
 */
function BloomFilter(array $t_args, array $input, array $output)
{
    grokit_assert(\count($output) == 1, 'BloomFilter produces only 1 value, ' . \count($output) . ' outputs given.');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'BloomFilter output must be numeric!');
    $exp = get_first_key_default($t_args, ['exponent'], 16);
    grokit_assert(is_integer($exp), 'BloomFilter exponent must be an integer.');
    grokit_assert($exp > 0 && $exp < 64, 'BloomFilter exponent must be in range (0,64), ' . $exp . ' given.');
    $nullCheck = get_default($t_args, 'null.check', false);
    $nullable = [];
    if (is_bool($nullCheck)) {
        foreach ($input as $name => $type) {
            $nullable[$name] = $nullCheck;
        }
    } else {
        if (is_array($nullCheck)) {
            foreach ($input as $name => $type) {
                $nullable[$name] = false;
            }
            foreach ($nullCheck as $index => $n) {
                grokit_assert(is_string($n), 'BloomFilster null.check has invalid value at position ' . $index);
                grokit_assert(array_key_exists($n, $nullable), 'BloomFilster null.check has unknown input ' . $n . ' at position ' . $index);
                $nullable[$n] = true;
            }
        } else {
            grokit_error('BloomFilster null.check must be boolean or list of inputs to check for nulls');
        }
    }
    $debug = get_default($t_args, 'debug', 0);
    $bits = pow(2, $exp);
    $bytes = ceil($bits / 8.0);
    // Calculate the number of bits set for every possible value of a byte
    $nBits = [];
    for ($i = 0; $i < 256; $i++) {
        $n = $i;
        $b = 0;
        while ($n > 0) {
            $n &= $n - 1;
            $b++;
        }
        $nBits[$i] = $b;
    }
    $className = generate_name('BloomFilter');
    ?>
class <?php 
    echo $className;
    ?>
 {
    static constexpr size_t BITS = <?php 
    echo $bits;
    ?>
;
    static constexpr size_t BYTES = <?php 
    echo $bytes;
    ?>
;
    static constexpr size_t MASK = BITS - 1;
    static constexpr std::array<unsigned char, 256> BITS_SET = { <?php 
    echo implode(', ', $nBits);
    ?>
 };
    static constexpr std::array<unsigned char, 8> BIT_MASKS = {
        0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
    };

    size_t count;

    std::array<unsigned char, BYTES> set;
    //unsigned char set[BYTES];
    //std::bitset<BITS> set;

public:
    <?php 
    echo $className;
    ?>
() : count(0), set() {
        for( size_t i = 0; i < BYTES; i++ ) { //>
            set[i] = 0;
        }
    }

    ~<?php 
    echo $className;
    ?>
() { }

//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:BloomFilter.h.php


示例7: ExtremeTuples

function ExtremeTuples(array $t_args, array $inputs, array $outputs)
{
    $extremes = get_first_key($t_args, ['extremes']);
    $nExt = \count($extremes);
    grokit_assert($nExt > 0, 'No extremes specified for ExtremeTuples GLA.');
    if (\count($inputs) == 0) {
        grokit_assert(array_key_exists('inputs', $t_args), 'No arguments specified for ExtremeTuples GLA.');
        $count = 0;
        foreach ($t_args['inputs'] as $type) {
            if (is_identifier($type)) {
                $type = lookupType(strval($type));
            }
            grokit_assert(is_datatype($type), 'Only datatypes can be specified as inputs to ' . 'the ExtremeTuples GLA');
            $name = 'et_val' . $count;
            $inputs[$name] = $type;
        }
    }
    $outputMap = [];
    reset($outputs);
    foreach ($inputs as $name => $type) {
        $oKey = key($outputs);
        $outputs[$oKey] = $type;
        $outputMap[$oKey] = $name;
        next($outputs);
    }
    grokit_assert($nExt <= \count($inputs), 'There can not be more extreme values than there are inputs!');
    $mainAtts = [];
    $extraAtts = [];
    $minOpts = ['MIN', 'MINIMUM', '-', '<'];
    $maxOpts = ['MAX', 'MAXIMUM', '+', '>'];
    $inArrayCase = function ($needle, $haystack) {
        foreach ($haystack as $item) {
            if (strcasecmp($needle, $item) == 0) {
                return true;
            }
        }
        return false;
    };
    $minimum = [];
    foreach ($extremes as $name => $val) {
        grokit_assert(array_key_exists($name, $inputs), "ExtremeTuples: Expression with name " . $name . " specified as extreme not found in inputs");
    }
    foreach ($inputs as $name => $type) {
        if (array_key_exists($name, $extremes)) {
            $mainAtts[$name] = $type;
            if ($inArrayCase($extremes[$name], $minOpts)) {
                $minimum[$name] = true;
            } else {
                if ($inArrayCase($extremes[$name], $maxOpts)) {
                    $minimum[$name] = false;
                } else {
                    grokit_error('Unknown extreme type ' . $extremes[$name] . ' specified for ' . $name);
                }
            }
        } else {
            $extraAtts[$name] = $type;
        }
    }
    $debug = get_default($t_args, 'debug', 0);
    $className = generate_name('ExtremeTuples');
    ?>

class <?php 
    echo $className;
    ?>
 {

    struct Tuple {
<?php 
    foreach ($inputs as $name => $type) {
        ?>
        <?php 
        echo $type;
        ?>
 <?php 
        echo $name;
        ?>
;
<?php 
    }
    // foreach input
    ?>

        // Default Constructor, Copy Constructor, and Copy Assignment are all
        // default
        Tuple(void) = default;
        Tuple(const Tuple &) = default;
        Tuple & operator = (const Tuple &) = default;

        Tuple(<?php 
    echo array_template('const {val} & _{key}', ', ', $inputs);
    ?>
) :
            <?php 
    echo array_template('{key}(_{key})', ', ', $inputs);
    ?>

        { }

        // operator > means that this tuple is "better" than the other tuple.
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:ExtremeTuples.h.php


示例8: IsNull

<?php 
    $functions[] = ['IsNull', ['@type'], 'BASE::BOOL', true, true];
    ?>
inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContent .= ob_get_clean();
    ?>
//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath'), "complex" => false, "global_content" => $gContent, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 8]);
}
//end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'FLOAT', 'INT'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::DOUBLE');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'DOUBLE', [$fullType], $call);
}
开发者ID:gokulp,项目名称:grokit,代码行数:30,代码来源:DOUBLE.h.php


示例9: HyperLogLog

/**
 *  A GLA that estimates the cardinality of a dataset using the HyperLogLog
 *  algorithm, with a configurable number of bins.
 */
function HyperLogLog(array $t_args, array $input, array $output)
{
    $debug = get_default($t_args, 'debug', 0);
    grokit_assert(\count($output) == 1, 'HyperLogLog produces only 1 value, ' . \count($output) . ' outputs given.');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'BloomFilter output must be numeric!');
    $exp = get_first_key_default($t_args, ['bins.exponent'], 4);
    grokit_assert(is_integer($exp), 'HyperLogLog bins.exponent must be an integer');
    // Set limit of 2^24 bins, because states past 16MB start to get silly
    grokit_assert($exp >= 4 && $exp < 24, 'HyperLogLog bins.exponent must be in range [4, 24]');
    $useBuiltinCtz = get_default($t_args, 'use.builtin.ctz', true);
    $ctzFunc = $useBuiltinCtz ? '__builtin_ctzl' : 'ctz';
    $bins = pow(2, $exp);
    // Determine the value of alpha based on $exp
    switch ($exp) {
        case 4:
            $alpha = 0.673;
            break;
        case 5:
            $alpha = 0.697;
            break;
        case 6:
            $alpha = 0.709;
            break;
        default:
            $alpha = 0.7213000000000001 / (1 + 1.079 / $bins);
    }
    $className = generate_name('HyperLogLog');
    ?>

class <?php 
    echo $className;
    ?>
 {
    // Number of bins for registers
    static constexpr const size_t NUM_BINS = <?php 
    echo $bins;
    ?>
;
    // Number of bits used to index into registers, log2(NUM_BINS)
    static constexpr const size_t INDEX_BITS = <?php 
    echo $exp;
    ?>
;
    // Mask used to obtain register index from hash value
    static constexpr const size_t INDEX_MASK = NUM_BINS - 1;

    // Alpha coefficient used to correct cardinality estimate. Based on NUM_BINS.
    static constexpr const long double ALPHA = <?php 
    echo $alpha;
    ?>
;

    // Value of cardinality estimate after which we must apply the
    // large range correction
    static constexpr const long double LARGE_BREAKPOINT = (1.0 / 30.0) * <?php 
    echo pow(2, 32);
    ?>
;

    // Constants for population count
    static constexpr const uint64_t m1  = 0x5555555555555555;
    static constexpr const uint64_t m2  = 0x3333333333333333;
    static constexpr const uint64_t m4  = 0x0f0f0f0f0f0f0f0f;
    static constexpr const uint64_t h01 = 0x0101010101010101;

    // The registers
    std::array<unsigned char, NUM_BINS> registers;

    // A count used to remember how many tuples were processed, mostly for debugging.
    size_t count;

public:

    <?php 
    echo $className;
    ?>
(void) : registers() {
        for( auto & elem : registers ) {
            elem = 0;
        }
    }

    ~<?php 
    echo $className;
    ?>
() { }

    int popcount(uint64_t x) {
        // Put count of each 2 bits into those 2 bits
        x -= (x >> 1) & m1;
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:HyperLogLog.h.php


示例10: IsNull

inline
bool IsNull( @type f ) {
    return isnan(f);
}

<?php 
    $gContents = ob_get_clean();
    ?>

//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'cmath', 'limits'), "complex" => false, 'binary_operators' => ['+', '-', '*', '/', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['real', 'numeric', '_primative_'], 'global_content' => $gContents, 'describe_json' => DescribeJson('float'), 'extras' => ['size.bytes' => 4]);
}
// end of function
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'BIGINT', 'INT', 'FLOAT', 'DOUBLE'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::FLOAT');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'FLOAT', [$fullType], $call);
}
?>

开发者ID:gokulp,项目名称:grokit,代码行数:29,代码来源:FLOAT.h.php


示例11: AlphaOperator

 public static function AlphaOperator($op, $nArgs, DataType $alpha)
 {
     $aVal = $alpha->value();
     switch ($nArgs) {
         case 1:
             grokit_assert(array_key_exists($op, self::$unaryOperators), 'Attempted to generate invalid unary operator ' . $op . ' with alpha type ' . $alpha);
             $form = self::$unaryOperators[$op];
             switch ($form) {
                 case 'ata':
                     $args = [$alpha->value()];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha], 'result' => $alpha);
                     };
                     break;
             }
             break;
         case 2:
             // Binary operator
             grokit_assert(array_key_exists($op, self::$binaryOperators), 'Attempted to generate invalid binary operator ' . $op . ' with alpha type ' . $alpha);
             $form = self::$binaryOperators[$op];
             switch ($form) {
                 case 'aata':
                     $args = [$aVal, $aVal];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha, $alpha], 'result' => $alpha);
                     };
                     break;
                 case 'aatb':
                     $args = [$aVal, $aVal];
                     $call = function () use($alpha) {
                         return array('kind' => InfoKind::T_OP, 'input' => [$alpha, $alpha], 'result' => lookupType('base::bool'));
                     };
                     break;
             }
     }
     declareOperator($op, $args, $call);
 }
开发者ID:gokulp,项目名称:grokit,代码行数:37,代码来源:grokit_libman.php


示例12: generate_name

    $name = generate_name('Time');
    ?>

inline TIME <?php 
    echo $name;
    ?>
(const DATETIME& date_time) {
  return TIME(date_time.Hour(), date_time.Minute(), date_time.Second(), 0);
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true];
});
?>

<?php 
declareFunction('DATETIMEFROMINT', ['BASE::INT'], function ($args) {
    $result = lookupType('BASE::DATETIME');
    $name = generate_name('DateTimeFromInt');
    ?>

inline DATETIME <?php 
    echo $name;
    ?>
(const INT& seconds) {
  return DATETIME(seconds);
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true];
});
开发者ID:gokulp,项目名称:grokit,代码行数:31,代码来源:Date_Functions.php


示例13: page_rank_vd

function page_rank_vd($t_args, $inputs, $outputs)
{
    $className = generate_name('PageRank');
    $inputs_ = array_combine(['s', 't'], $inputs);
    $vertex = $inputs_['s'];
    $outputs_ = ['node' => $vertex, 'rank' => lookupType('double')];
    $outputs = array_combine(array_keys($outputs), $outputs_);
    $sys_headers = ['vector', 'algorithm'];
    $user_headers = [];
    $lib_headers = [];
    $libraries = [];
    $properties = [];
    $extra = [];
    $result_type = ['fragment'];
    ?>

using namespace std;

class <?php 
    echo $className;
    ?>
;

<?php 
    $constantState = lookupResource('pagerankVD::page_rank_vd_Constant_State', ['className' => $className]);
    ?>

class <?php 
    echo $className;
    ?>
 {
 public:
  using ConstantState = <?php 
    echo $constantState;
    ?>
;
  using Iterator = std::pair<int, int>;
  static const constexpr float kDamping = 0.85;
  static const constexpr int nIterations = 5;
  static const constexpr int kBlock = 32;
  static const constexpr int kMaxFragments = 64;

 private:

  static std::vector<double> weight;
  static std::vector<double> pagerank;
  static std::vector<double> oldPagerank;

  const ConstantState& constant_state;
  long nVertices;
  int iteration;
  int num_fragments;

 public:
  <?php 
    echo $className;
    ?>
(const <?php 
    echo $constantState;
    ?>
& state)
      : constant_state(state),
        nVertices(state.nVertices),
        iteration(state.iteration) {
  }

  void AddItem(<?php 
    echo const_typed_ref_args($inputs_);
    ?>
) {
    if (iteration == 0) {
      nVertices = max((long) max(s, t), nVertices);
      return;
    } else if (iteration == 1) {
      weight[s]++;
    } else {
      oldPagerank[t] += weight[s] * pagerank[s];
    }
  }

  void AddState(<?php 
    echo $className;
    ?>
 &other) {
    if (iteration == 0)
      nVertices = max(nVertices, other.nVertices);
  }

  // Most computation that happens at the end of each iteration is parallelized
  // by performed it inside Finalize.
  bool ShouldIterate(ConstantState& state) {
    state.iteration = ++iteration;
    cout << "Finished Iteration: " << iteration << endl;
    if (iteration == 1) {
      state.nVertices = ++nVertices;
      cout << "num_nodes: " << nVertices << endl;
      oldPagerank.reserve(nVertices);
      pagerank.reserve(nVertices);
      weight.reserve(nVertices);
      std::fill (pagerank.begin(),pagerank.end(),1);
//.........这里部分代码省略.........
开发者ID:vineethdasaraju,项目名称:LGDataProcessingPageRank,代码行数:101,代码来源:pagerankvd.php


示例14: CountDistinct

/**
 *  A GLA that counts the number of distinct elements by keeping track of the
 *  distinct elements.
 *
 *  Unless an exact count of the distinct is absolutely needed, consider using
 *  an approximation of the distinct, such as a Bloom Filter.
 */
function CountDistinct(array $t_args, array $input, array $output)
{
    grokit_assert(\count($output) == 1, 'CountDistinct should have only 1 output, ' . \count($output) . 'given');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'CountDistinct output must be numeric!');
    $useMCT = get_default($t_args, 'use.mct', true);
    $keepHashes = get_default($t_args, 'mct.keep.hashes', false);
    $initSize = get_default($t_args, 'init.size', 65536);
    $nullCheck = get_default($t_args, 'null.check', false);
    grokit_assert(is_bool($useMCT), 'CountDistinct use.mct argument must be boolean');
    grokit_assert(is_integer($initSize), 'Distinct init.size argument must be an integer');
    grokit_assert($initSize > 0, 'Distinct init.size argument must be positive');
    grokit_assert(is_bool($keepHashes), 'CountDistinct mct.keep.hashes argument must be boolean');
    $distTmpArgs = ['use.mct' => $useMCT, 'init.size' => $initSize, 'mct.keep.hashes' => $keepHashes, 'null.check' => $nullCheck];
    $gla = lookupGLA('BASE::DISTINCT', $distTmpArgs, $input, $input);
    $className = generate_name('CountDistinct');
    ?>
class <?php 
    echo $className;
    ?>
 {
    using Distinct = <?php 
    echo $gla->value();
    ?>
;

    Distinct distinctGLA;

public:

    <?php 
    echo $className;
    ?>
(void):
        distinctGLA()
    { }

    ~<?php 
    echo $className;
    ?>
(void) { }

    void AddItem(<?php 
    echo const_typed_ref_args($input);
    ?>
) {
        distinctGLA.AddItem(<?php 
    echo args($input);
    ?>
);
    }

    void AddState(<?php 
    echo $className;
    ?>
 & o) {
        distinctGLA.AddState(o.distinctGLA);
    }

    void GetResult(<?php 
    echo $outputType;
    ?>
 & <?php 
    echo $outputName;
    ?>
) {
        <?php 
    echo $outputName;
    ?>
 = distinctGLA.get_countDistinct();
    }
};
<?php 
    return ['kind' => 'GLA', 'name' => $className, 'input' => $input, 'output' => $output, 'result_type' => 'single'];
}
开发者ID:gokulp,项目名称:grokit,代码行数:87,代码来源:CountDistinct.h.php


示例15: declareFunctionGlobal

<?php

// Copyright 2015, Tera Insights, LLC. All Rights Reserved.
declareFunctionGlobal('BASE', 'BOOL', ['BASE::NULL'], function () {
    $boolType = lookupType('BASE::BOOL');
    $nullType = lookupType('BASE::NULL');
    return ['kind' => 'FUNCTION', 'name' => 'bool_Null', 'input' => [$nullType], 'result' => $boolType, 'deterministic' => true];
});
?>

inline int ToString(bool b, char * buffer) {
	if (b)
		return 1 + sprintf(buffer, "true");
	else
		return 1 + sprintf(buffer, "false");
}

inline void FromString(bool & b, const char* buffer) {
	char first = *buffer;
	char upper = *buffer & 0xDF;
	if (first == '1' || upper == 'T' || upper == 'Y')
		b = true;
	else
		b = false;
}

namespace BASE {
	inline
	bool bool_Null(const GrokitNull& null) {
		return false;
	}
开发者ID:gokulp,项目名称:grokit,代码行数:31,代码来源:BOOL.h.php


示例16: ClusterValue

inline
int64_t ClusterValue(const @type & x) {
    return x;
}

<?php 
    $gContent .= ob_get_clean();
    ?>

//////////////
// Operators

// all operators defined by C++

<?php 
    return array('kind' => 'TYPE', "system_headers" => array("cstdlib", "cstdio", "cinttypes", 'limits'), "complex" => false, "global_content" => $gContent, 'binary_operators' => ['+', '-', '*', '/', '%', '==', '!=', '>', '<', '>=', '<='], 'unary_operators' => ['+', '-'], 'constructors' => $constructors, 'functions' => $functions, 'properties' => ['integral', 'numeric', '_primative_', 'clusterable'], 'describe_json' => DescribeJson('integer'), 'extras' => ['size.bytes' => 4]);
}
declareOperator('//', ['base::UINT', 'base::UINT'], function ($args) {
    $l = lookupType('base::UINT');
    return ['kind' => 'OPERATOR', 'name' => '/', 'input' => [$l, $l], 'result' => $l, 'deterministic' => true];
});
// Define the constructors from the various other types.
foreach (['BYTE', 'SMALLINT', 'INT', 'UINT', 'BIGINT', 'FLOAT', 'DOUBLE'] as $type) {
    $fullType = 'base::' . $type;
    $call = function ($args, $targs = []) use($fullType) {
        $arg = lookupType($fullType);
        $ret = lookupType('base::UINT');
        return array('kind' => 'FUNCTION', 'input' => [$arg], 'result' => $ret, 'deterministic' => true);
    };
    declareFunctionGlobal('base', 'UINT', [$fullType], $call);
}
开发者ID:gokulp,项目名称:grokit,代码行数:31,代码来源:UINT.h.php


示例17: parseNull

function parseNull($ast)
{
    assert_ast_type($ast, Nodetype::NUL);
    $nType = lookupType('BASE::NULL');
    $nVal = 'GrokitNull::Value';
    $source = ast_node_source($ast);
    $info = new ExpressionInfo($source, $nType, $nVal, true);
    return $info;
}
开发者ID:gokulp,项目名称:grokit,代码行数:9,代码来源:grokit_codegen_expr.php


示例18: apply

 public function apply($obj, array $exprs, $source)
 {
     $this->checkFuzzy($this->args, $exprs, 'parameter');
     $exprVals = array_map(function ($val) {
         return $val->value();
     }, $exprs);
     $value = $obj->value() . '.' . $this->name . '(' . implode(', ', $exprVals) . ')';
     $is_const = $this->deterministic && $obj->is_const();
     foreach ($exprs as $expr) {
         $is_const = $is_const && $expr->is_const();
     }
     $retType = lookupType($this->resultType);
     $info = new ExpressionInfo($source, $retType, $value, $is_const);
     $info->absorbMeta($obj);
     foreach ($exprs as $expr) {
         $info->absorbMeta($expr);
     }
     return $info;
 }
开发者ID:gokulp,项目名称:grokit,代码行数:19,代码来源:grokit_func_info.php


示例19: CCompLP

function CCompLP($t_args, $inputs, $outputs)
{
    // Class name is randomly generated.
    $className = generate_name('CComp');
    // Initializiation of argument names.
    $inputs_ = array_combine(['s', 't'], $inputs);
    $vertex = $inputs_['s'];
    // Construction of outputs.
    $outputs_ = ['node' => $vertex, 'component' => lookupType('int')];
    $outputs = array_combine(array_keys($outputs), $outputs_);
    $sys_headers = ['armadillo', 'algorithm'];
    $user_headers = [];
    $lib_headers = [];
    $libraries = ['armadillo'];
    $properties = [];
    $extra = [];
    $result_type = ['multi'];
    ?>

using namespace arma;
using namespace std;

class <?php 
    echo $className;
    ?>
;

<?php 
    $constantState = lookupResource('graph::CCompLP_Constant_State', ['className' => $className]);
    ?>

class <?php 
    echo $className;
    ?>
 {
 public:
  // The constant state for this GLA.
  using ConstantState = <?php 
    echo $constantState;
    ?>
;

  // The number of iterations to perform, not counting the initial set-up.
  static const constexpr int kIterations = 30;

  // The work is split into chunks of this size before being partitioned.
  static const constexpr int kBlock = 32;

  // The maximum number of fragments to use.
  static const constexpr int kMaxFragments = 64;

 private:
  
  // Node Component
  static arma::rowvec node_component;

  // The typical constant state for an iterable GLA.
  const ConstantState& constant_state;

  // The number of unique nodes seen.
  long num_nodes;

  // 
  long output_iterator;

  // The current iteration.
  int iteration;
  
  // check if need more iterations
  long connections;

 public:
  <?php 
    echo $className;
    ?>
(const <?php 
    echo $constantState;
    ?>
& state)
      : constant_state(state),
        num_nodes(state.num_nodes),
        iteration(state.iteration),output_iterator(0),connections(0) {
  }

  // Basic dynamic array allocation.
  void AddItem(<?php 
    echo const_typed_ref_args($inputs_);
    ?>
) {
    if (iteration == 0) {
      num_nodes = max((long) max(s, t), num_nodes);
      return;
    } /*else if (iteration == 1){
      long max_known = (long) max(s, t);
      node_component(s) = max_known;
      node_component(t) = max_known;
      ++ connections;
    }*/else{
      long s_id = node_component(s), t_id = node_component(t);
      if (s_id != t_id){
//.........这里部分代码省略.........
开发者ID:csur,项目名称:gtGraph,代码行数:101,代码来源:CCompLP.php


示例20: CATEGORY

function CATEGORY(array $t_args)
{
    if (array_key_exists('dict', $t_args)) {
        $values = $t_args['dict'];
        $maxID = 0;
        foreach ($values as $id => $val) {
            $maxID = \max($id, $maxID);
        }
    } else {
        $old_vals = get_first_key($t_args, ['values', 0]);
        $startAt = get_first_key_default($t_args, ['start.at'], 0);
        $values = [];
        $maxID = $startAt;
        foreach ($old_vals as $ind => $val) {
            $values[$maxID++] = $val;
        }
    }
    $cardinality = \count($values);
    // Add 1 to the cardinality for the invalid id
    $storageTypeBits = ceil(log($maxID + 1, 2));
    if ($storageTypeBits > 64) {
        // This should never happen. PHP would explode processing 2^64 values.
        grokit_error("Unable to store {$cardinality} values within 64 bits.");
    } else {
        if ($storageTypeBits > 32) {
            $storageType = 'uint64_t';
            $storageBytes = 8;
        } else {
            if ($storageTypeBits > 16) {
                $storageType = 'uint32_t';
                $storageBytes = 4;
            } else {
                if ($storageTypeBits > 8) {
                    $storageType = 'uint16_t';
                    $storageBytes = 2;
                } else {
                    $storageType = 'uint8_t';
                    $storageBytes = 1;
                }
            }
        }
    }
    $className = generate_name('CATEGORY');
    $stringType = lookupType('base::STRING');
    $methods = [];
    $constructors = [];
    $functions = [];
    ?>

class <?php 
    echo $className;
    ?>
 {
public:
    typedef <?php 
    echo $storageType;
    ?>
 StorageType;
    typedef std::unordered_map<StorageType, std::string> IDToNameMap;
    typedef std::unordered_map<std::string, StorageType> NameToIDMap;

    static const StorageType InvalidID __attribute__((weak));

private:
    static const IDToNameMap idToName __attribute__((weak));
    static const NameToIDMap nameToID __attribute__((weak));

    // The ID of this categorical variable
    StorageType myID;

public:

    /* ----- Constructors / Destructor ----- */
    <?php 
    echo $className;
    ?>
( void );

<?php 
    $constructors[] = [['base::STRING_LITERAL'], true];
    ?>
    <?php 
    echo $className;
    ?>
( const char * );
<?php 
    $constructors[] = [['base::STRING'], true];
    ?>
    <?php 
    echo $className;
    ?>
( const <?php 
    echo $stringType;
    ?>
 & );
    <?php 
    echo $className;
    ?>
( const <?php 
    echo $storageType;
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:CATEGORY.h.php



注:本文中的lookupType函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP lookup_ca函数代码示例发布时间:2022-05-15
下一篇:
PHP lookup函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap