Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
faust
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
faust group
faust
Commits
f20d12f8
Commit
f20d12f8
authored
3 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Update MatBSR: new ctor, get_cols/rows signature fix (id type), new to_sparse function.
parent
8377d375
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/faust_linear_operator/CPU/faust_MatBSR.h
+12
-5
12 additions, 5 deletions
src/faust_linear_operator/CPU/faust_MatBSR.h
src/faust_linear_operator/CPU/faust_MatBSR.hpp
+54
-8
54 additions, 8 deletions
src/faust_linear_operator/CPU/faust_MatBSR.hpp
with
66 additions
and
13 deletions
src/faust_linear_operator/CPU/faust_MatBSR.h
+
12
−
5
View file @
f20d12f8
...
...
@@ -37,6 +37,7 @@ namespace Faust
MatBSR
()
:
MatGeneric
<
FPP
,
Cpu
>
()
{}
MatBSR
(
BSRMat
<
FPP
>&
mat
);
public
:
MatBSR
(
faust_unsigned_int
nrows
,
faust_unsigned_int
ncols
,
faust_unsigned_int
bnrows
,
faust_unsigned_int
bncols
,
faust_unsigned_int
nblocks
,
const
FPP
*
data
,
const
int
*
block_rowptr
,
const
int
*
block_colinds
);
MatGeneric
<
FPP
,
Cpu
>*
Clone
(
const
bool
isOptimize
=
false
)
const
;
void
multiply
(
Vect
<
FPP
,
Cpu
>
&
vec
,
char
opThis
)
const
;
Vect
<
FPP
,
Cpu
>
multiply
(
const
Vect
<
FPP
,
Cpu
>
&
v
)
const
;
// from LinearOperator
...
...
@@ -58,19 +59,24 @@ namespace Faust
Real
<
FPP
>
norm
()
const
;
Real
<
FPP
>
normL1
(
faust_unsigned_int
&
col_id
,
const
bool
transpose
)
const
;
Vect
<
FPP
,
Cpu
>
get_col
(
faust_unsigned_int
id
)
const
;
Mat
Generic
<
FPP
,
Cpu
>*
get_cols
(
faust_unsigned_int
col_id_start
,
faust_unsigned_int
num_cols
)
const
;
Mat
Generic
<
FPP
,
Cpu
>*
get_rows
(
faust_unsigned_int
row_id_start
,
faust_unsigned_int
num_rows
)
const
;
Mat
Generic
<
FPP
,
Cpu
>*
get_cols
(
const
faust_unsigned_int
*
col_ids
,
faust_unsigned_int
num_cols
)
const
;
Mat
Generic
<
FPP
,
Cpu
>*
get_rows
(
const
faust_unsigned_int
*
row_ids
,
faust_unsigned_int
num_rows
)
const
;
Mat
Sparse
<
FPP
,
Cpu
>*
get_cols
(
faust_unsigned_int
col_id_start
,
faust_unsigned_int
num_cols
)
const
;
Mat
Sparse
<
FPP
,
Cpu
>*
get_rows
(
faust_unsigned_int
row_id_start
,
faust_unsigned_int
num_rows
)
const
;
Mat
Sparse
<
FPP
,
Cpu
>*
get_cols
(
const
faust_unsigned_int
*
col_ids
,
faust_unsigned_int
num_cols
)
const
;
Mat
Sparse
<
FPP
,
Cpu
>*
get_rows
(
const
faust_unsigned_int
*
row_ids
,
faust_unsigned_int
num_rows
)
const
;
std
::
list
<
std
::
pair
<
int
,
int
>>
nonzeros_indices
()
const
;
void
setZeros
();
bool
containsNaN
();
bool
containsNaN
()
const
;
const
FPP
&
operator
()(
faust_unsigned_int
i
,
faust_unsigned_int
j
)
const
;
MatDense
<
FPP
,
Cpu
>
to_dense
()
const
;
MatSparse
<
FPP
,
Cpu
>
to_sparse
()
const
;
/**
* Returns the number of nonzeros blocks.
*/
size_t
getNBlocks
()
const
;
/**
* Returns the number of blocks along the dim_id dimension.
* \param dim_id 0 for row dimension, 1 for column dimension.
*/
size_t
getNbBlocksPerDim
(
int
dim_id
)
const
;
/**
* Returns number of rows of each nonzero block.
...
...
@@ -116,6 +122,7 @@ class BSRMat
// private default constructor
BSRMat
()
:
data
(
nullptr
),
bcolinds
(
nullptr
),
browptr
(
nullptr
),
bnnz
(
0
),
m
(
0
),
n
(
0
),
bm
(
0
),
bn
(
0
),
b_per_rowdim
(
0
),
b_per_coldim
(
0
)
{}
public
:
BSRMat
(
unsigned
long
int
nrows
,
unsigned
long
int
ncols
,
unsigned
long
int
bnrows
,
unsigned
long
int
bncols
,
unsigned
long
int
nblocks
,
const
T
*
data
,
const
int
*
block_rowptr
,
const
int
*
block_colinds
);
/** Copy constructor */
BSRMat
(
const
BSRMat
<
T
,
BlockStorageOrder
>&
src_bmat
);
/** Move constructor */
...
...
This diff is collapsed.
Click to expand it.
src/faust_linear_operator/CPU/faust_MatBSR.hpp
+
54
−
8
View file @
f20d12f8
...
...
@@ -6,6 +6,11 @@
namespace
Faust
{
template
<
typename
FPP
>
MatBSR
<
FPP
,
Cpu
>::
MatBSR
(
faust_unsigned_int
nrows
,
faust_unsigned_int
ncols
,
faust_unsigned_int
bnrows
,
faust_unsigned_int
bncols
,
faust_unsigned_int
nblocks
,
const
FPP
*
data
,
const
int
*
block_rowptr
,
const
int
*
block_colinds
)
:
MatGeneric
<
FPP
,
Cpu
>
(
nrows
,
ncols
),
bmat
(
nrows
,
ncols
,
bnrows
,
bncols
,
nblocks
,
data
,
block_rowptr
,
block_colinds
)
{
}
template
<
typename
FPP
>
MatBSR
<
FPP
,
Cpu
>::
MatBSR
(
BSRMat
<
FPP
>&
bmat
)
{
...
...
@@ -324,34 +329,38 @@ namespace Faust
}
template
<
typename
FPP
>
Mat
Generic
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_cols
(
faust_unsigned_int
col_id_start
,
faust_unsigned_int
num_cols
)
const
Mat
Sparse
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_cols
(
faust_unsigned_int
col_id_start
,
faust_unsigned_int
num_cols
)
const
{
auto
smat
=
new
MatSparse
<
FPP
,
Cpu
>
(
this
->
dim1
,
num_cols
);
smat
->
mat
=
bmat
.
get_rows
(
col_id_start
,
num_cols
);
smat
->
mat
=
bmat
.
get_cols
(
col_id_start
,
num_cols
);
smat
->
update_dim
();
return
smat
;
}
template
<
typename
FPP
>
Mat
Generic
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_rows
(
faust_unsigned_int
row_id_start
,
faust_unsigned_int
num_rows
)
const
Mat
Sparse
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_rows
(
faust_unsigned_int
row_id_start
,
faust_unsigned_int
num_rows
)
const
{
auto
smat
=
new
MatSparse
<
FPP
,
Cpu
>
(
num_rows
,
this
->
dim2
);
smat
->
mat
=
bmat
.
get_rows
(
row_id_start
,
num_rows
);
smat
->
update_dim
();
return
smat
;
}
template
<
typename
FPP
>
Mat
Generic
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_cols
(
const
faust_unsigned_int
*
col_ids
,
faust_unsigned_int
num_cols
)
const
Mat
Sparse
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_cols
(
const
faust_unsigned_int
*
col_ids
,
faust_unsigned_int
num_cols
)
const
{
auto
smat
=
new
MatSparse
<
FPP
,
Cpu
>
(
this
->
dim1
,
num_cols
);
smat
->
mat
=
bmat
.
get_rows
(
col_ids
,
num_cols
);
smat
->
mat
=
bmat
.
get_cols
(
col_ids
,
num_cols
);
smat
->
update_dim
();
return
smat
;
}
template
<
typename
FPP
>
Mat
Generic
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_rows
(
const
faust_unsigned_int
*
row_ids
,
faust_unsigned_int
num_rows
)
const
Mat
Sparse
<
FPP
,
Cpu
>*
MatBSR
<
FPP
,
Cpu
>::
get_rows
(
const
faust_unsigned_int
*
row_ids
,
faust_unsigned_int
num_rows
)
const
{
auto
smat
=
new
MatSparse
<
FPP
,
Cpu
>
(
num_rows
,
this
->
dim2
);
smat
->
mat
=
bmat
.
get_rows
(
row_ids
,
num_rows
);
smat
->
update_dim
();
return
smat
;
}
...
...
@@ -370,7 +379,7 @@ namespace Faust
}
template
<
typename
FPP
>
bool
MatBSR
<
FPP
,
Cpu
>::
containsNaN
()
bool
MatBSR
<
FPP
,
Cpu
>::
containsNaN
()
const
{
return
bmat
.
contains_nan
();
}
...
...
@@ -384,11 +393,21 @@ namespace Faust
template
<
typename
FPP
>
MatDense
<
FPP
,
Cpu
>
MatBSR
<
FPP
,
Cpu
>::
to_dense
()
const
{
MatDense
<
FPP
,
Cpu
>
dmat
(
this
->
dim1
,
this
->
dim2
)
;
MatDense
<
FPP
,
Cpu
>
dmat
;
dmat
.
mat
=
bmat
.
to_dense
();
dmat
.
dim1
=
bmat
.
m
;
dmat
.
dim2
=
bmat
.
n
;
return
dmat
;
}
template
<
typename
FPP
>
MatSparse
<
FPP
,
Cpu
>
MatBSR
<
FPP
,
Cpu
>::
to_sparse
()
const
{
MatSparse
<
FPP
,
Cpu
>
smat
(
this
->
dim1
,
this
->
dim2
);
smat
.
mat
=
bmat
.
to_sparse
();
return
smat
;
}
template
<
typename
FPP
>
MatBSR
<
FPP
,
Cpu
>::~
MatBSR
()
{
...
...
@@ -412,6 +431,33 @@ BSRMat<T, BlockStorageOrder>::BSRMat(const BSRMat<T, BlockStorageOrder>& src_bma
*
this
=
src_bmat
;
}
template
<
typename
T
,
int
BlockStorageOrder
>
BSRMat
<
T
,
BlockStorageOrder
>::
BSRMat
(
unsigned
long
int
nrows
,
unsigned
long
int
ncols
,
unsigned
long
int
bnrows
,
unsigned
long
int
bncols
,
unsigned
long
int
nblocks
,
const
T
*
data
,
const
int
*
block_rowptr
,
const
int
*
block_colinds
)
:
BSRMat
<
T
,
BlockStorageOrder
>
()
{
// verify bm and bn evenly divide m and n
if
(
nrows
%
bnrows
)
throw
std
::
runtime_error
(
"BSRMat error: bnrows must evenly divide nrows."
);
if
(
ncols
%
bncols
)
throw
std
::
runtime_error
(
"BSRMat error: bncols must evenly divide ncols."
);
// enforce bnnz is less or equel to m*n/bm/bn
nblocks
=
std
::
min
(
nblocks
,
nrows
*
ncols
/
bnrows
/
bncols
);
this
->
m
=
nrows
;
this
->
n
=
ncols
;
this
->
bm
=
bnrows
;
this
->
bn
=
bncols
;
this
->
bnnz
=
nblocks
;
this
->
b_per_rowdim
=
this
->
n
/
this
->
bn
;
this
->
b_per_coldim
=
this
->
m
/
this
->
bm
;
int
data_size
=
bnnz
*
bm
*
bn
;
// init data
this
->
data
=
new
T
[
data_size
];
memcpy
(
this
->
data
,
data
,
sizeof
(
T
)
*
nblocks
);
this
->
browptr
=
new
int
[
this
->
b_per_coldim
+
1
];
memcpy
(
this
->
browptr
,
block_rowptr
,
sizeof
(
int
)
*
(
this
->
b_per_rowdim
+
1
));
this
->
bcolinds
=
new
int
[
this
->
bnnz
];
memcpy
(
this
->
bcolinds
,
block_colinds
,
sizeof
(
int
)
*
this
->
bnnz
);
}
template
<
typename
T
,
int
BlockStorageOrder
>
BSRMat
<
T
,
BlockStorageOrder
>::
BSRMat
(
BSRMat
<
T
,
BlockStorageOrder
>&&
src_bmat
)
:
BSRMat
<
T
,
BlockStorageOrder
>
()
{
...
...
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