mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add boilerplate for line_profiler
This commit is contained in:
parent
38696efdfb
commit
209b7f6831
@ -9,7 +9,7 @@ pipeline = [
|
|||||||
["config.h", "export.h", "common.h", "memory.h", "vector.h", "str.h", "tuplelist.h", "namedict.h", "error.h"],
|
["config.h", "export.h", "common.h", "memory.h", "vector.h", "str.h", "tuplelist.h", "namedict.h", "error.h"],
|
||||||
["obj.h", "dict.h", "codeobject.h", "frame.h"],
|
["obj.h", "dict.h", "codeobject.h", "frame.h"],
|
||||||
["gc.h", "vm.h", "ceval.h", "lexer.h", "expr.h", "compiler.h", "repl.h"],
|
["gc.h", "vm.h", "ceval.h", "lexer.h", "expr.h", "compiler.h", "repl.h"],
|
||||||
["_generated.h", "cffi.h", "bindings.h", "iter.h", "base64.h", "csv.h", "collections.h", "array2d.h", "dataclasses.h", "random.h", "linalg.h", "easing.h", "io.h", "modules.h"],
|
["_generated.h", "cffi.h", "bindings.h", "iter.h", "base64.h", "csv.h", "collections.h", "line_profiler.h", "array2d.h", "dataclasses.h", "random.h", "linalg.h", "easing.h", "io.h", "modules.h"],
|
||||||
["pocketpy.h", "pocketpy_c.h"]
|
["pocketpy.h", "pocketpy_c.h"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
9
include/pocketpy/line_profiler.h
Normal file
9
include/pocketpy/line_profiler.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "bindings.h"
|
||||||
|
|
||||||
|
namespace pkpy {
|
||||||
|
|
||||||
|
void add_module_line_profiler(VM* vm);
|
||||||
|
|
||||||
|
} // namespace pkpy
|
@ -16,4 +16,5 @@
|
|||||||
#include "csv.h"
|
#include "csv.h"
|
||||||
#include "dataclasses.h"
|
#include "dataclasses.h"
|
||||||
#include "array2d.h"
|
#include "array2d.h"
|
||||||
|
#include "line_profiler.h"
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
|
10
include/typings/line_profiler.pyi
Normal file
10
include/typings/line_profiler.pyi
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
class LineProfiler:
|
||||||
|
def __init__(self): ...
|
||||||
|
|
||||||
|
def add_function(self, func: Callable) -> None: ...
|
||||||
|
|
||||||
|
def runcall(self, func: Callable, *args, **kw) -> None: ...
|
||||||
|
|
||||||
|
def print_stats(self) -> None: ...
|
@ -168,8 +168,11 @@ struct Array2d{
|
|||||||
vm->bind(type, "copy_(self, other)", [](VM* vm, ArgsView args){
|
vm->bind(type, "copy_(self, other)", [](VM* vm, ArgsView args){
|
||||||
Array2d& self = PK_OBJ_GET(Array2d, args[0]);
|
Array2d& self = PK_OBJ_GET(Array2d, args[0]);
|
||||||
Array2d& other = CAST(Array2d&, args[1]);
|
Array2d& other = CAST(Array2d&, args[1]);
|
||||||
delete self.data;
|
// if self and other have different sizes, re-initialize self
|
||||||
self.init(other.n_cols, other.n_rows);
|
if(self.n_cols != other.n_cols || self.n_rows != other.n_rows){
|
||||||
|
delete self.data;
|
||||||
|
self.init(other.n_cols, other.n_rows);
|
||||||
|
}
|
||||||
for(int i = 0; i < self.numel; i++){
|
for(int i = 0; i < self.numel; i++){
|
||||||
self.data[i] = other.data[i];
|
self.data[i] = other.data[i];
|
||||||
}
|
}
|
||||||
|
35
src/line_profiler.cpp
Normal file
35
src/line_profiler.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "pocketpy/line_profiler.h"
|
||||||
|
|
||||||
|
namespace pkpy{
|
||||||
|
|
||||||
|
struct LineProfiler{
|
||||||
|
PY_CLASS(LineProfiler, line_profiler, LineProfiler)
|
||||||
|
|
||||||
|
std::set<void*> _functions;
|
||||||
|
|
||||||
|
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||||
|
vm->bind_default_constructor<LineProfiler>(type);
|
||||||
|
|
||||||
|
vm->bind(type, "add_function(self, func)", [](VM* vm, ArgsView args){
|
||||||
|
// ...
|
||||||
|
return vm->None;
|
||||||
|
});
|
||||||
|
|
||||||
|
vm->bind(type, "runcall(self, func, *args, **kw)", [](VM* vm, ArgsView args){
|
||||||
|
// ...
|
||||||
|
return vm->None;
|
||||||
|
});
|
||||||
|
|
||||||
|
vm->bind(type, "print_stats(self)", [](VM* vm, ArgsView args){
|
||||||
|
// ...
|
||||||
|
return vm->None;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void add_module_line_profiler(VM *vm){
|
||||||
|
PyObject* mod = vm->new_module("line_profiler");
|
||||||
|
LineProfiler::register_class(vm, mod);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pkpy
|
@ -1529,6 +1529,7 @@ void VM::post_init(){
|
|||||||
add_module_easing(this);
|
add_module_easing(this);
|
||||||
add_module_collections(this);
|
add_module_collections(this);
|
||||||
add_module_array2d(this);
|
add_module_array2d(this);
|
||||||
|
add_module_line_profiler(this);
|
||||||
|
|
||||||
#ifdef PK_USE_CJSON
|
#ifdef PK_USE_CJSON
|
||||||
add_module_cjson(this);
|
add_module_cjson(this);
|
||||||
|
@ -89,6 +89,9 @@ assert d == array2d(2, 4, default=0)
|
|||||||
# test copy_
|
# test copy_
|
||||||
a.copy_(d)
|
a.copy_(d)
|
||||||
assert a == d and a is not d
|
assert a == d and a is not d
|
||||||
|
x = array2d(4, 4, default=0)
|
||||||
|
x.copy_(d)
|
||||||
|
assert x == d and x is not d
|
||||||
|
|
||||||
# test subclass array2d
|
# test subclass array2d
|
||||||
class A(array2d):
|
class A(array2d):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user