Skip to content

Commit

Permalink
Instantiate octave_base_diag and octave_base_sparse template classes.
Browse files Browse the repository at this point in the history
* ov-base-diag-inst.cc: Add new file to explicitly instantiate template class
octave_base_diag with types that need to be exported from liboctinterp.
* ov-base-sparse-inst.cc: Add new file to explicitly instantiate template class
octave_base_sparse with types that need to be exported from liboctinterp.
* ov-base-diag.h, ov-base-sparse.h: Use macro for template export. Mark all
member functions for export.
* ov-bool-sparse.cc, ov-bool-sparse.h, ov-cx-diag.cc, ov-cx-diag.h,
ov-cx-sparse.cc, ov-cx-sparse.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h,
ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-re-diag.cc, ov-re-diag.h,
ov-re-sparse.cc, ov-re-sparse.h: Instantiate template classes octave_base_diag
and octave_base_sparse only in one compilation unit. Move extern template class
declarations to headers.
* ov-base-sparse.cc: Include missing header.
* libinterp/octave-value/module.mk: Add new files to build system.

See: https://octave.discourse.group/t/6086
  • Loading branch information
mmuetzel committed Dec 29, 2024
1 parent 4971f42 commit e931407
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 110 deletions.
2 changes: 2 additions & 0 deletions libinterp/octave-value/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ OCTAVE_VALUE_SRC = \
%reldir%/cdef-package.cc \
%reldir%/cdef-property.cc \
%reldir%/cdef-utils.cc \
%reldir%/ov-base-diag-inst.cc \
%reldir%/ov-base-int-inst.cc \
%reldir%/ov-base-mat-inst.cc \
%reldir%/ov-base-scalar-inst.cc \
%reldir%/ov-base-sparse-inst.cc \
%reldir%/ov-base.cc \
%reldir%/ov-bool-mat.cc \
%reldir%/ov-bool.cc \
Expand Down
38 changes: 38 additions & 0 deletions libinterp/octave-value/ov-base-diag-inst.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING. If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif

#include "ov-base-diag.cc"

// instantiate template class with types that need to be exported from library

template class OCTINTERP_API octave_base_diag<FloatComplexDiagMatrix, FloatComplexMatrix>;
template class OCTINTERP_API octave_base_diag<FloatDiagMatrix, FloatMatrix>;
template class OCTINTERP_API octave_base_diag<ComplexDiagMatrix, ComplexMatrix>;
template class OCTINTERP_API octave_base_diag<DiagMatrix, Matrix>;

104 changes: 61 additions & 43 deletions libinterp/octave-value/ov-base-diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@
// Real matrix values.

template <typename DMT, typename MT>
class OCTINTERP_API octave_base_diag : public octave_base_value
class OCTINTERP_TEMPLATE_API octave_base_diag : public octave_base_value
{

public:

OCTINTERP_API
octave_base_diag ()
: octave_base_value (), m_matrix (), m_dense_cache () { }

OCTINTERP_API
octave_base_diag (const DMT& m)
: octave_base_value (), m_matrix (m), m_dense_cache ()
{ }

OCTINTERP_API
octave_base_diag (const octave_base_diag& m)
: octave_base_value (), m_matrix (m.m_matrix), m_dense_cache () { }

~octave_base_diag () = default;
OCTINTERP_API ~octave_base_diag () = default;

std::size_t byte_size () const { return m_matrix.byte_size (); }
OCTINTERP_API std::size_t byte_size () const
{ return m_matrix.byte_size (); }

octave_value squeeze () const { return m_matrix; }
OCTINTERP_API octave_value squeeze () const
{ return m_matrix; }

octave_value full_value () const { return to_dense (); }
OCTINTERP_API octave_value full_value () const
{ return to_dense (); }

// We don't need to override all three forms of subsref. The using
// declaration will avoid warnings about partially-overloaded virtual
Expand All @@ -74,8 +80,9 @@ class OCTINTERP_API octave_base_diag : public octave_base_value
OCTINTERP_API octave_value
subsref (const std::string& type, const std::list<octave_value_list>& idx);

octave_value_list subsref (const std::string& type,
const std::list<octave_value_list>& idx, int)
OCTINTERP_API octave_value_list
subsref (const std::string& type, const std::list<octave_value_list>& idx,
int)
{ return subsref (type, idx); }

OCTINTERP_API octave_value
Expand All @@ -85,14 +92,17 @@ class OCTINTERP_API octave_base_diag : public octave_base_value
subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
const octave_value& rhs);

dim_vector dims () const { return m_matrix.dims (); }
OCTINTERP_API dim_vector dims () const
{ return m_matrix.dims (); }

octave_idx_type nnz () const { return diag ().nnz (); }
OCTINTERP_API octave_idx_type nnz () const
{ return diag ().nnz (); }

octave_value reshape (const dim_vector& new_dims) const
OCTINTERP_API octave_value reshape (const dim_vector& new_dims) const
{ return to_dense ().reshape (new_dims); }

octave_value permute (const Array<int>& vec, bool inv = false) const
OCTINTERP_API octave_value
permute (const Array<int>& vec, bool inv = false) const
{
if (vec.numel () == 2
&& ((vec.xelem (0) == 1 && vec.xelem (1) == 0)
Expand All @@ -105,11 +115,15 @@ class OCTINTERP_API octave_base_diag : public octave_base_value
OCTINTERP_API octave_value
resize (const dim_vector& dv, bool fill = false) const;

octave_value all (int dim = 0) const { return MT (m_matrix).all (dim); }
octave_value any (int dim = 0) const { return MT (m_matrix).any (dim); }
OCTINTERP_API octave_value all (int dim = 0) const
{ return MT (m_matrix).all (dim); }

OCTINTERP_API octave_value any (int dim = 0) const
{ return MT (m_matrix).any (dim); }

MatrixType matrix_type () const { return MatrixType::Diagonal; }
MatrixType matrix_type (const MatrixType&) const
OCTINTERP_API MatrixType matrix_type () const
{ return MatrixType::Diagonal; }
OCTINTERP_API MatrixType matrix_type (const MatrixType&) const
{ return matrix_type (); }

// We don't need to override both forms of the diag method. The using
Expand All @@ -119,38 +133,42 @@ class OCTINTERP_API octave_base_diag : public octave_base_value

OCTINTERP_API octave_value diag (octave_idx_type k = 0) const;

octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
OCTINTERP_API octave_value
sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
{ return to_dense ().sort (dim, mode); }
octave_value sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
sortmode mode = ASCENDING) const
OCTINTERP_API octave_value
sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
sortmode mode = ASCENDING) const
{ return to_dense ().sort (sidx, dim, mode); }

sortmode issorted (sortmode mode = UNSORTED) const
OCTINTERP_API sortmode issorted (sortmode mode = UNSORTED) const
{ return to_dense ().issorted (mode); }

Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
OCTINTERP_API Array<octave_idx_type>
sort_rows_idx (sortmode mode = ASCENDING) const
{ return to_dense ().sort_rows_idx (mode); }

sortmode is_sorted_rows (sortmode mode = UNSORTED) const
OCTINTERP_API sortmode is_sorted_rows (sortmode mode = UNSORTED) const
{ return to_dense ().is_sorted_rows (mode); }

bool is_matrix_type () const { return true; }
OCTINTERP_API bool is_matrix_type () const { return true; }

bool isnumeric () const { return true; }
OCTINTERP_API bool isnumeric () const { return true; }

bool is_defined () const { return true; }
OCTINTERP_API bool is_defined () const { return true; }

bool is_constant () const { return true; }
OCTINTERP_API bool is_constant () const { return true; }

OCTINTERP_API bool is_true () const;

bool is_diag_matrix () const { return true; }
OCTINTERP_API bool is_diag_matrix () const { return true; }

OCTINTERP_API double double_value (bool = false) const;

OCTINTERP_API float float_value (bool = false) const;

double scalar_value (bool frc_str_conv = false) const
OCTINTERP_API double
scalar_value (bool frc_str_conv = false) const
{ return double_value (frc_str_conv); }

OCTINTERP_API octave::idx_vector
Expand Down Expand Up @@ -187,29 +205,29 @@ class OCTINTERP_API octave_base_diag : public octave_base_value
OCTINTERP_API SparseComplexMatrix
sparse_complex_matrix_value (bool = false) const;

int8NDArray
int8_array_value () const { return to_dense ().int8_array_value (); }
OCTINTERP_API int8NDArray int8_array_value () const
{ return to_dense ().int8_array_value (); }

int16NDArray
int16_array_value () const { return to_dense ().int16_array_value (); }
OCTINTERP_API int16NDArray int16_array_value () const
{ return to_dense ().int16_array_value (); }

int32NDArray
int32_array_value () const { return to_dense ().int32_array_value (); }
OCTINTERP_API int32NDArray int32_array_value () const
{ return to_dense ().int32_array_value (); }

int64NDArray
int64_array_value () const { return to_dense ().int64_array_value (); }
OCTINTERP_API int64NDArray int64_array_value () const
{ return to_dense ().int64_array_value (); }

uint8NDArray
uint8_array_value () const { return to_dense ().uint8_array_value (); }
OCTINTERP_API uint8NDArray uint8_array_value () const
{ return to_dense ().uint8_array_value (); }

uint16NDArray
uint16_array_value () const { return to_dense ().uint16_array_value (); }
OCTINTERP_API uint16NDArray uint16_array_value () const
{ return to_dense ().uint16_array_value (); }

uint32NDArray
uint32_array_value () const { return to_dense ().uint32_array_value (); }
OCTINTERP_API uint32NDArray uint32_array_value () const
{ return to_dense ().uint32_array_value (); }

uint64NDArray
uint64_array_value () const { return to_dense ().uint64_array_value (); }
OCTINTERP_API uint64NDArray uint64_array_value () const
{ return to_dense ().uint64_array_value (); }

OCTINTERP_API octave_value
convert_to_str_internal (bool pad, bool force, char type) const;
Expand Down
36 changes: 36 additions & 0 deletions libinterp/octave-value/ov-base-sparse-inst.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2024 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING. If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif

#include "ov-base-sparse.cc"

// instantiate template class with types that need to be exported from library

template class OCTINTERP_API octave_base_sparse<SparseBoolMatrix>;
template class OCTINTERP_API octave_base_sparse<SparseComplexMatrix>;
template class OCTINTERP_API octave_base_sparse<SparseMatrix>;
1 change: 1 addition & 0 deletions libinterp/octave-value/ov-base-sparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "pr-output.h"

#include "byte-swap.h"
#include "errwarn.h"
#include "ls-oct-text.h"
#include "ls-utils.h"
#include "ls-hdf5.h"
Expand Down
Loading

0 comments on commit e931407

Please sign in to comment.