-
Notifications
You must be signed in to change notification settings - Fork 166
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
WIP: Addition of a subroutine get_other_scalar in stdlib_hashmap_wrappers #664
Conversation
I am on vacation with many things going on so it will take some time to review this. FWIW |
I have been using |
Strange, it passed the test of the CI on MacOS with |
|
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.
I don't think this is the right way to go. Better have a subroutine for every type you want to retrieve.
doc/specs/stdlib_hashmaps.md
Outdated
`call [[stdlib_hashmap_wrappers:get_other_scalar]]( other[, value_char, | ||
value_int8, value_int16, value_int32, value_int64, value_sp, value_dp, value_csp, value_cdp, value_lk, | ||
exists] )` |
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.
I very much dislike this API. In which case do you need to retrieve both a value_sp
and value_lk
together? The user would have to implement the same dispatch logic again which is already used in the wrapper.
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.
Reading it again now, I totally agree with you. I will change the code with multiple subroutines.
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.
For TOML Fortran I'm using the following get_value
API: https://github.com/toml-f/toml-f/blob/main/src/tomlf/build/table.f90 (toml_key
is similar to stdlib's string_type
)
@awvwgk I modified the API by generating specific procedures for each type. I think this is more in-line with what you propose. |
src/stdlib_hashmap_wrappers.fypp
Outdated
get_int8_key | ||
|
||
end interface get | ||
|
||
interface get_other_scalar |
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.
Should this go together with the get
interface? get_other_scalar
is a somewhat unpractical name for any application.
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.
It could be done, indeed.
I separated from get
because the API of get
is get(input, value)
(i.e., 2 args, instead of 3 for get_other_scalar), and though that it could generate confusion in the specs.
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.
With this commit I moved it inside the get
interface. Hopefully the specs are clear enough.
Seems to fail with Intel due to an ambiguous interface
|
Yes, I was afraid for this issue, and I was a bit surprised that |
I think the In TOML Fortran the |
Making this argument not
I totally agree with you. But
I need to think a bit more on this approach. I don't understand directly how this approach will solve this issue. |
I use a zero copy approach for the data structure, you can either obtain a pointer to the object in the data structure ( This map implementation is designed differently, specially I agree that a specialized API is needed because an unlimited polymorphic value is inconvenient to work with, but I can't see a good way to fit it in the current structure. |
Thank you @awvwgk for yoour explanations. Really useful.
Could the use of
I agree with you. My main aim was to provide a simple API for most scalar types to users of stdlib. The user can still write his own code for other specific types. Maybe a small example in the docs with such a code using subroutine get_other_scalar_int32(other, value, exists)
!! Version: Experimental
!!
!! Gets the content of the other as a scalar of a kind provided by stdlib_kinds
class(other_type), intent(in) :: other
integer(int32), intent(out) :: value
logical, intent(out), optional :: exists
logical :: exists_
exists_ = .false.
if (.not.allocated(other % value)) then
if (present(exists)) exists = exists_
return
end if
select type(d => other % value)
type is ( integer(int32) )
value = d
exists_ = .true.
end select
if (present(exists)) exists = exists_
end subroutine This topic would be also a good candidate for a tutorial.
Let wait and see the experience of other users. |
Addition of the subroutine
get_other_scalar( other, value [, exists])
to extract the content ofother_type
into the scalar variablevalue
of a kind provided by the modulestdlib_kinds
.The aim of this subroutine is to help the user to get the content of
other_type
when it is only a scalar value.