Code Monkey home page Code Monkey logo

pyinterval's Introduction

PyInterval — Interval Arithmetic in Python

This library provides a Python implementation of an algebraically closed interval system on the extended real number set. Interval objects, as defined in this library, consist of a finite union of closed, possibly unbound intervals in the mathematical sense.

Links

pyinterval's People

Contributors

captainpatate avatar taschini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyinterval's Issues

abs() missing

Calling abs() on an interval currently does not result in the interval's absolute value:

>>> abs(interval.interval[-1,1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for abs(): 'interval'

However, this is easy to implement! This is a function I used:

def interval_abs(i):
    """
    Get absolute value of interval i.
    """
    return (i | (-i)) & interval.interval[0, inf]

contains() not working for components?

I need to write a method that tells me if a set of intervals is contained in another. When trying on a single interval like such:

import interval as itv
tst = itv.interval([0,1],[-7,-1],[2,3])
def contains(itvset_a, itvset_b):
    for x,y in zip(itvset_a,itvset_b):
        if not x.__contains__(y):
            return False
    return True 
print(contains(tst,tst))

it returns False. However, it correctly zips up the components of the interval, meaning that for a component a.__contains__(a) is evaluated to False. Why is that?
Note that changing the call to print(contains([tst5],[tst5])) works perfectly fine.

Port to Python 3

I tried to install this library in Python 3 and I got this error.

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-j9ciam2g/pyinterval/setup.py", line 58, in <module>
        @apply
    NameError: name 'apply' is not defined

Then I checked the package info. in PyPI and I saw that this is available only for Python 3. Would it be too much trouble to port the library to Python 3? I could help you to do it...

Cheers.

open vs closed intervals

Hi!

Is there a way to specify if the interval is inclusive or exclusive of its endpoints? [] vs () ?

Division of positive intervals

What steps will reproduce the problem?
1. z = interval[0,1] / interval[0,1]
2. print z

What is the expected output? What do you see instead?

The expected output is z == interval[0, inf], whereas it is computed 
interval[-inf, inf]

What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 29 Jan 2012 at 3:49

copy interval error

I need to copy/deepcopy a interval with the module copy, but it's always error:

k = interval([-3, -2], [0, 1])
A=copy.copy(k)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 96, in copy
return _reconstruct(x, rv, 0)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
y = callable(*args)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 93, in newobj
return cls.new(cls, *args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 101, in new
return cls.union(process(x) for x in args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 181, in union
return cls._canonical(c for i in intervals for c in i)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 158, in _canonical
components = [c for c in components if c.inf <= c.sup]
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 181, in
return cls._canonical(c for i in intervals for c in i)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 101, in
return cls.union(process(x) for x in args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 100, in process
raise cls.ComponentError("Invalid interval component: " + repr(x))
ComponentError: Invalid interval component: ((-3.0, -2.0), (0.0, 1.0))

for deepcopy:

k = interval([-3, -2], [0, 1])
A=copy.copy(k)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 96, in copy
return _reconstruct(x, rv, 0)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
y = callable(*args)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 93, in newobj
return cls.new(cls, _args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 101, in new
return cls.union(process(x) for x in args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 181, in union
return cls._canonical(c for i in intervals for c in i)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 158, in _canonical
components = [c for c in components if c.inf <= c.sup]
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 181, in
return cls._canonical(c for i in intervals for c in i)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 101, in
return cls.union(process(x) for x in args)
File "/usr/local/lib/python2.7/site-packages/interval/init.py", line 100, in process
raise cls.ComponentError("Invalid interval component: " + repr(x))
ComponentError: Invalid interval component: ((-3.0, -2.0), (0.0, 1.0))
k = interval([-3, -2], [0, 1])
A=copy.deepcopy(k)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 328, in _reconstruct
args = deepcopy(args, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
y = callable(_args)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 93, in newobj
return cls.new(cls, *args)
TypeError: new() takes exactly 3 arguments (2 given)

also it cannot be copied by module pickle. Any ideas?

Add "empty" and "full" intervals

It would be nice to have identity elements for operations on intervals. For example, "empty interval" would be the identity element for Union operation. "Full" would be identity element for Intersect operation.

Invalid interval component due to precision?

Hi,

Could you tell why the following error is being thrown? Are the operators used not able to handle this much precision?

Error1:
Traceback (most recent call last):
File "c.py", line 78, in
input_prev[index] = interval(lower,upper)
File "path/python2.7/site-packages/interval/init.py", line 101, in new
return cls.union(process(x) for x in args)
File "path/python2.7/site-packages/interval/init.py", line 185, in union
return cls._canonical(c for i in intervals for c in i)
File "path/python2.7/site-packages/interval/init.py", line 162, in _canonical
components = [c for c in components if c.inf <= c.sup]
File "path/python2.7/site-packages/interval/init.py", line 185, in
return cls._canonical(c for i in intervals for c in i)
File "path/python2.7/site-packages/interval/init.py", line 101, in
return cls.union(process(x) for x in args)
File "path/python2.7/site-packages/interval/init.py", line 100, in process
raise cls.ComponentError("Invalid interval component: " + repr(x))
interval.ComponentError: Invalid interval component: interval([0.020530565167243362, 0.020530565167243373])

Similarly,
File "/path/python2.7/site-packages/interval/init.py", line 100, in process
raise cls.ComponentError("Invalid interval component: " + repr(x))
interval.ComponentError: Invalid interval component: interval([0.004029219530949634, 0.004029219530949636])

Installing pyinterval on Windows with Python 3.6

Hi,

This might not be the right place for this question since it concerns pycrlibm. I asked the same question at https://github.com/taschini/pycrlibm/issues but there is more activity in this project so I am asking the same question here as well.

I tried installing pyinterval on Windows and Python 3.6. The complete output of the error I am getting is below.

(oe-3.6.2) C:\Users\ifisl\workspace>pip install pyinterval
Collecting pyinterval
  Using cached pyinterval-1.2.0.tar.gz
Collecting crlibm==1.*,>=1.0.3 (from pyinterval)
  Using cached crlibm-1.0.3.tar.gz
Requirement already satisfied: six>=1.10 in c:\users\ifisl\workspace\venvs\oe-3.
6.2\lib\site-packages (from pyinterval)
Installing collected packages: crlibm, pyinterval
  Running setup.py install for crlibm ... error
    Complete output from command c:\users\ifisl\workspace\venvs\oe-3.6.2\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ifisl\\AppData\\Local\\Temp\\pip-build-24w2c8s7\\crlibm\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ifisl\AppData\Local\Temp\pip-qajjsl7u-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\ifisl\workspace\venvs\oe-3.6.2\include\site\python3.6\crlibm:
    running install
    running build
    running build_ext
    using msys2 compiler
    building 'crlibm' extension
    creating build
    creating build\temp.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    creating build\temp.win-amd64-3.6\Release\ext
    C:\msys64\mingw64\bin\gcc.exe -mdll -O2 -Wall -fno-strict-aliasing -fwrapv -DMS_WIN64 -Ibuild/crlibm/include -Ic:\users\ifisl\workspace\venvs\oe-3.6.2\include "-IC:\Program Files\Python362\include" "-IC:\Program Files\Python362\include" -c ext/crlibmmodule.c -o build\temp.win-amd64-3.6\Release\ext\crlibmmodule.o
    ext/crlibmmodule.c:7:10: fatal error: crlibm.h: No such file or directory
     #include "crlibm.h"
              ^~~~~~~~~~
    compilation terminated.
    invoking: ['make', 'msys2', 'PYTHON_DLL=c:\\users\\ifisl\\workspace\\venvs\\oe-3.6.2\\scripts\\python36.dll']
    error: [WinError 2] The system cannot find the file specified

    ----------------------------------------

I followed all instructions in http://stackoverflow.com/a/30071634 on installing/configuring MinGW-w64 under MSYS2 and am getting the error above. I tried to look for crlibm.h at http://lipforge.ens-lyon.fr/www/crlibm but that page does not exist any more.

Is there anything I can do to install pyinterval without pycrlibm? If not, how can I install pycrlibm on Windows with Python 3.6?

Thanks!
Igor

crlibm extension...

Of course it's not the right place to solve this, but it would be kind of you to help to solve this:
Cannot load crlibm extension. The imath functions will not be available.

Problem with pyinterval / Python3.4 / WS7-32 : What should I do ?
Thank you in advance

Raising interval to power zero should always give one

Raising an interval X to the integer power zero should give the interval [1, 1] provided that X is not empty, even if X contains zero. However, the current version delivers [0, 1] if X contains zero.

Example:

interval[0]**0
interval([0.0, 1.0])

Complement of interval?

Is there a way to take the complement of an interval object?

Strictly speaking I think it's not possible since you define all your intervals to be unions of closed simple intervals, so the complements would be unions of open simple intervals, which are not representable in your scheme.

But if you define complement(x) to be the smallest object representable in your scheme whose union with x produces the entire extended real line; or equivalently, the union of the classical complement of x with x.extrema(), then it's in your scheme and it would work for me.

Installation with pip fails " ValueError: Unknown MS Compiler version 1916"

Error:

`C:\WINDOWS\system32>pip install pyinterval
Collecting pyinterval
Using cached pyinterval-1.2.0-py3-none-any.whl
Requirement already satisfied: six>=1.10 in c:\users\ofjok\appdata\local\programs\python\python37\lib\site-packages (from pyinterval) (1.14.0)
Collecting crlibm==1.*,>=1.0.3
Using cached crlibm-1.0.3.tar.gz (1.6 MB)
Building wheels for collected packages: crlibm
Building wheel for crlibm (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\ofjok\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"'; file='"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\ofjok\AppData\Local\Temp\pip-wheel-jyi72ead'
cwd: C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42
Complete output (40 lines):
running bdist_wheel
running build
running build_ext
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 189, in
setup(**metadata)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\site-packages\setuptools_init_.py", line 144, in setup
return distutils.core.setup(**attrs)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
self.run_command('build')
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\command\build_ext.py", line 309, in run
force=self.force)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\ccompiler.py", line 1031, in new_compiler
return klass(None, dry_run, force)
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 58, in init
cygwinccompiler.CygwinCCompiler.init(self, verbose, dry_run, force)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cygwinccompiler.py", line 157, in init
self.dll_libraries = get_msvcr()
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 25, in get_msvcr
return _get_msvcr()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cygwinccompiler.py", line 86, in get_msvcr
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
ValueError: Unknown MS Compiler version 1916

ERROR: Failed building wheel for crlibm
Running setup.py clean for crlibm
Failed to build crlibm
Installing collected packages: crlibm, pyinterval
Running setup.py install for crlibm ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\ofjok\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"'; file='"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\ofjok\AppData\Local\Temp\pip-record-obaqt1et\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\ofjok\appdata\local\programs\python\python37\Include\crlibm'
cwd: C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42
Complete output (42 lines):
running install
running build
running build_ext
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 189, in
setup(**metadata)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\site-packages\setuptools_init_.py", line 144, in setup
return distutils.core.setup(**attrs)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\site-packages\setuptools\command\install.py", line 61, in run
return orig.install.run(self)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\command\install.py", line 545, in run
self.run_command('build')
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\command\build_ext.py", line 309, in run
force=self.force)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\ccompiler.py", line 1031, in new_compiler
return klass(None, dry_run, force)
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 58, in init
cygwinccompiler.CygwinCCompiler.init(self, verbose, dry_run, force)
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cygwinccompiler.py", line 157, in init
self.dll_libraries = get_msvcr()
File "C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py", line 25, in get_msvcr
return _get_msvcr()
File "c:\users\ofjok\appdata\local\programs\python\python37\lib\distutils\cygwinccompiler.py", line 86, in get_msvcr
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
ValueError: Unknown MS Compiler version 1916

ERROR: Command errored out with exit status 1: 'c:\users\ofjok\appdata\local\programs\python\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"'; file='"'"'C:\Users\ofjok\AppData\Local\Temp\pip-install-fm33ar7k\crlibm_fd5461c661ab45d2b35ddbcdb8691d42\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\ofjok\AppData\Local\Temp\pip-record-obaqt1et\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\ofjok\appdata\local\programs\python\python37\Include\crlibm' Check the logs for full command output.`

Too hard and ugly to obtain interval boundaries

If you want the extrema, you can use interval.extrema, but that returns another interval. I can see why, but it's counter-intuitive in some cases.

Furthermore, interval.components returns instances of interval, instead of interval.Component as I would expect.

I see no readable way to get the superior and inferior boundaries of an interval, so I've been using min(interval)[0] and max(interval)[0], which is a little ugly, but it appears to work.

Am I missing something? If it's something you agree with, I could try and patch it. I just wanted to discuss it first.

generating an interval from a list of lists

I've got pairs of years that look like this
timespans = [[1200, 1400], [150, 230]]

and can't see how to generate a multi-component interval looking like this via iteration:
interval([150.0, 230.0], [1200.0, 1400.0])

I have tried several things, including these
k = interval(t for t in timespans)
k = interval(tuple(t) for t in timespans)
which return an "Invalid interval component" error

k = interval(interval(t) for t in timespans)
results in interval([150.0, 1400.0]), which is not multi-component and won't work for the operations I want

k=interval(timespans[0],timespans[1]) gets the right result, but I can't find a way to generate it from a list

can you help?

Is this repo dead? Also can't inmport after install

Running 3.9.1 in a jupyter notebook. Using visual code as an IDE. pip install works fine, gives no errors But when I run the import in the kernel....

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
c:\Users\angus\Desktop\SteinmetzLab\Analysis\KernelRegtest.py in <module>
----> 1 from interval import interval, inf, imath

ImportError: cannot import name 'interval' from 'interval' (c:\Users\angus\AppData\Local\Programs\Python\Python39\lib\site-packages\interval.py)

Wondering if this package is in need up updating and if the people who built it are still around as I saw the last update was in 2017.

Filter out zero-length components

I'm using the pyinterval package to represent unions of open intervals. Thus I would like to have an easy way to get rid of components whose inf and sup are identical. Is there a more elegant way to do it than the following?

        b = interval()
        for i in a:
            if i.sup > i.inf:
                b |= i
        a = b

Intervals for arbitrary comparable values

Hello,

First of all, thank you for pyinterval!

This post is not really an issue but could be considered as an "ads", sorry for that ;-)
Some days ago, I was looking for a Python library providing interval arithmetic. A well-known search engine suggested pyinterval, but it seems that pyinterval is "restricted" to real numbers, and I was looking for a library that supports arbitrary objects (in short: I wanted to create and manipulate intervals of software versions).

Given I haven't found any maintained/stable/correct alternative, I decided to implement my own library that supports interval arithmetic for arbitrary comparable objects in Python. As I think I'm not the only one who found pyinterval by looking for a library that supports arbitrary objects, having a pointer to "alternative" libraries like mine could be interesting.

The library can be found at https://github.com/AlexandreDecan/python-intervals or on PyPI (package name is "python-intervals". Yeah, I known, that's not very imaginative ;-))

Incorrect interval for sin(x)*x

I am unable to compute the correct interval for sin(x) * x. I'm using the following code:

from interval import interval, imath

x = interval([-0.5, 0.5])
y = imath.sin(x) * x
print(y)                                # [-0.2397, 0.2397]


import numpy as np

X = np.linspace(-0.5, 0.5, 100)
Y = np.sin(X) * X
print(Y.min(), Y.max())                 # [0, 0.2397]

The correct bound should be [0, 0.2397], but pyinterval evaluates to [-0.2397, 0.2397]. Is there something I am missing?

Constructor of interval that contains number not represented exactly by IEEE 754

Thanks for making this interval package available publicly. I have found it useful for making "gold" datasets for verifying and benchmarking competing numerical algorithms to solve the same problem.

I would like to pyinterval to have a constructor that will return the smallest interval (with exact IEEE 754 endpoints) that contains a number passed in as an "exact" decimal representation as a string.

For example,

x = interval('0.1')

would return the smallest interval (with exact IEEE 754 endpoints) containing 0.1.

Also, it would be very helpful to be able to turn on a "full precision" mode that shows all interval endpoints at full (decimal) precision. A hexidecimal option here would make things more compact as well (cf. https://docs.python.org/3/library/functions.html#hex).

pickle intervals

Can I serialize intervals using pickle module?
(pyinterval==1.1.1)

Following code:

import pickle
from interval import interval, inf, imath

t = interval([500, 2000])
serialized = pickle.dumps(t)

Got error:
pickle.PicklingError: Can't pickle <class 'interval.Component'>: it's not found as interval.Component

Calculate length of interval

Is there a way to calculate the "length" of an interval ?
To give an example the length of interval([1.0, 2.0], [3.0, 5.0]) would be 3.0.

pip install is failing

In setup.py
metadata = dict(
author = 'Stefano Taschini',
author_email = '[email protected]',
description = 'Interval arithmetic in Python',
install_requires = ['crlibm>=1.0.3,==1.*', 'six>=1.10'],

install_requires is incomplete, please fix to allow successful install.

Difference between two intervals

Hi,

I don't know if it's already existent, but I would like to calculate the difference between two intervals, like that :

i1 = interval([3,4], [7,9])
i2 = interval([0,10])

foo(i1, i2) -> interval([0,2], [5,6], [10,10])

Is there a function doing that right now ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.