Home Reference Source Repository

src/leq.js

  1. import pointwise2 from './pointwise2'
  2. import spPointwise2 from './spPointwise2'
  3.  
  4. const leq = pointwise2((x, y) => x <= y);
  5. const sleq = spPointwise2((x, y) => x <= y);
  6.  
  7. function cleq(x, y) {
  8. throw new Error('mathlab.leq: no leq for complex number')
  9. }
  10.  
  11.  
  12. /**
  13. * Pointwise leq
  14. *
  15. * @export
  16. * @param {Number|Array|Complex|Sparse} m1
  17. * @param {Number|Array|Complex|Sparse} m2
  18. * @returns {Number|Array|Complex|Sparse}
  19. * @example
  20. *
  21. * leq(1, 2)
  22. * // returns 1 <= 2
  23. * leq([1, 2], [2, 2])
  24. * // returns [1 <= 2, 2 <= 2]
  25. * leq([[2,1], [1,2]], [[2, 2], [2, 2]]))
  26. * // returns [ [2 <= 2, 1 <= 2], [1 <= 2, 2 <= 2] ]
  27. */
  28. export default function (m1, m2) {
  29. switch (m1.constructor.name) {
  30. case 'Complex':
  31. return cleq(m1, m2);
  32. case 'Sparse':
  33. return sleq(m1, m2);
  34. default:
  35. return leq(m1, m2);
  36. }
  37. }