[Python] (scalar) vector reading speedup via numpy (#4390)

* Add numpy accessor to python flatbuffers scalar vectors

* Update python tests to test numpy vector accessor

* Update appveyor CI to run Python tests, save generated code as artifact

* Update example generated python code

* Add numpy info to python usage docs

* Update test schema and python tests w/ multi-byte vector

* did not mean to push profiling code

* adding float64 numpy tests
This commit is contained in:
Kevin Rose
2017-08-01 10:34:00 -05:00
committed by Wouter van Oortmerssen
parent 89a68942ac
commit 3282a84e30
21 changed files with 666 additions and 32 deletions

View File

@@ -444,22 +444,60 @@ class Monster extends Table
return $o != 0 ? $this->__vector_len($o) : 0;
}
/**
* @param int offset
* @return long
*/
public function getVectorOfLongs($j)
{
$o = $this->__offset(68);
return $o != 0 ? $this->bb->getLong($this->__vector($o) + $j * 8) : 0;
}
/**
* @return int
*/
public function getVectorOfLongsLength()
{
$o = $this->__offset(68);
return $o != 0 ? $this->__vector_len($o) : 0;
}
/**
* @param int offset
* @return double
*/
public function getVectorOfDoubles($j)
{
$o = $this->__offset(70);
return $o != 0 ? $this->bb->getDouble($this->__vector($o) + $j * 8) : 0;
}
/**
* @return int
*/
public function getVectorOfDoublesLength()
{
$o = $this->__offset(70);
return $o != 0 ? $this->__vector_len($o) : 0;
}
/**
* @param FlatBufferBuilder $builder
* @return void
*/
public static function startMonster(FlatBufferBuilder $builder)
{
$builder->StartObject(32);
$builder->StartObject(34);
}
/**
* @param FlatBufferBuilder $builder
* @return Monster
*/
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5)
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5, $vector_of_longs, $vector_of_doubles)
{
$builder->startObject(32);
$builder->startObject(34);
self::addPos($builder, $pos);
self::addMana($builder, $mana);
self::addHp($builder, $hp);
@@ -491,6 +529,8 @@ class Monster extends Table
self::addTestarrayofsortedstruct($builder, $testarrayofsortedstruct);
self::addFlex($builder, $flex);
self::addTest5($builder, $test5);
self::addVectorOfLongs($builder, $vector_of_longs);
self::addVectorOfDoubles($builder, $vector_of_doubles);
$o = $builder->endObject();
$builder->required($o, 10); // name
return $o;
@@ -1041,6 +1081,74 @@ class Monster extends Table
$builder->startVector(4, $numElems, 2);
}
/**
* @param FlatBufferBuilder $builder
* @param VectorOffset
* @return void
*/
public static function addVectorOfLongs(FlatBufferBuilder $builder, $vectorOfLongs)
{
$builder->addOffsetX(32, $vectorOfLongs, 0);
}
/**
* @param FlatBufferBuilder $builder
* @param array offset array
* @return int vector offset
*/
public static function createVectorOfLongsVector(FlatBufferBuilder $builder, array $data)
{
$builder->startVector(8, count($data), 8);
for ($i = count($data) - 1; $i >= 0; $i--) {
$builder->addLong($data[$i]);
}
return $builder->endVector();
}
/**
* @param FlatBufferBuilder $builder
* @param int $numElems
* @return void
*/
public static function startVectorOfLongsVector(FlatBufferBuilder $builder, $numElems)
{
$builder->startVector(8, $numElems, 8);
}
/**
* @param FlatBufferBuilder $builder
* @param VectorOffset
* @return void
*/
public static function addVectorOfDoubles(FlatBufferBuilder $builder, $vectorOfDoubles)
{
$builder->addOffsetX(33, $vectorOfDoubles, 0);
}
/**
* @param FlatBufferBuilder $builder
* @param array offset array
* @return int vector offset
*/
public static function createVectorOfDoublesVector(FlatBufferBuilder $builder, array $data)
{
$builder->startVector(8, count($data), 8);
for ($i = count($data) - 1; $i >= 0; $i--) {
$builder->addDouble($data[$i]);
}
return $builder->endVector();
}
/**
* @param FlatBufferBuilder $builder
* @param int $numElems
* @return void
*/
public static function startVectorOfDoublesVector(FlatBufferBuilder $builder, $numElems)
{
$builder->startVector(8, $numElems, 8);
}
/**
* @param FlatBufferBuilder $builder
* @return int table offset