Obtains a vector that is backed by this , at very little memory cost. Mutations to this vector will alter the values stored in the matrix, and vice versa. @param r the row to obtain a view of @return a vector backed by the specified row of the matrix
(final int r)
| 695 | * @return a vector backed by the specified row of the matrix |
| 696 | */ |
| 697 | public Vec getRowView(final int r) |
| 698 | { |
| 699 | final Matrix M = this; |
| 700 | return new Vec() |
| 701 | { |
| 702 | |
| 703 | /** |
| 704 | * |
| 705 | */ |
| 706 | private static final long serialVersionUID = 8484494698777822563L; |
| 707 | |
| 708 | @Override |
| 709 | public int length() |
| 710 | { |
| 711 | return M.cols(); |
| 712 | } |
| 713 | |
| 714 | @Override |
| 715 | public double get(int index) |
| 716 | { |
| 717 | return M.get(r, index); |
| 718 | } |
| 719 | |
| 720 | @Override |
| 721 | public void set(int index, double val) |
| 722 | { |
| 723 | M.set(r, index, val); |
| 724 | } |
| 725 | |
| 726 | @Override |
| 727 | public boolean isSparse() |
| 728 | { |
| 729 | return M.isSparce(); |
| 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public Vec clone() |
| 734 | { |
| 735 | if(M.isSparce()) |
| 736 | return new SparseVector(this); |
| 737 | else |
| 738 | return new DenseVector(this); |
| 739 | } |
| 740 | }; |
| 741 | } |
| 742 | |
| 743 | @Override |
| 744 | public String toString() |
no outgoing calls