Skip to content
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

added cupy.format_float_positional #6308

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cupy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def result_type(*arrays_and_dtypes):
from cupy._io.formatting import array_repr # NOQA
from cupy._io.formatting import array_str # NOQA
from cupy._io.formatting import array2string # NOQA
from cupy._io.formatting import format_float_positional # NOQA

from cupy._io.text import savetxt # NOQA

Expand Down
9 changes: 9 additions & 0 deletions cupy/_io/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ def array2string(a, *args, **kwargs):

"""
return numpy.array2string(cupy.asnumpy(a), *args, **kwargs)


def format_float_positional(a, *args, **kwargs):
"""Returns the decimal string in positional notation

amanchhaparia marked this conversation as resolved.
Show resolved Hide resolved
.. seealso:: :func:`numpy.format_float_positional`

"""
return numpy.format_float_positional(cupy.asnumpy(a), *args, **kwargs)
amanchhaparia marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docs/source/reference/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ String formatting
.. autosummary::
:toctree: generated/

format_float_positional
amanchhaparia marked this conversation as resolved.
Show resolved Hide resolved
array2string
array_repr
array_str
Expand Down
6 changes: 6 additions & 0 deletions tests/cupy_tests/io_tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ def test_array2string(self):
a = testing.shaped_arange((2, 3, 4), cupy)
b = testing.shaped_arange((2, 3, 4), numpy)
return cupy.array2string(a) == numpy.array2string(b)

amanchhaparia marked this conversation as resolved.
Show resolved Hide resolved
def test_format_float_positional(self):
a = testing.shaped_arange((1,), cupy)
b = testing.shaped_arange((1,), numpy)
assert cupy.format_float_positional(
a) == numpy.format_float_positional(b)