matidx.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*Daala video codec
  2. Copyright (c) 2008-2012 Daala project contributors. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
  11. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  13. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  14. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  15. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  16. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  17. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  18. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
  20. #if !defined(_cpack_linalg_matidx_H)
  21. # define _cpack_linalg_matidx_H (1)
  22. /*Returns the total number of elements in an (_n)x(_n) lower-triangular
  23. matrix stored in row-major order.*/
  24. #define LT_SZ(_n) (((_n)*((_n)+1)>>1))
  25. /*Returns the index of element (_i,_j) in a lower-triangular matrix stored in
  26. row-major order ((_i)>=(_j)).*/
  27. #define LT_IDX(_i,_j) (LT_SZ(_i)+(_j))
  28. /*Returns the total number of elements in an (_n)x(_n) strictly
  29. lower-triangular matrix stored in row-major order.*/
  30. #define SLT_SZ(_n) ((((_n)-1)*(_n)>>1))
  31. /*Returns the index of element (_i,_j) in a strictly lower-triangular matrix
  32. stored in row-major order ((_i)>(_j)).*/
  33. #define SLT_IDX(_i,_j) (SLT_SZ(_i)+(_j))
  34. /*Returns the total number of elements in an (_m)x(_n) upper-triangular
  35. matrix, (_m)<=(_n), stored in row-major order.*/
  36. #define UT_SZ(_m,_n) (LT_SZ(_n)-LT_SZ((_n)-(_m)))
  37. /*Returns the index of element (_i,_j) in an upper-triangular matrix stored in
  38. row-major order ((_i)<=(_j)).*/
  39. #define UT_IDX(_i,_j,_n) (UT_SZ(_i,_n)+(_j)-(_i))
  40. /*This version is fewer operations, but the compiler should be able to optimize
  41. the above version better when _n is fixed.
  42. #define UT_IDX(_i,_j,_n) (((_i)*(((_n)<<1)-(_i)-1)>>1)+(_j))*/
  43. /*Returns the total number of elements in an (_m)x(_n) strictly
  44. upper-triangular matrix, (_m)<=(_n), stored in row-major order.*/
  45. #define SUT_SZ(_m,_n) (SLT_SZ(_n)-SLT_SZ((_n)-(_m)))
  46. /*Returns the index of element (_i,_j) in a strictly upper-triangular matrix
  47. stored in row-major order ((_i)<(_j)).*/
  48. #define SUT_IDX(_i,_j,_n) (SUT_SZ(_i,_n)+(_j)-(_i)-1)
  49. /*Swaps elements _a and _b, storing _a in _t as a temporary.*/
  50. #define CP_SWAP(_a,_b,_t) \
  51. do{ \
  52. (_t)=(_a); \
  53. (_a)=(_b); \
  54. (_b)=(_t); \
  55. } \
  56. while(0)
  57. #endif