-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reserve
for list
#2238
Add reserve
for list
#2238
Conversation
l2: list[list[tuple[f64, str, tuple[i32, f64]]]] = [] | ||
i: i32 | ||
|
||
l1.reserve(100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l1.reserve(100) | |
reserve(l1, 100) |
l1.append(i) | ||
assert len(l1) == i + 1 | ||
|
||
l1.reserve(150) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l1.reserve(150) | |
reserve(l1, 150) |
l1.pop(0) | ||
assert len(l1) == 49 - i | ||
|
||
l2.reserve(100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l2.reserve(100) | |
reserve(l2, 100) |
l2.append([(f64(i * i), str(i), (i, f64(i + 1))), (f64(i), str(i), (i, f64(i)))]) | ||
assert len(l2) == i + 1 | ||
|
||
l2.reserve(150) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l2.reserve(150) | |
reserve(l2, 150) |
@@ -0,0 +1,30 @@ | |||
from lpython import i32, f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from lpython import i32, f64 | |
from lpython import i32, f64, reserve |
return nullptr; | ||
} | ||
|
||
static inline ASR::asr_t* create_ListReserve(Allocator& al, const Location& loc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static inline ASR::asr_t* create_ListReserve(Allocator& al, const Location& loc, | |
static inline ASR::asr_t* create_Reserve(Allocator& al, const Location& loc, |
x.base.base.loc, diagnostics); | ||
} | ||
|
||
static inline ASR::expr_t *eval_list_reserve(Allocator &/*al*/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static inline ASR::expr_t *eval_list_reserve(Allocator &/*al*/, | |
static inline ASR::expr_t *eval_reserve(Allocator &/*al*/, |
@@ -3124,6 +3172,8 @@ namespace IntrinsicFunctionRegistry { | |||
{nullptr, &DictValues::verify_args}}, | |||
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListPop), | |||
{nullptr, &ListPop::verify_args}}, | |||
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListReserve), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListReserve), | |
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::Reserve), |
@@ -3206,6 +3256,8 @@ namespace IntrinsicFunctionRegistry { | |||
"list.reverse"}, | |||
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListPop), | |||
"list.pop"}, | |||
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListReserve), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::ListReserve), | |
{static_cast<int64_t>(ASRUtils::IntrinsicFunctions::Reserve), |
@@ -3290,6 +3342,7 @@ namespace IntrinsicFunctionRegistry { | |||
{"list.index", {&ListIndex::create_ListIndex, &ListIndex::eval_list_index}}, | |||
{"list.reverse", {&ListReverse::create_ListReverse, &ListReverse::eval_list_reverse}}, | |||
{"list.pop", {&ListPop::create_ListPop, &ListPop::eval_list_pop}}, | |||
{"list.reserve", {&ListReserve::create_ListReserve, &ListReserve::eval_list_reserve}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{"list.reserve", {&ListReserve::create_ListReserve, &ListReserve::eval_list_reserve}}, | |
{"list.reserve", {&ListReserve::create_Reserve, &ListReserve::eval_reserve}}, |
Beautiful. Yes, as Gagandeep said, you just do:
Let's get this in and benchmark again. |
The latest commit makes these changes. But the test gives this error
@czgdp1807 Could you please point where exactly is this to be registered in |
@czgdp1807 if you could please help, that would be great. Let's get this finished. |
I will meet @kabra1110 today after our meeting ends. We will complete it then. |
Thanks @czgdp1807 ! How do the updated benchmarks look like? |
Fixes #2232.
Similar to C++, I have kept this as a function intrinsic to list class.
The test does not work with CPython, as this function is not present there. I'm not entirely sure on how to add a no-op function for this to work.