From d868eb3e200f657a1284c4cc933e7a4d25260dce Mon Sep 17 00:00:00 2001 From: "Field G. Van Zee" Date: Fri, 29 Jun 2018 12:36:04 -0500 Subject: [PATCH] Implemented bli_obj_scalar_cast_to(). Details: - Implemented bli_obj_scalar_cast_to(), which will typecast the value in the internal scalar of an obj_t to a specified datatype. - Changed bli_obj_scalar_attach() so that the scalar value being attached is first typecast to the storage datatype of the destination object rather than the target datatype. - Reformatted function type signatures in bli_obj_scalar.c as well as prototypes in its corresponding header file. --- frame/base/bli_obj_scalar.c | 85 +++++++++++++++++++++++++++++-------- frame/base/bli_obj_scalar.h | 64 ++++++++++++++++++++-------- 2 files changed, 114 insertions(+), 35 deletions(-) diff --git a/frame/base/bli_obj_scalar.c b/frame/base/bli_obj_scalar.c index 4ee6eb6af..93a69a566 100644 --- a/frame/base/bli_obj_scalar.c +++ b/frame/base/bli_obj_scalar.c @@ -35,8 +35,11 @@ #include "blis.h" -void bli_obj_scalar_init_detached( num_t dt, - obj_t* beta ) +void bli_obj_scalar_init_detached + ( + num_t dt, + obj_t* beta + ) { void* p; @@ -52,10 +55,13 @@ void bli_obj_scalar_init_detached( num_t dt, bli_obj_set_imag_stride( 1, beta ); } -void bli_obj_scalar_init_detached_copy_of( num_t dt, - conj_t conj, - obj_t* alpha, - obj_t* beta ) +void bli_obj_scalar_init_detached_copy_of + ( + num_t dt, + conj_t conj, + obj_t* alpha, + obj_t* beta + ) { obj_t alpha_local; @@ -71,8 +77,11 @@ void bli_obj_scalar_init_detached_copy_of( num_t dt, bli_copysc( &alpha_local, beta ); } -void bli_obj_scalar_detach( obj_t* a, - obj_t* alpha ) +void bli_obj_scalar_detach + ( + obj_t* a, + obj_t* alpha + ) { num_t dt_a = bli_obj_dt( a ); @@ -84,15 +93,18 @@ void bli_obj_scalar_detach( obj_t* a, bli_obj_copy_internal_scalar( a, alpha ); } -void bli_obj_scalar_attach( conj_t conj, - obj_t* alpha, - obj_t* a ) +void bli_obj_scalar_attach + ( + conj_t conj, + obj_t* alpha, + obj_t* a + ) { obj_t alpha_cast; // Make a copy-cast of alpha of the same datatype as A. This step // gives us the opportunity to conjugate and/or typecast alpha. - bli_obj_scalar_init_detached_copy_of( bli_obj_dt( a ), + bli_obj_scalar_init_detached_copy_of( bli_obj_target_dt( a ), conj, alpha, &alpha_cast ); @@ -101,8 +113,36 @@ void bli_obj_scalar_attach( conj_t conj, bli_obj_copy_internal_scalar( &alpha_cast, a ); } -void bli_obj_scalar_apply_scalar( obj_t* alpha, - obj_t* a ) +void bli_obj_scalar_cast_to + ( + num_t dt, + obj_t* a + ) +{ + obj_t alpha; + obj_t alpha_cast; + + // Initialize alpha to be a bufferless internal scalar of datatype dt. + bli_obj_scalar_init_detached( bli_obj_dt( a ), &alpha ); + + // Copy the internal scalar in A to alpha. + bli_obj_copy_internal_scalar( a, &alpha ); + + // Make a copy-cast of alpha of datatype dt. + bli_obj_scalar_init_detached_copy_of( dt, + BLIS_NO_CONJUGATE, + &alpha, + &alpha_cast ); + + // Copy the copy-casted value in alpha_cast back to A. + bli_obj_copy_internal_scalar( &alpha_cast, a ); +} + +void bli_obj_scalar_apply_scalar + ( + obj_t* alpha, + obj_t* a + ) { obj_t alpha_cast; obj_t scalar_a; @@ -123,7 +163,10 @@ void bli_obj_scalar_apply_scalar( obj_t* alpha, bli_obj_copy_internal_scalar( &scalar_a, a ); } -void bli_obj_scalar_reset( obj_t* a ) +void bli_obj_scalar_reset + ( + obj_t* a + ) { num_t dt = bli_obj_dt( a ); void* scalar_a = bli_obj_internal_scalar_buffer( a ); @@ -138,7 +181,10 @@ void bli_obj_scalar_reset( obj_t* a ) //bli_obj_scalar_attach( BLIS_NO_CONJUGATE, &BLIS_ONE, a ); } -bool_t bli_obj_scalar_has_nonzero_imag( obj_t* a ) +bool_t bli_obj_scalar_has_nonzero_imag + ( + obj_t* a + ) { bool_t r_val = FALSE; num_t dt = bli_obj_dt( a ); @@ -160,8 +206,11 @@ bool_t bli_obj_scalar_has_nonzero_imag( obj_t* a ) return r_val; } -bool_t bli_obj_scalar_equals( obj_t* a, - obj_t* beta ) +bool_t bli_obj_scalar_equals + ( + obj_t* a, + obj_t* beta + ) { obj_t scalar_a; bool_t r_val; diff --git a/frame/base/bli_obj_scalar.h b/frame/base/bli_obj_scalar.h index 388a2929f..4b69e3935 100644 --- a/frame/base/bli_obj_scalar.h +++ b/frame/base/bli_obj_scalar.h @@ -32,28 +32,58 @@ */ -void bli_obj_scalar_init_detached( num_t dt, - obj_t* beta ); +void bli_obj_scalar_init_detached + ( + num_t dt, + obj_t* beta + ); -void bli_obj_scalar_init_detached_copy_of( num_t dt, - conj_t conj, - obj_t* alpha, - obj_t* beta ); +void bli_obj_scalar_init_detached_copy_of + ( + num_t dt, + conj_t conj, + obj_t* alpha, + obj_t* beta + ); -void bli_obj_scalar_detach( obj_t* a, - obj_t* alpha ); +void bli_obj_scalar_detach + ( + obj_t* a, + obj_t* alpha + ); -void bli_obj_scalar_attach( conj_t conj, - obj_t* alpha, - obj_t* a ); +void bli_obj_scalar_attach + ( + conj_t conj, + obj_t* alpha, + obj_t* a + ); -void bli_obj_scalar_apply_scalar( obj_t* alpha, - obj_t* a ); +void bli_obj_scalar_cast_to + ( + num_t dt, + obj_t* a + ); -void bli_obj_scalar_reset( obj_t* a ); +void bli_obj_scalar_apply_scalar + ( + obj_t* alpha, + obj_t* a + ); -bool_t bli_obj_scalar_has_nonzero_imag( obj_t* a ); +void bli_obj_scalar_reset + ( + obj_t* a + ); -bool_t bli_obj_scalar_equals( obj_t* a, - obj_t* beta ); +bool_t bli_obj_scalar_has_nonzero_imag + ( + obj_t* a + ); + +bool_t bli_obj_scalar_equals + ( + obj_t* a, + obj_t* beta + );