Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Use more Borrows #109

@tafia

Description

@tafia

There are many places where copies are done (via select_rows for instance) when a simple borrow would have been enough.

We could probably save some memory by:

  • implementing Borrow and AsRef between Matrix and MatrixSlice(Mut) (they make sense I think)
  • having more generic traits that require Borrow<T> or AsRef<T> instead of &T

Example with Optimizable:

        /// Trait for models which can be gradient-optimized.
        pub trait Optimizable {
            /// The input data type to the model.
            type Inputs;
            /// The target data type to the model.
            type Targets;
            /// Compute the gradient for the model.
            fn compute_grad(&self,
                            params: &[f64],
                            inputs: Borrow<Self::Inputs>,
                            targets: Borrow<Self::Targets>)
                            -> (f64, Vec<f64>);
        }

Then we could use MatrixSlice instead of select_rows here.

There are probably many examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions