Present:
Note: a table of contents can be found in the lower left corner
Based on Matti's suggestion, if something is confusing maybe use these?:
class mytype(dtype):
pass
class dtype(object):
def __promote__(self, other):
"""Used by np.promote_types, identical to result_type
but without scalar logic.
"""
if isinstance(other, self):
# make sure to give priority to subclasses:
self, other = other, self
if self.__can_cast__(other):
return other
if other.__can_cast__(self):
return self
raise TypeError("cannot promote to common type.")
class unit(dtype):
itemsize = 8
type = pyunit
def __new__(self):
# what is specfically needed here?
pass
def __item_unpack__(self, val):
"""How to do this as low level loops?"""
return self.type.from_bytes(val)
def __item_pack__(self, obj):
if not isinstance(obj, self.type):
raise ValueError
return obj.to_bytes()
@classmethod # not sure?
def __promote__(cls, dt1, dt2):
"""By default, checks can_cast(self, other)"""
return np.result_type(self, other)
@classmethod
def __can_cast__(cls, dt1, dt2, casting="safe"):
return True or False # or unit["m"], loop?
@classmethod
def __get_loop__(self, ufunc, in_types, out_types):
"""
Alternatively, register loops and:
* check exact loops → promote → check loops again
* (loop could still refuse)
"""
if not_possible:
return NotImplemented
return UfuncLoop
class UfuncLoop:
# probably largely C-slots, but could fill from python
inner_loop
setup_loop = None # i.e. FloatClearErr
teardown_loop = None # i.e. FloatCheckErr
needs_api # Flag (or allow setup to set/override?)
identity = NotImplemented
# more flags to add
# Other or even extendable things?:
masked_inner_loop = None # already auto-wrapped if not there
specialized_inner_loops = None # contiguous (copy code), AVX?
…
…
…
…
__can_cast__
?…
Common type normally found with safe casting semantics (if a
can safe cast to b
, then promote(a, b) is a
).
np.floating
may be tricky?np.array
…
Need:
Should thi
…
ufunc->functions
to find its own andufunc->data
for that function.ntypes
functions
data
ptr
(used also by from_pyfunc
, is freed on dealloc
)
ptr == |<- functions ->|<- data ->|<- types ->|
Room for random notes/thoughts so they do not get lost?
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing