Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LightMotif
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Larralde
LightMotif
Commits
6d5eb3a8
Commit
6d5eb3a8
authored
6 months ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Add `DenseMatrix::ravel` function to get the full buffer of a matrix
parent
7e62d302
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lightmotif/src/dense.rs
+23
-4
23 additions, 4 deletions
lightmotif/src/dense.rs
with
23 additions
and
4 deletions
lightmotif/src/dense.rs
+
23
−
4
View file @
6d5eb3a8
...
...
@@ -8,6 +8,8 @@ use std::ops::Index;
use
std
::
ops
::
IndexMut
;
use
std
::
ops
::
Range
;
use
crate
::
abc
::
Alphabet
;
use
crate
::
abc
::
Symbol
;
use
crate
::
num
::
ArrayLength
;
// --- MatrixElement -----------------------------------------------------------
...
...
@@ -131,18 +133,35 @@ impl<T: MatrixElement, C: ArrayLength> DenseMatrix<T, C> {
Iter
::
new
(
self
)
}
/// Returns an it
,
erator that allows modifying each row.
/// Returns an iterator that allows modifying each row.
#[inline]
pub
fn
iter_mut
(
&
mut
self
)
->
IterMut
<
'_
,
T
,
C
>
{
IterMut
::
new
(
self
)
}
/// Return the matrix content as a flat slice, including padding.
#[inline]
pub
fn
ravel
(
&
self
)
->
&
[
T
]
{
unsafe
{
std
::
slice
::
from_raw_parts
(
self
.data
.as_ptr
()
as
*
mut
T
,
self
.rows
()
*
self
.stride
())
}
}
/// Return the matrix content as a flat mutable slice, including padding.
#[inline]
pub
fn
ravel_mut
(
&
mut
self
)
->
&
mut
[
T
]
{
unsafe
{
std
::
slice
::
from_raw_parts_mut
(
self
.data
.as_mut_ptr
()
as
*
mut
T
,
self
.rows
()
*
self
.stride
(),
)
}
}
/// Fill the entire matrix with a constant value.
#[inline]
pub
fn
fill
(
&
mut
self
,
value
:
T
)
{
for
row
in
self
.data
.iter_mut
()
{
row
.a
.fill
(
value
)
}
self
.ravel_mut
()
.fill
(
value
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment